From f84871b1242a642e58f92f2e7c89e24ad30aa3f2 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Fri, 9 May 2008 16:00:08 -0700 Subject: [PATCH] Render empty tags on one line. --- lib/haml/precompiler.rb | 6 ++-- test/haml/engine_test.rb | 36 +++++++++++----------- test/haml/results/content_for_layout.xhtml | 3 +- test/haml/results/eval_suppressed.xhtml | 6 ++-- test/haml/results/just_stuff.xhtml | 3 +- test/haml/results/tag_parsing.xhtml | 3 +- test/haml/results/very_basic.xhtml | 6 ++-- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/lib/haml/precompiler.rb b/lib/haml/precompiler.rb index 95d9a5fe..b22a269b 100644 --- a/lib/haml/precompiler.rb +++ b/lib/haml/precompiler.rb @@ -558,9 +558,9 @@ END self_closing ||= !!( !@block_opened && value.empty? && @options[:autoclose].include?(tag_name) ) + # Check if we can render the tag directly to text and not process it in the buffer if object_ref == "nil" && attributes_hash.nil? && !preserve_script - # This means that we can render the tag directly to text and not process it in the buffer - tag_closed = !value.empty? && !parse + tag_closed = !@block_opened && !self_closing && !parse open_tag = prerender_tag(tag_name, self_closing, attributes) open_tag << "#{value}" if tag_closed @@ -572,7 +572,7 @@ END flush_merged_text content = value.empty? || parse ? 'nil' : value.dump attributes_hash = ', ' + attributes_hash if attributes_hash - push_silent "_hamlout.open_tag(#{tag_name.inspect}, #{self_closing.inspect}, #{(!value.empty?).inspect}, #{preserve_tag.inspect}, #{escape_html.inspect}, #{attributes.inspect}, #{object_ref}, #{content}#{attributes_hash})" + push_silent "_hamlout.open_tag(#{tag_name.inspect}, #{self_closing.inspect}, #{(!@block_opened).inspect}, #{preserve_tag.inspect}, #{escape_html.inspect}, #{attributes.inspect}, #{object_ref}, #{content}#{attributes_hash})" end return if self_closing diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 8fb9a929..1a26054a 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -52,7 +52,7 @@ END end def test_attributes_should_render_correctly - assert_equal("
\n
", render(".atlantis{:style => 'ugly'}").chomp) + assert_equal("
", render(".atlantis{:style => 'ugly'}").chomp) end def test_ruby_code_should_work_inside_attributes @@ -61,7 +61,7 @@ END end def test_nil_should_render_empty_tag - assert_equal("
\n
", + assert_equal("
", render(".no_attributes{:nil => nil}").chomp) end @@ -131,14 +131,14 @@ END end def test_boolean_attributes - assert_equal("

\n

\n", + assert_equal("

\n", render("%p{:foo => 'bar', :bar => true, :baz => 'true'}", :format => :html4)) - assert_equal("

\n

\n", + assert_equal("

\n", render("%p{:foo => 'bar', :bar => true, :baz => 'true'}", :format => :xhtml)) - assert_equal("

\n

\n", + assert_equal("

\n", render("%p{:foo => 'bar', :bar => false, :baz => 'false'}", :format => :html4)) - assert_equal("

\n

\n", + assert_equal("

\n", render("%p{:foo => 'bar', :bar => false, :baz => 'false'}", :format => :xhtml)) end @@ -252,18 +252,18 @@ END end def test_attr_wrapper - assert_equal("

\n

\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*')) - assert_equal("

\n

\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"')) - assert_equal("

\n

\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"')) - assert_equal("

\n

\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"')) + assert_equal("

\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*')) + assert_equal("

\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"')) + assert_equal("

\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"')) + assert_equal("

\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"')) assert_equal("\n", render("!!! XML", :attr_wrapper => '"')) end def test_attrs_parsed_correctly - assert_equal("

biddly='bar => baz'>\n

\n", render("%p{'boom=>biddly' => 'bar => baz'}")) - assert_equal("

\n

\n", render("%p{'foo,bar' => 'baz, qux'}")) - assert_equal("

\n

\n", render("%p{ :escaped => \"quo\\nte\"}")) - assert_equal("

\n

\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}")) + assert_equal("

biddly='bar => baz'>

\n", render("%p{'boom=>biddly' => 'bar => baz'}")) + assert_equal("

\n", render("%p{'foo,bar' => 'baz, qux'}")) + assert_equal("

\n", render("%p{ :escaped => \"quo\\nte\"}")) + assert_equal("

\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}")) end def test_correct_parsing_with_brackets @@ -326,8 +326,8 @@ END end def test_dynamic_attrs_shouldnt_register_as_literal_values - assert_equal("

\n

\n", render('%p{:a => "b#{1 + 1}c"}')) - assert_equal("

\n

\n", render("%p{:a => 'b' + (1 + 1).to_s + 'c'}")) + assert_equal("

\n", render('%p{:a => "b#{1 + 1}c"}')) + assert_equal("

\n", render("%p{:a => 'b' + (1 + 1).to_s + 'c'}")) end def test_dynamic_attrs_with_self_closed_tag @@ -559,11 +559,11 @@ END end def test_html_renders_empty_node_with_closing_tag - assert_equal %{
\n
\n}, render(".foo", :format => :html4) + assert_equal "
\n", render(".foo", :format => :html4) end def test_html_ignores_explicit_self_closing_declaration - assert_equal "\n\n", render("%a/", :format => :html4) + assert_equal "\n", render("%a/", :format => :html4) end def test_html_ignores_xml_prolog_declaration diff --git a/test/haml/results/content_for_layout.xhtml b/test/haml/results/content_for_layout.xhtml index 8761e357..45d4d58a 100644 --- a/test/haml/results/content_for_layout.xhtml +++ b/test/haml/results/content_for_layout.xhtml @@ -1,7 +1,6 @@ - - +
Lorem ipsum dolor sit amet diff --git a/test/haml/results/eval_suppressed.xhtml b/test/haml/results/eval_suppressed.xhtml index 0e10b2d4..0ad97d9b 100644 --- a/test/haml/results/eval_suppressed.xhtml +++ b/test/haml/results/eval_suppressed.xhtml @@ -1,7 +1,5 @@ -

-

-

-

+

+

Me!

All

diff --git a/test/haml/results/just_stuff.xhtml b/test/haml/results/just_stuff.xhtml index bab762df..63578b70 100644 --- a/test/haml/results/just_stuff.xhtml +++ b/test/haml/results/just_stuff.xhtml @@ -59,6 +59,5 @@ testtest

Blah

Blump

Woah inner quotes -

-

+

diff --git a/test/haml/results/tag_parsing.xhtml b/test/haml/results/tag_parsing.xhtml index c1d694c4..5e95f34b 100644 --- a/test/haml/results/tag_parsing.xhtml +++ b/test/haml/results/tag_parsing.xhtml @@ -12,8 +12,7 @@ 11

-

-

+

a
b
c
diff --git a/test/haml/results/very_basic.xhtml b/test/haml/results/very_basic.xhtml index 9713fb1c..6a4cd257 100644 --- a/test/haml/results/very_basic.xhtml +++ b/test/haml/results/very_basic.xhtml @@ -1,7 +1,5 @@ - - - - + +