mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Can force Sass attribute syntax by setting the :attribute_syntax option.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@582 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
1c96889cef
commit
25d671729c
3 changed files with 44 additions and 0 deletions
16
lib/sass.rb
16
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)
|
|||
# [<tt>:style</tt>] Sets the style of the CSS output.
|
||||
# See the section on Output Style, above.
|
||||
#
|
||||
# [<tt>:attribute_syntax</tt>] Forces the document to use one syntax for attributes.
|
||||
# If the correct syntax isn't used, an error is thrown.
|
||||
# <tt>:normal</tt> forces the use of a colon
|
||||
# before the attribute name.
|
||||
# For example: <tt>:color #0f3</tt>
|
||||
# or <tt>:width = !main_width</tt>.
|
||||
# <tt>:alternate</tt> forces the use of a colon or equals sign
|
||||
# after the attribute name.
|
||||
# For example: <tt>color: #0f3</tt>
|
||||
# or <tt>width = !main_width</tt>.
|
||||
# By default, either syntax is valid.
|
||||
#
|
||||
# [<tt>:always_update</tt>] Whether the CSS files should be updated every
|
||||
# time a controller is accessed,
|
||||
# as opposed to only when the template has been modified.
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -110,6 +110,26 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
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
|
||||
|
||||
def render(sass, options = {})
|
||||
|
|
Loading…
Add table
Reference in a new issue