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

Fixing content_tag bug with Rails 2.2.

Calling content_tag with a block returned nothing.
Added a unit test that isolates the bug and a patch to action_view_mods that resolves the issue.
This commit is contained in:
Jacques Crocker 2008-11-22 20:53:19 -08:00 committed by Nathan Weizenbaum
parent a9a134a1c5
commit dc7ab5f579
3 changed files with 38 additions and 14 deletions

View file

@ -405,6 +405,17 @@ END
!@haml_buffer.nil? && @haml_buffer.active?
end
# Checks to see if a block is defined in a view as haml
def block_is_haml?(block)
begin
eval('_hamlout', block)
true
rescue
false
end
end
private
# call-seq:

View file

@ -51,15 +51,8 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
# if it's not actually in the template context,
# as detected by the existance of an _erbout variable.
# We've got to do the same thing for compatibility.
block_is_haml =
begin
eval('_hamlout', block)
true
rescue
false
end
if block_is_haml && is_haml?
if is_haml? && Haml::Helpers.block_is_haml?(block)
capture_haml(*args, &block)
else
capture_without_haml(*args, &block)
@ -105,15 +98,23 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
end
module TagHelper
def content_tag_with_haml(name, *args, &block)
content = content_tag_without_haml(name, *args, &block)
if is_haml? && haml_buffer.options[:preserve].include?(name.to_s)
content = Haml::Helpers.preserve content
def content_tag_with_haml(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
# handle preserve tags
if is_haml? && content_or_options_with_block.is_a?(String) && haml_buffer.options[:preserve].include?(name.to_s)
content_or_options_with_block = Haml::Helpers.preserve content_or_options_with_block
end
content
if block_given? and is_haml?
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
content_tag_html = content_tag_string(name, capture(&block), options, escape)
return concat(content_tag_html)
end
content_tag_without_haml(name, content_or_options_with_block, options, &block)
end
alias_method :content_tag_without_haml, :content_tag
alias_method :content_tag, :content_tag_with_haml
end

View file

@ -95,7 +95,19 @@ class HelperTest < Test::Unit::TestCase
def test_capture_haml
assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump"))
end
def test_content_tag_block
assert_equal(<<HTML.strip, render(<<HAML, :action_view))
<div><p>bar</p>
<strong>bar</strong>
</div>
HTML
- content_tag :div do
%p bar
%strong bar
HAML
end
def test_haml_tag_attribute_html_escaping
assert_equal("<p id='foo&amp;bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
end