From ff1571831c99524c012afb8a19b51488e310efc6 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 3 Oct 2010 19:06:42 -0700 Subject: [PATCH] [Haml] Allow newlines between case and when. Closes gh-289 --- doc-src/HAML_CHANGELOG.md | 4 ++++ lib/haml/precompiler.rb | 14 ++++++++------ test/haml/engine_test.rb | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 0b7adc71..88e8ae35 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -3,6 +3,10 @@ * Table of contents {:toc} +## 3.0.22 (Unreleased) + +* Allow an empty line after `case` but before `when`. + ## 3.0.21 [Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.21). diff --git a/lib/haml/precompiler.rb b/lib/haml/precompiler.rb index 0c959115..429f056f 100644 --- a/lib/haml/precompiler.rb +++ b/lib/haml/precompiler.rb @@ -336,12 +336,14 @@ END end end - @precompiled << - if @options[:ugly] - "_hamlout.buffer << \"#{str}\";" - else - "_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});" - end + unless str.empty? + @precompiled << + if @options[:ugly] + "_hamlout.buffer << \"#{str}\";" + else + "_hamlout.push_text(\"#{str}\", #{mtabs}, #{@dont_tab_up_next_text.inspect});" + end + end @precompiled << "\n" * newlines @to_merge = [] @dont_tab_up_next_text = false diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 497d8db5..f0392760 100755 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -86,6 +86,7 @@ MESSAGE "foo\n:plain\n 1\n 2\n 3\#{''}\n4\n- raise 'foo'" => ["foo", 7], "foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5], "= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1], + "- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4], } User = Struct.new('User', :id) @@ -774,6 +775,30 @@ HTML HAML end + def test_case_with_newline_after_case + assert_equal(< true)) foo,