Fixed rendering of partials with layout when done from site layout (closes #9209) [antramm]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8541 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2008-01-03 15:28:36 +00:00
parent 7b8ee2438f
commit d5645fd4a0
5 changed files with 45 additions and 6 deletions

@ -1,5 +1,7 @@
*SVN*
* Fixed rendering of partials with layout when done from site layout #9209 [antramm]
* Fix atom_feed_helper to comply with the atom spec. Closes #10672 [xaviershay]
* The tags created do not contain a date (http://feedvalidator.org/docs/error/InvalidTAG.html)

@ -338,12 +338,14 @@ def render(options = {}, old_local_assigns = {}, &block) #:nodoc:
path, partial_name = partial_pieces(options.delete(:layout))
if block_given?
@content_for_layout = capture(&block)
wrap_content_for_layout capture(&block) do
concat(render(options.merge(:partial => "#{path}/#{partial_name}")), block.binding)
end
else
@content_for_layout = render(options)
wrap_content_for_layout render(options) do
render(options.merge(:partial => "#{path}/#{partial_name}"))
end
end
elsif options[:file]
render_file(options[:file], options[:use_full_path], options[:locals])
elsif options[:partial] && options[:collection]
@ -441,6 +443,12 @@ def append_view_path(path)
end
private
def wrap_content_for_layout(content)
original_content_for_layout = @content_for_layout
@content_for_layout = content
returning(yield) { @content_for_layout = original_content_for_layout }
end
def find_full_template_path(template_path, extension)
file_name = "#{template_path}.#{extension}"
base_path = find_base_path_for(file_name)

@ -361,10 +361,18 @@ def render_call_to_partial_with_layout
render :action => "calling_partial_with_layout"
end
def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
render :action => "calling_partial_with_layout"
end
def render_using_layout_around_block
render :action => "using_layout_around_block"
end
def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
render :action => "using_layout_around_block"
end
def rescue_action(e) raise end
private
@ -387,6 +395,10 @@ def determine_layout
"layouts/builder"
when "action_talk_to_layout", "layout_overriding_layout"
"layouts/talk_from_action"
when "render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout"
"layouts/partial_with_layout"
when "render_using_layout_around_block_in_main_layout_and_within_content_for_layout"
"layouts/block_with_layout"
end
end
end
@ -826,8 +838,19 @@ def test_render_call_to_partial_with_layout
assert_equal "Before (David)\nInside from partial (David)\nAfter", @response.body
end
def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
assert_equal "Before (Anthony)\nInside from partial (Anthony)\nAfter\nBefore (David)\nInside from partial (David)\nAfter\nBefore (Ramm)\nInside from partial (Ramm)\nAfter", @response.body
end
def test_using_layout_around_block
get :using_layout_around_block
get :render_using_layout_around_block
assert_equal "Before (David)\nInside from block\nAfter", @response.body
end
def test_using_layout_around_block_in_main_layout_and_within_content_for_layout
get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout
assert_equal "Before (Anthony)\nInside from first block in layout\nAfter\nBefore (David)\nInside from block\nAfter\nBefore (Ramm)\nInside from second block in layout\nAfter\n", @response.body
end
end

@ -0,0 +1,3 @@
<% render(:layout => "layout_for_partial", :locals => { :name => "Anthony" }) do %>Inside from first block in layout<% end %>
<%= yield %>
<% render(:layout => "layout_for_partial", :locals => { :name => "Ramm" }) do %>Inside from second block in layout<% end %>

@ -0,0 +1,3 @@
<%= render( :layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => {:name => 'Anthony' } ) %>
<%= yield %>
<%= render( :layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => {:name => 'Ramm' } ) %>