From f1206a7206c3e9d347d5c1a4d67135b7a85b0f54 Mon Sep 17 00:00:00 2001 From: Anton Astashov Date: Mon, 6 Sep 2010 09:14:32 +0800 Subject: [PATCH] Added fix and test for 'Layout with partial and yield' bug [#5557] --- actionpack/lib/action_view/render/partials.rb | 23 +++++++++---------- .../test/_layout_with_partial_and_yield.html.erb | 4 +++ actionpack/test/template/render_test.rb | 5 ++++ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 92cdbfb..699fda9 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -179,19 +179,18 @@ module ActionView class PartialRenderer PARTIAL_NAMES = Hash.new {|h,k| h[k] = {} } - def initialize(view_context, options, block) + def initialize(view_context, options) @view = view_context @partial_names = PARTIAL_NAMES[@view.controller.class.name] - setup(options, block) + setup(options) end - def setup(options, block) + def setup(options) partial = options[:partial] @options = options @locals = options[:locals] || {} - @block = block if String === partial @object = options[:object] @@ -209,7 +208,7 @@ module ActionView end end - def render + def render(&block) identifier = ((@template = find_template) ? @template.identifier : @path) if @collection @@ -220,10 +219,10 @@ module ActionView else content = ActiveSupport::Notifications.instrument("render_partial.action_view", :identifier => identifier) do - render_partial + render_partial(@object, &block) end - if !@block && (layout = @options[:layout]) + if !block && (layout = @options[:layout]) content = @view._render_layout(find_template(layout), @locals){ content } end @@ -285,14 +284,14 @@ module ActionView segments end - def render_partial(object = @object) + def render_partial(object = @object, &block) locals, view, template = @locals, @view, @template object ||= locals[template.variable_name] locals[@options[:as] || template.variable_name] = object template.render(view, locals) do |*name| - view._layout_for(*name, &@block) + view._layout_for(*name, &block) end end @@ -326,12 +325,12 @@ module ActionView def _render_partial(options, &block) #:nodoc: if defined?(@renderer) - @renderer.setup(options, block) + @renderer.setup(options) else - @renderer = PartialRenderer.new(self, options, block) + @renderer = PartialRenderer.new(self, options) end - @renderer.render + @renderer.render(&block) end end diff --git a/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb b/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb new file mode 100644 index 0000000..5db0822 --- /dev/null +++ b/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb @@ -0,0 +1,4 @@ +Before +<%= render :partial => "test/partial.html.erb" %> +<%= yield %> +After diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c17bec8..e981f45 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -189,6 +189,11 @@ module RenderTestCases @view.formats = nil end + def test_render_layout_with_block_and_other_partial_inside + render = @view.render(:layout => "test/layout_with_partial_and_yield.html.erb") { "Yield!" } + assert_equal "Before\npartial html\nYield!\nAfter\n", render + end + def test_render_inline assert_equal "Hello, World!", @view.render(:inline => "Hello, World!") end -- 1.7.1