mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
haml_tag should only close elements that are listed as autoclose.
E.g. we want haml_tag :br #=> "<br />\n" but haml_tag :p #=> "<p>\n</p>\n"
This commit is contained in:
parent
c0a88ed133
commit
5ca0f21a6c
3 changed files with 13 additions and 1 deletions
|
@ -265,6 +265,7 @@ END
|
|||
# This should remain loadable from #inspect.
|
||||
def options_for_buffer
|
||||
{
|
||||
:autoclose => @options[:autoclose],
|
||||
:preserve => @options[:preserve],
|
||||
:attr_wrapper => @options[:attr_wrapper],
|
||||
:ugly => @options[:ugly],
|
||||
|
|
|
@ -286,6 +286,8 @@ module Haml
|
|||
# </table>
|
||||
#
|
||||
def haml_tag(name, attributes = {}, alt_atts = {}, &block)
|
||||
name = name.to_s
|
||||
|
||||
text = nil
|
||||
if attributes.is_a? String
|
||||
text = attributes
|
||||
|
@ -294,7 +296,8 @@ module Haml
|
|||
|
||||
attributes = Haml::Precompiler.build_attributes(
|
||||
haml_buffer.html?, haml_buffer.options[:attr_wrapper], attributes)
|
||||
if text.nil? && block.nil?
|
||||
|
||||
if text.nil? && block.nil? && haml_buffer.options[:autoclose].include?(name)
|
||||
puts "<#{name}#{attributes} />"
|
||||
return nil
|
||||
end
|
||||
|
|
|
@ -100,6 +100,14 @@ class HelperTest < Test::Unit::TestCase
|
|||
assert_equal("<p id='foo&bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
|
||||
end
|
||||
|
||||
def test_haml_tag_autoclosed_tags_are_closed
|
||||
assert_equal("<br class='foo' />\n", render("- haml_tag :br, :class => 'foo'"))
|
||||
end
|
||||
|
||||
def test_haml_tag_non_autoclosed_tags_arent_closed
|
||||
assert_equal("<p>\n</p>\n", render("- haml_tag :p"))
|
||||
end
|
||||
|
||||
def test_is_haml
|
||||
assert(!ActionView::Base.new.is_haml?)
|
||||
assert_equal("true\n", render("= is_haml?"))
|
||||
|
|
Loading…
Add table
Reference in a new issue