Fixed bug with variables being passed to captured blocks being forced into arrays. Thanks, Robin Ward!

git-svn-id: svn://hamptoncatlin.com/haml/trunk@516 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-05-15 15:51:50 +00:00
parent 3d177edd2f
commit 9b5d11e80b
2 changed files with 16 additions and 4 deletions

View File

@ -70,7 +70,7 @@ module Haml
#
def list_of(array, &block) # :yields: item
to_return = array.collect do |i|
result = capture_haml(*i, &block)
result = capture_haml(i, &block)
if result.count("\n") > 1
result.gsub!("\n", "\n ")
@ -286,10 +286,10 @@ module Haml
# Performs the function of capture_haml, assuming <tt>local_buffer</tt>
# is where the output of block goes.
def capture_haml_with_buffer(local_buffer, *args)
def capture_haml_with_buffer(local_buffer, *args, &block)
position = local_buffer.length
yield args
block.call *args
captured = local_buffer.slice!(position..-1)

View File

@ -35,7 +35,7 @@ class HelperTest < Test::Unit::TestCase
def test_list_of_should_render_correctly
assert_equal("<li>1</li>\n<li>2</li>\n", render("= list_of([1, 2]) do |i|\n = i"))
assert_equal("<li>1</li>\n", render("= list_of([[1]]) do |i|\n = i.first"))
assert_equal("<li>[1]</li>\n", render("= list_of([[1]]) do |i|\n = i.inspect"))
assert_equal("<li>\n <h1>Fee</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fi</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fo</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fum</h1>\n <p>A word!</p>\n</li>\n",
render("= list_of(['Fee', 'Fi', 'Fo', 'Fum']) do |title|\n %h1= title\n %p A word!"))
end
@ -119,5 +119,17 @@ class HelperTest < Test::Unit::TestCase
def test_indented_capture
assert_equal(" \n Foo\n ", @base.render(:inline => " <% res = capture do %>\n Foo\n <% end %><%= res %>"))
end
def test_capture_deals_properly_with_collections
Haml::Helpers.module_eval do
def trc(collection, &block)
collection.each do |record|
puts capture_haml(record, &block)
end
end
end
assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect"))
end
end