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:
commit
70c2f5b817
3 changed files with 40 additions and 9 deletions
|
@ -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,
|
||||
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)
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ module Sass
|
|||
|
||||
def tabulate(string)
|
||||
tab_str = nil
|
||||
initial_comment_tab_str = nil
|
||||
comment_tab_str = nil
|
||||
first = true
|
||||
lines = []
|
||||
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*/]
|
||||
unless line_tab_str.empty?
|
||||
initial_comment_tab_str ||= line_tab_str
|
||||
# Support comments at the beginning of the document
|
||||
# using arbitrary indentation
|
||||
if tab_str.nil? && lines.last && lines.last.comment? && line =~ /^(?:#{initial_comment_tab_str})(.*)$/
|
||||
lines.last.text << "\n" << $1
|
||||
next
|
||||
if tab_str.nil?
|
||||
comment_tab_str ||= line_tab_str
|
||||
next if try_comment(line, lines.last, "", comment_tab_str, index)
|
||||
comment_tab_str = nil
|
||||
end
|
||||
|
||||
tab_str ||= line_tab_str
|
||||
|
@ -229,9 +227,11 @@ module Sass
|
|||
next
|
||||
end
|
||||
|
||||
if lines.last && lines.last.comment? && line =~ /^(?:#{tab_str}){#{lines.last.tabs + 1}}(.*)$/
|
||||
lines.last.text << "\n" << $1
|
||||
comment_tab_str ||= line_tab_str
|
||||
if try_comment(line, lines.last, tab_str * (lines.last.tabs + 1), comment_tab_str, index)
|
||||
next
|
||||
else
|
||||
comment_tab_str = nil
|
||||
end
|
||||
|
||||
line_tabs = line_tab_str.scan(tab_str).size
|
||||
|
@ -248,6 +248,21 @@ END
|
|||
lines
|
||||
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)
|
||||
return [], i if arr[i].nil?
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ MSG
|
|||
'@if' => "Invalid if directive '@if': expected expression.",
|
||||
'@while' => "Invalid while directive '@while': 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
|
||||
"a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3],
|
||||
|
@ -945,6 +946,20 @@ foo
|
|||
SASS
|
||||
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
|
||||
assert_equal(<<CSS, render(<<SASS))
|
||||
a b[foo = bar] {
|
||||
|
|
Loading…
Add table
Reference in a new issue