mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Broaden the alternate attribute syntax for Sass.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@541 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
4bf132877f
commit
dc2cda98c3
5 changed files with 28 additions and 18 deletions
|
@ -39,14 +39,16 @@ module Sass
|
|||
# The character used to denote a compiler directive.
|
||||
DIRECTIVE_CHAR = ?@
|
||||
|
||||
# The regex that matches attributes of the form <tt>:name attr</tt>.
|
||||
ATTRIBUTE = /:([^\s=:]+)\s*(=?)(?:\s+|$)(.*)/
|
||||
# The regex that matches and extracts data from
|
||||
# attributes of the form <tt>:name attr</tt>.
|
||||
ATTRIBUTE = /^:([^\s=:]+)\s*(=?)(?:\s+|$)(.*)/
|
||||
|
||||
# The regex that matches attributes of the form <tt>name: attr</tt>.
|
||||
ALTERNATE_ATTRIBUTE_SELECTOR = /^[^\s:]+:(\s+|$)/
|
||||
ATTRIBUTE_ALTERNATE_MATCHER = /^[^\s:]+\s*[=:](\s|$)/
|
||||
|
||||
# The regex that extracts data from attributes of the form <tt>name: attr</tt>.
|
||||
ATTRIBUTE_ALTERNATE = /([^\s=]+):\s*(=?)\s*(.*)/
|
||||
# The regex that matches and extracts data from
|
||||
# attributes of the form <tt>name: attr</tt>.
|
||||
ATTRIBUTE_ALTERNATE = /^([^\s=:]+)(\s*=|:)(?:\s+|$)(.*)/
|
||||
|
||||
# Creates a new instace of Sass::Engine that will compile the given
|
||||
# template string when <tt>render</tt> is called.
|
||||
|
@ -217,18 +219,18 @@ module Sass
|
|||
end
|
||||
|
||||
def parse_line(line)
|
||||
if line[0] == ATTRIBUTE_CHAR
|
||||
case line[0]
|
||||
when ATTRIBUTE_CHAR
|
||||
parse_attribute(line, ATTRIBUTE)
|
||||
elsif line.match(ALTERNATE_ATTRIBUTE_SELECTOR)
|
||||
parse_attribute(line, ATTRIBUTE_ALTERNATE)
|
||||
when Constant::CONSTANT_CHAR
|
||||
parse_constant(line)
|
||||
when COMMENT_CHAR
|
||||
parse_comment(line)
|
||||
when DIRECTIVE_CHAR
|
||||
parse_directive(line)
|
||||
else
|
||||
case line[0]
|
||||
when Constant::CONSTANT_CHAR
|
||||
parse_constant(line)
|
||||
when COMMENT_CHAR
|
||||
parse_comment(line)
|
||||
when DIRECTIVE_CHAR
|
||||
parse_directive(line)
|
||||
if line =~ ATTRIBUTE_ALTERNATE_MATCHER
|
||||
parse_attribute(line, ATTRIBUTE_ALTERNATE)
|
||||
else
|
||||
Tree::RuleNode.new(line, @options[:style])
|
||||
end
|
||||
|
@ -242,7 +244,7 @@ module Sass
|
|||
raise SyntaxError.new("Invalid attribute: \"#{line}\"", @line)
|
||||
end
|
||||
|
||||
if eq[0] == SCRIPT_CHAR
|
||||
if eq.strip[0] == SCRIPT_CHAR
|
||||
value = Sass::Constant.parse(value, @constants, @line).to_s
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,11 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
":= a" => 'Invalid attribute: ":= a"',
|
||||
"a\n :b" => 'Invalid attribute: ":b "',
|
||||
"a\n :b: c" => 'Invalid attribute: ":b: c"',
|
||||
"a\n :b:c d" => 'Invalid attribute: ":b:c d"',
|
||||
"a\n :b=c d" => 'Invalid attribute: ":b=c d"',
|
||||
"a\n :b c;" => 'Invalid attribute: ":b c;" (This isn\'t CSS!)',
|
||||
"a\n b : c" => 'Invalid attribute: "b : c"',
|
||||
"a\n b=c: d" => 'Invalid attribute: "b=c: d"',
|
||||
":a" => 'Attributes aren\'t allowed at the root of a document.',
|
||||
"!" => 'Invalid constant: "!"',
|
||||
"!a" => 'Invalid constant: "!a"',
|
||||
|
@ -61,7 +65,7 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
assert(err.sass_line, "Line: #{key}")
|
||||
assert_match(/\(sass\):[0-9]+/, err.backtrace[0], "Line: #{key}")
|
||||
else
|
||||
assert(false, "Exception not raised for '#{key}'!")
|
||||
assert(false, "Exception not raised for\n#{key}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ class SassPluginTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def teardown
|
||||
FileUtils.rm_r File.dirname(__FILE__) + '/tmp'
|
||||
FileUtils.rm_r File.dirname(__FILE__) + '/tmp'
|
||||
end
|
||||
|
||||
def test_templates_should_render_correctly
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
h1 { float: left; width: 274px; height: 75px; margin: 0; background-repeat: no-repeat; background-image: none; }
|
||||
h1 a:hover, h1 a:visited { color: green; }
|
||||
h1 b:hover { color: red; background-color: green; }
|
||||
h1 const { nosp: 3; sp: 3; }
|
||||
|
|
|
@ -11,3 +11,6 @@ h1
|
|||
b:hover
|
||||
color: red
|
||||
:background-color green
|
||||
const
|
||||
nosp= 1 + 2
|
||||
sp = 1 + 2
|
||||
|
|
Loading…
Add table
Reference in a new issue