From c55174768b1374f5045f35a07b9348c02e1bed77 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Mon, 1 Feb 2010 17:47:52 -0800 Subject: [PATCH] [Sass] Allow comments at the beginning of the doc to have arbitrary indentation. --- doc-src/SASS_CHANGELOG.md | 3 +++ lib/sass/engine.rb | 9 +++++++++ test/sass/engine_test.rb | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index c97c6c70..1d620480 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -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} diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb index f8d639ae..1a7afdb6 100644 --- a/lib/sass/engine.rb +++ b/lib/sass/engine.rb @@ -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 diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb index 4bbec266..d6f547c5 100755 --- a/test/sass/engine_test.rb +++ b/test/sass/engine_test.rb @@ -691,6 +691,22 @@ foo { CSS end + def test_comment_indentation_at_beginning_of_doc + assert_equal <