Render empty tags on one line.
This commit is contained in:
parent
af0334e2e4
commit
f84871b124
|
@ -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}</#{tag_name}>" 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
|
||||
|
|
|
@ -52,7 +52,7 @@ END
|
|||
end
|
||||
|
||||
def test_attributes_should_render_correctly
|
||||
assert_equal("<div class='atlantis' style='ugly'>\n</div>", render(".atlantis{:style => 'ugly'}").chomp)
|
||||
assert_equal("<div class='atlantis' style='ugly'></div>", 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("<div class='no_attributes'>\n</div>",
|
||||
assert_equal("<div class='no_attributes'></div>",
|
||||
render(".no_attributes{:nil => nil}").chomp)
|
||||
end
|
||||
|
||||
|
@ -131,14 +131,14 @@ END
|
|||
end
|
||||
|
||||
def test_boolean_attributes
|
||||
assert_equal("<p bar baz='true' foo='bar'>\n</p>\n",
|
||||
assert_equal("<p bar baz='true' foo='bar'></p>\n",
|
||||
render("%p{:foo => 'bar', :bar => true, :baz => 'true'}", :format => :html4))
|
||||
assert_equal("<p bar='bar' baz='true' foo='bar'>\n</p>\n",
|
||||
assert_equal("<p bar='bar' baz='true' foo='bar'></p>\n",
|
||||
render("%p{:foo => 'bar', :bar => true, :baz => 'true'}", :format => :xhtml))
|
||||
|
||||
assert_equal("<p baz='false' foo='bar'>\n</p>\n",
|
||||
assert_equal("<p baz='false' foo='bar'></p>\n",
|
||||
render("%p{:foo => 'bar', :bar => false, :baz => 'false'}", :format => :html4))
|
||||
assert_equal("<p baz='false' foo='bar'>\n</p>\n",
|
||||
assert_equal("<p baz='false' foo='bar'></p>\n",
|
||||
render("%p{:foo => 'bar', :bar => false, :baz => 'false'}", :format => :xhtml))
|
||||
end
|
||||
|
||||
|
@ -252,18 +252,18 @@ END
|
|||
end
|
||||
|
||||
def test_attr_wrapper
|
||||
assert_equal("<p strange=*attrs*>\n</p>\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*'))
|
||||
assert_equal("<p escaped='quo\"te'>\n</p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<p escaped=\"quo'te\">\n</p>\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<p escaped=\"q'uo"te\">\n</p>\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<p strange=*attrs*></p>\n", render("%p{ :strange => 'attrs'}", :attr_wrapper => '*'))
|
||||
assert_equal("<p escaped='quo\"te'></p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<p escaped=\"quo'te\"></p>\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<p escaped=\"q'uo"te\"></p>\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"'))
|
||||
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"'))
|
||||
end
|
||||
|
||||
def test_attrs_parsed_correctly
|
||||
assert_equal("<p boom=>biddly='bar => baz'>\n</p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
|
||||
assert_equal("<p foo,bar='baz, qux'>\n</p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
|
||||
assert_equal("<p escaped='quo\nte'>\n</p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
|
||||
assert_equal("<p escaped='quo4te'>\n</p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
|
||||
assert_equal("<p boom=>biddly='bar => baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
|
||||
assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
|
||||
assert_equal("<p escaped='quo\nte'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
|
||||
assert_equal("<p escaped='quo4te'></p>\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("<p a='b2c'>\n</p>\n", render('%p{:a => "b#{1 + 1}c"}'))
|
||||
assert_equal("<p a='b2c'>\n</p>\n", render("%p{:a => 'b' + (1 + 1).to_s + 'c'}"))
|
||||
assert_equal("<p a='b2c'></p>\n", render('%p{:a => "b#{1 + 1}c"}'))
|
||||
assert_equal("<p a='b2c'></p>\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 %{<div class='foo'>\n</div>\n}, render(".foo", :format => :html4)
|
||||
assert_equal "<div class='foo'></div>\n", render(".foo", :format => :html4)
|
||||
end
|
||||
|
||||
def test_html_ignores_explicit_self_closing_declaration
|
||||
assert_equal "<a>\n</a>\n", render("%a/", :format => :html4)
|
||||
assert_equal "<a></a>\n", render("%a/", :format => :html4)
|
||||
end
|
||||
|
||||
def test_html_ignores_xml_prolog_declaration
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<head></head>
|
||||
<body>
|
||||
<div id='content'>
|
||||
Lorem ipsum dolor sit amet
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<p>
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
<h1>Me!</h1>
|
||||
<div id='foo'>
|
||||
<p id='bar'>All</p>
|
||||
|
|
|
@ -59,6 +59,5 @@ testtest
|
|||
<p class='article foo' id='article_1'>Blah</p>
|
||||
<p class='article quux qux' id='article_1'>Blump</p>
|
||||
Woah inner quotes
|
||||
<p class='dynamic_quote' dyn='3' quotes="single '">
|
||||
</p>
|
||||
<p class='dynamic_quote' dyn='3' quotes="single '"></p>
|
||||
<p class='dynamic_self_closing' dyn='3' />
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
<foo2u>11</foo2u>
|
||||
</div>
|
||||
<div class='classes'>
|
||||
<p class='foo bar' id='boom'>
|
||||
</p>
|
||||
<p class='foo bar' id='boom'></p>
|
||||
<div class='fooBar'>a</div>
|
||||
<div class='foo-bar'>b</div>
|
||||
<div class='foo_bar'>c</div>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<head></head>
|
||||
<body></body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue