1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Haml] Fix a bug with elements with dynamic attributes and no content.

Closes gh-47
This commit is contained in:
Nathan Weizenbaum 2009-10-25 14:36:09 -07:00
parent cb603f81da
commit 4771e550d3
3 changed files with 19 additions and 2 deletions

View file

@ -3,6 +3,11 @@
* Table of contents
{:toc}
## 2.2.10 (Unreleased)
* Fixed a bug where elements with dynamic attributes and no content
would have too much whitespace between the opening and closing tag.
## [2.2.9](http://github.com/nex3/haml/commit/2.2.9)
* Fixed a bug where Haml's text was concatenated to the wrong buffer

View file

@ -727,6 +727,7 @@ END
raise SyntaxError.new("Self-closing tags can't have content.", last_line - 1) if self_closing && !value.empty?
self_closing ||= !!( !block_opened? && value.empty? && @options[:autoclose].include?(tag_name) )
value = nil if value.empty? && (block_opened? || self_closing)
dont_indent_next_line =
(nuke_outer_whitespace && !block_opened?) ||
@ -751,7 +752,7 @@ END
return if tag_closed
else
flush_merged_text
content = value.empty? || parse ? 'nil' : value.dump
content = parse ? 'nil' : value.inspect
if attributes_hashes.empty?
attributes_hashes = ''
elsif attributes_hashes.size == 1
@ -769,7 +770,7 @@ END
return if self_closing
if value.empty?
if value.nil?
push_and_tabulate([:element, [tag_name, nuke_outer_whitespace, nuke_inner_whitespace]])
@output_tabs += 1 unless nuke_inner_whitespace
return

View file

@ -123,6 +123,17 @@ class EngineTest < Test::Unit::TestCase
assert_equal("<p class='3'>foo</p>", render("%p{:class => 1+2} foo").chomp)
end
def test_dynamic_attributes_with_no_content
assert_equal(<<HTML, render(<<HAML))
<p>
<a href='http://haml-lang.com'></a>
</p>
HTML
%p
%a{:href => "http://" + "haml-lang.com"}
HAML
end
def test_nil_should_render_empty_tag
assert_equal("<div class='no_attributes'></div>",
render(".no_attributes{:nil => nil}").chomp)