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

[Sass] Allow comments at the beginning of the doc to have arbitrary indentation.

This commit is contained in:
Nathan Weizenbaum 2010-02-01 17:47:52 -08:00
parent e724b98cd7
commit c55174768b
3 changed files with 28 additions and 0 deletions

View file

@ -21,6 +21,9 @@
* Fix the `--cache-location` flag, which was previously throwing errors.
Thanks to [tav](http://tav.espians.com/).
* Allow comments at the beginning of the document to have arbitrary indentation,
just like comments elsewhere.
## [2.2.17](http://github.com/nex3/haml/commit/2.2.16)
* When the {file:SASS_REFERENCE.md#full_exception-option `:full_exception` option}

View file

@ -182,6 +182,7 @@ module Sass
def tabulate(string)
tab_str = nil
initial_comment_tab_str = nil
first = true
lines = []
string.gsub(/\r|\n|\r\n|\r\n/, "\n").scan(/^.*?$/).each_with_index do |line, index|
@ -193,6 +194,14 @@ 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
end
tab_str ||= line_tab_str
raise SyntaxError.new("Indenting at the beginning of the document is illegal.", index) if first

View file

@ -691,6 +691,22 @@ foo {
CSS
end
def test_comment_indentation_at_beginning_of_doc
assert_equal <<CSS, render(<<SASS)
/* foo
* bar
* baz */
foo {
a: b; }
CSS
/* foo
bar
baz
foo
a: b
SASS
end
def test_attribute_selector_with_spaces
assert_equal(<<CSS, render(<<SASS))
a b[foo = bar] {