diff --git a/lib/sass.rb b/lib/sass.rb
index 39cfa7c8..deb54349 100644
--- a/lib/sass.rb
+++ b/lib/sass.rb
@@ -119,6 +119,10 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
# color: #00ff00;
# width: 97% }
#
+# By default, either attribute syntax may be used.
+# If you want to force one or the other,
+# see the :attribute_syntax option below.
+#
# === Nested Rules
#
# Rules can also be nested within each other.
@@ -567,6 +571,18 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
# [:style] Sets the style of the CSS output.
# See the section on Output Style, above.
#
+# [:attribute_syntax] Forces the document to use one syntax for attributes.
+# If the correct syntax isn't used, an error is thrown.
+# :normal forces the use of a colon
+# before the attribute name.
+# For example: :color #0f3
+# or :width = !main_width.
+# :alternate forces the use of a colon or equals sign
+# after the attribute name.
+# For example: color: #0f3
+# or width = !main_width.
+# By default, either syntax is valid.
+#
# [:always_update] Whether the CSS files should be updated every
# time a controller is accessed,
# as opposed to only when the template has been modified.
diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb
index 43d545e2..3e4dbe41 100644
--- a/lib/sass/engine.rb
+++ b/lib/sass/engine.rb
@@ -238,6 +238,14 @@ module Sass
end
def parse_attribute(line, attribute_regx)
+ if @options[:attribute_syntax] == :normal &&
+ attribute_regx == ATTRIBUTE_ALTERNATE
+ raise SyntaxError.new("Illegal attribute syntax: can't use alternate syntax when :attribute_syntax => :normal is set.")
+ elsif @options[:attribute_syntax] == :alternate &&
+ attribute_regx == ATTRIBUTE
+ raise SyntaxError.new("Illegal attribute syntax: can't use normal syntax when :attribute_syntax => :alternate is set.")
+ end
+
name, eq, value = line.scan(attribute_regx)[0]
if name.nil? || value.nil?
diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb
index 4ac85d9d..fd7ecd05 100644
--- a/test/sass/engine_test.rb
+++ b/test/sass/engine_test.rb
@@ -109,6 +109,26 @@ class SassEngineTest < Test::Unit::TestCase
assert_equal("#foo #bar, #baz #boom { foo: bar; }\n",
render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compact))
end
+
+ def test_colon_only
+ begin
+ render("a\n b: c", :attribute_syntax => :normal)
+ rescue Sass::SyntaxError => e
+ assert_equal("Illegal attribute syntax: can't use alternate syntax when :attribute_syntax => :normal is set.",
+ e.message)
+ else
+ assert(false, "SyntaxError not raised for :attribute_syntax => :normal")
+ end
+
+ begin
+ render("a\n :b c", :attribute_syntax => :alternate)
+ rescue Sass::SyntaxError => e
+ assert_equal("Illegal attribute syntax: can't use normal syntax when :attribute_syntax => :alternate is set.",
+ e.message)
+ else
+ assert(false, "SyntaxError not raised for :attribute_syntax => :alternate")
+ end
+ end
private