mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Bring #haml_tag more in line with actual tag behavior.
This commit is contained in:
parent
27daf070ba
commit
377464e79e
3 changed files with 25 additions and 16 deletions
|
@ -321,17 +321,21 @@ module Haml
|
|||
return nil
|
||||
end
|
||||
|
||||
puts "<#{name}#{attributes}>"
|
||||
unless text && text.empty?
|
||||
tab_up
|
||||
# Print out either the text (using push_text) or call the block and add an endline
|
||||
if text
|
||||
puts(text)
|
||||
elsif block
|
||||
block.call
|
||||
end
|
||||
tab_down
|
||||
tag = "<#{name}#{attributes}>"
|
||||
if block.nil?
|
||||
tag << text.to_s << "</#{name}>"
|
||||
puts tag
|
||||
return
|
||||
end
|
||||
|
||||
if text
|
||||
raise Error.new("Illegal nesting: content can't be both given to haml_tag :#{name} and nested within it.")
|
||||
end
|
||||
|
||||
puts tag
|
||||
tab_up
|
||||
block.call
|
||||
tab_down
|
||||
puts "</#{name}>"
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -105,7 +105,15 @@ class HelperTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_haml_tag_non_autoclosed_tags_arent_closed
|
||||
assert_equal("<p>\n</p>\n", render("- haml_tag :p"))
|
||||
assert_equal("<p></p>\n", render("- haml_tag :p"))
|
||||
end
|
||||
|
||||
def test_haml_tag_renders_text_on_a_single_line
|
||||
assert_equal("<p>#{'a' * 100}</p>\n", render("- haml_tag :p, 'a' * 100"))
|
||||
end
|
||||
|
||||
def test_haml_tag_raises_error_for_multiple_content
|
||||
assert_raise(Haml::Error) { render("- haml_tag :p, 'foo' do\n bar") }
|
||||
end
|
||||
|
||||
def test_is_haml
|
||||
|
|
|
@ -79,9 +79,7 @@ foo
|
|||
<table>
|
||||
<tr>
|
||||
<td class='cell'>
|
||||
<strong>
|
||||
strong!
|
||||
</strong>
|
||||
<strong>strong!</strong>
|
||||
data
|
||||
</td>
|
||||
<td>
|
||||
|
@ -90,5 +88,4 @@ foo
|
|||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
<div>
|
||||
</div>
|
||||
<div></div>
|
||||
|
|
Loading…
Add table
Reference in a new issue