Permalink
Browse files

Adds :layout option to render :partial when a collection is given.

  • Loading branch information...
Serabe committed Mar 6, 2012
1 parent dc80715 commit e4e1388318cd281bf27114b608487330ae1a58df
@@ -238,7 +238,14 @@ def render_collection
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
end
+ if layout = @options[:layout]
+ layout = find_template(layout)
+ end
+
result = @template ? collection_with_template : collection_without_template
+
+ result.map!{|content| layout.render(@view, @locals) { content } } if layout
+
result.join(spacer).html_safe
end
@@ -342,9 +349,10 @@ def collection_with_template
locals[as] = object
segments << template.render(@view, locals)
end
-
+
segments
end
+
def collection_without_template
segments, locals, collection_data = [], @locals, @collection_data
@@ -0,0 +1 @@
+<b><%= yield %></b>
@@ -238,6 +238,10 @@ def test_render_partial_with_nil_collection_should_return_nil
def test_render_partial_with_nil_values_in_collection
assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ])
end
+
+ def test_render_partial_with_layout_using_collection_and_template
+ assert_equal "<b>Hello: Amazon</b><b>Hello: Yahoo</b>", @view.render(:partial => "test/customer", :layout => 'test/b_layout_for_partial', :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
+ end
def test_render_partial_with_empty_array_should_return_nil
assert_nil @view.render(:partial => [])

0 comments on commit e4e1388

Please sign in to comment.