Round out support for self-closing tags in HTML.

This commit is contained in:
Nathan Weizenbaum 2008-10-06 09:46:09 -07:00
parent 49155711f3
commit 178cababc3
3 changed files with 11 additions and 6 deletions

View File

@ -158,10 +158,12 @@ module Haml
if self_closing && xhtml?
str = " />" + (nuke_outer_whitespace ? "" : "\n")
elsif self_closing && html?
str = " >" + (nuke_outer_whitespace ? "" : "\n")
else
str = ">" + (try_one_line || preserve_tag || nuke_inner_whitespace ? "" : "\n")
str = ">" + ((if self_closing && html?
nuke_outer_whitespace
else
try_one_line || preserve_tag || nuke_inner_whitespace
end) ? "" : "\n")
end
attributes = Precompiler.build_attributes(html?, @options[:attr_wrapper], attributes)

View File

@ -544,7 +544,7 @@ END
preserve_tag &&= !options[:ugly]
case action
when '/'; self_closing = xhtml?
when '/'; self_closing = true
when '~'; parse = preserve_script = true
when '='
parse = true

View File

@ -554,8 +554,11 @@ END
assert_equal "<div class='foo'></div>\n", render(".foo", :format => :html4)
end
def test_html_ignores_explicit_self_closing_declaration
assert_equal "<a></a>\n", render("%a/", :format => :html4)
def test_html_doesnt_add_slash_to_self_closing_tags
assert_equal "<a>\n", render("%a/", :format => :html4)
assert_equal "<a foo='2'>\n", render("%a{:foo => 1 + 1}/", :format => :html4)
assert_equal "<meta>\n", render("%meta", :format => :html4)
assert_equal "<meta foo='2'>\n", render("%meta{:foo => 1 + 1}", :format => :html4)
end
def test_html_ignores_xml_prolog_declaration