From f851e8f4b5b1c2de295f6796b9af83341dee1062 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Tue, 28 Oct 2008 13:29:18 -0700 Subject: [PATCH] check content_for before yielding to block in render :layout --- actionpack/lib/action_view/renderable.rb | 2 +- actionpack/test/fixtures/layouts/_column.html.erb | 2 ++ actionpack/test/fixtures/test/nested_layout.erb | 3 +++ actionpack/test/template/render_test.rb | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletions(-) create mode 100644 actionpack/test/fixtures/layouts/_column.html.erb create mode 100644 actionpack/test/fixtures/test/nested_layout.erb diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index 3d4dc6d..c23b8cd 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -36,7 +36,7 @@ module ActionView result = view.send(method_name(local_assigns), local_assigns) do |*names| ivar = :@_proc_for_layout - if view.instance_variable_defined?(ivar) and proc = view.instance_variable_get(ivar) + if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar)) view.capture(*names, &proc) elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}") view.instance_variable_get(ivar) diff --git a/actionpack/test/fixtures/layouts/_column.html.erb b/actionpack/test/fixtures/layouts/_column.html.erb new file mode 100644 index 0000000..96db002 --- /dev/null +++ b/actionpack/test/fixtures/layouts/_column.html.erb @@ -0,0 +1,2 @@ +
<%= yield :column %>
+
<%= yield %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/nested_layout.erb b/actionpack/test/fixtures/test/nested_layout.erb new file mode 100644 index 0000000..7b6dcbb --- /dev/null +++ b/actionpack/test/fixtures/test/nested_layout.erb @@ -0,0 +1,3 @@ +<% content_for :title, "title" -%> +<% content_for :column do -%>column<% end -%> +<% render :layout => 'layouts/column' do -%>content<% end -%> \ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 7e4fff3..da8c782 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -162,4 +162,14 @@ class ViewRenderTest < Test::Unit::TestCase ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + + def test_render_with_layout + assert_equal %(\nHello world!\n), + @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") + end + + def test_render_with_nested_layout + assert_equal %(title\n
column
\n
content
\n), + @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") + end end -- 1.5.6.4