1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge branch 'master' into scss

This commit is contained in:
Nathan Weizenbaum 2010-02-01 21:20:22 -08:00
commit 70c2f5b817
3 changed files with 40 additions and 9 deletions

View file

@ -231,6 +231,7 @@ Several bug fixes and minor improvements have been made, including:
* Allow comments at the beginning of the document to have arbitrary indentation, * Allow comments at the beginning of the document to have arbitrary indentation,
just like comments elsewhere. just like comments elsewhere.
Similarly, comment parsing is a little nicer than before.
## [2.2.17](http://github.com/nex3/haml/commit/2.2.16) ## [2.2.17](http://github.com/nex3/haml/commit/2.2.16)

View file

@ -195,7 +195,7 @@ module Sass
def tabulate(string) def tabulate(string)
tab_str = nil tab_str = nil
initial_comment_tab_str = nil comment_tab_str = nil
first = true first = true
lines = [] lines = []
string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^.*?$/).each_with_index do |line, index| string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^.*?$/).each_with_index do |line, index|
@ -207,12 +207,10 @@ module Sass
line_tab_str = line[/^\s*/] line_tab_str = line[/^\s*/]
unless line_tab_str.empty? unless line_tab_str.empty?
initial_comment_tab_str ||= line_tab_str if tab_str.nil?
# Support comments at the beginning of the document comment_tab_str ||= line_tab_str
# using arbitrary indentation next if try_comment(line, lines.last, "", comment_tab_str, index)
if tab_str.nil? && lines.last && lines.last.comment? && line =~ /^(?:#{initial_comment_tab_str})(.*)$/ comment_tab_str = nil
lines.last.text << "\n" << $1
next
end end
tab_str ||= line_tab_str tab_str ||= line_tab_str
@ -229,9 +227,11 @@ module Sass
next next
end end
if lines.last && lines.last.comment? && line =~ /^(?:#{tab_str}){#{lines.last.tabs + 1}}(.*)$/ comment_tab_str ||= line_tab_str
lines.last.text << "\n" << $1 if try_comment(line, lines.last, tab_str * (lines.last.tabs + 1), comment_tab_str, index)
next next
else
comment_tab_str = nil
end end
line_tabs = line_tab_str.scan(tab_str).size line_tabs = line_tab_str.scan(tab_str).size
@ -248,6 +248,21 @@ END
lines lines
end end
def try_comment(line, last, tab_str, comment_tab_str, index)
return unless last && last.comment?
return unless line =~ /^#{tab_str}/
unless line =~ /^(?:#{comment_tab_str})(.*)$/
raise SyntaxError.new(<<MSG.strip.gsub("\n", " "), :line => index)
Inconsistent indentation:
previous line was indented by #{Haml::Shared.human_indentation comment_tab_str},
but this line was indented by #{Haml::Shared.human_indentation line[/^\s*/]}.
MSG
end
last.text << "\n" << $1
true
end
def tree(arr, i = 0) def tree(arr, i = 0)
return [], i if arr[i].nil? return [], i if arr[i].nil?

View file

@ -98,6 +98,7 @@ MSG
'@if' => "Invalid if directive '@if': expected expression.", '@if' => "Invalid if directive '@if': expected expression.",
'@while' => "Invalid while directive '@while': expected expression.", '@while' => "Invalid while directive '@while': expected expression.",
'@debug' => "Invalid debug directive '@debug': expected expression.", '@debug' => "Invalid debug directive '@debug': expected expression.",
"/* foo\n bar\n baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.",
# Regression tests # Regression tests
"a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3], "a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3],
@ -945,6 +946,20 @@ foo
SASS SASS
end end
def test_unusual_comment_indentation
assert_equal <<CSS, render(<<SASS)
foo {
/* foo
* bar
* baz */ }
CSS
foo
/* foo
bar
baz
SASS
end
def test_attribute_selector_with_spaces def test_attribute_selector_with_spaces
assert_equal(<<CSS, render(<<SASS)) assert_equal(<<CSS, render(<<SASS))
a b[foo = bar] { a b[foo = bar] {