From e4e1388318cd281bf27114b608487330ae1a58df Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Tue, 6 Mar 2012 16:20:56 +0100 Subject: Adds :layout option to render :partial when a collection is given. --- actionpack/lib/action_view/renderer/partial_renderer.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index 3628b935b7..ac4c8db50e 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -238,7 +238,14 @@ module ActionView 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 @@ module ActionView locals[as] = object segments << template.render(@view, locals) end - + segments end + def collection_without_template segments, locals, collection_data = [], @locals, @collection_data -- cgit v1.2.3 From 6e0a763d0047dcaae26fb691757c3407a20e4a84 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Wed, 7 Mar 2012 00:06:42 +0100 Subject: Adds line to change log and update documentation. --- .../lib/action_view/renderer/partial_renderer.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index ac4c8db50e..245a19deec 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -158,6 +158,43 @@ module ActionView # Name: <%= user.name %> # # + # If a collection is given, the layout will be rendered once for each item in the collection. Just think + # these two snippets have the same output: + # + # <%# app/views/users/_user.html.erb %> + # Name: <%= user.name %> + # + # <%# app/views/users/index.html.erb %> + # <%# This does not use layouts %> + # + # + # <%# app/views/users/_li_layout.html.erb %> + #
  • + # <%= yield %> + #
  • + # + # <%# app/views/users/index.html.erb %> + # + # + # Given two users whose names are Alice and Bob, these snippets return: + # + # + # # You can also apply a layout to a block within any template: # # <%# app/views/users/_chief.html.erb &> -- cgit v1.2.3