Ticket #9209: render_partial_with_layout_patch_2.diff
| File render_partial_with_layout_patch_2.diff, 4.9 kB (added by antramm, 10 months ago) |
|---|
-
actionpack/test/controller/new_render_test.rb
old new 361 361 render :action => "calling_partial_with_layout" 362 362 end 363 363 364 def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout 365 render :action => "calling_partial_with_layout" 366 end 367 364 368 def render_using_layout_around_block 365 369 render :action => "using_layout_around_block" 366 370 end 367 371 372 def render_using_layout_around_block_in_main_layout_and_within_content_for_layout 373 render :action => "using_layout_around_block" 374 end 375 368 376 def rescue_action(e) raise end 369 377 370 378 private … … 387 395 "layouts/builder" 388 396 when "action_talk_to_layout", "layout_overriding_layout" 389 397 "layouts/talk_from_action" 398 when "render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout" 399 "layouts/partial_with_layout" 400 when "render_using_layout_around_block_in_main_layout_and_within_content_for_layout" 401 "layouts/block_with_layout" 390 402 end 391 403 end 392 404 end … … 824 836 get :render_call_to_partial_with_layout 825 837 assert_equal "Before (David)\nInside from partial (David)\nAfter", @response.body 826 838 end 827 839 840 def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout 841 get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout 842 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 843 end 844 828 845 def test_using_layout_around_block 829 get : using_layout_around_block846 get :render_using_layout_around_block 830 847 assert_equal "Before (David)\nInside from block\nAfter", @response.body 831 848 end 849 850 def test_using_layout_around_block_in_main_layout_and_within_content_for_layout 851 get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout 852 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 853 end 854 832 855 end -
actionpack/test/fixtures/layouts/block_with_layout.erb
old new 1 <% render(:layout => "layout_for_partial", :locals => { :name => "Anthony" }) do %>Inside from first block in layout<% end %> 2 <%= yield %> 3 <% render(:layout => "layout_for_partial", :locals => { :name => "Ramm" }) do %>Inside from second block in layout<% end %> -
actionpack/test/fixtures/layouts/partial_with_layout.erb
old new 1 <%= render( :layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => {:name => 'Anthony' } ) %> 2 <%= yield %> 3 <%= render( :layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => {:name => 'Ramm' } ) %> -
actionpack/lib/action_view/base.rb
old new 338 338 path, partial_name = partial_pieces(options.delete(:layout)) 339 339 340 340 if block_given? 341 @content_for_layout = capture(&block) 342 concat(render(options.merge(:partial => "#{path}/#{partial_name}")), block.binding) 341 wrap_content_for_layout capture(&block) do 342 concat(render(options.merge(:partial => "#{path}/#{partial_name}")), block.binding) 343 end 343 344 else 344 @content_for_layout = render(options) 345 render(options.merge(:partial => "#{path}/#{partial_name}")) 345 wrap_content_for_layout render(options) do 346 render(options.merge(:partial => "#{path}/#{partial_name}")) 347 end 346 348 end 347 349 elsif options[:file] 348 350 render_file(options[:file], options[:use_full_path], options[:locals]) … … 441 443 end 442 444 443 445 private 446 def wrap_content_for_layout(content) 447 original_content_for_layout = @content_for_layout 448 @content_for_layout = content 449 returning(yield) { @content_for_layout = original_content_for_layout } 450 end 451 444 452 def find_full_template_path(template_path, extension) 445 453 file_name = "#{template_path}.#{extension}" 446 454 base_path = find_base_path_for(file_name)