From cedf2c0ba1f5463865ef3829e4fa38d97cfd7a88 Mon Sep 17 00:00:00 2001 From: Maxim Kulkin Date: Wed, 10 Sep 2008 22:34:51 +0400 Subject: [PATCH] render partial collection with inline spacer --- actionpack/lib/action_controller/base.rb | 5 ++++- actionpack/lib/action_view/partials.rb | 2 +- ...nder_partial_with_record_identification_test.rb | 10 ++++++++++ actionpack/test/controller/render_test.rb | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 457b9e8..2f3f8b5 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -728,7 +728,10 @@ module ActionController #:nodoc: # # Renders a collection of partials but with a custom local variable name # render :partial => "admin_person", :collection => @winners, :as => :person # - # # Renders the same collection of partials, but also renders the + # # Renders the same collection of partials with specified text between each partial. + # render :partial => "person", :collection => @winners, :spacer => ", " + # + # # Renders the same collection of partials, but also renders the # # person_divider partial between each person partial. # render :partial => "person", :collection => @winners, :spacer_template => "person_divider" # diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 373bb92..7f295ad 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -171,7 +171,7 @@ module ActionView return nil if options[:collection].blank? partial = options[:partial] - spacer = options[:spacer_template] ? render(:partial => options[:spacer_template]) : '' + spacer = options[:spacer] || (options[:spacer_template] ? render(:partial => options[:spacer_template]) : '') local_assigns = options[:locals] ? options[:locals].clone : {} as = options[:as] diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index d75cb2b..77eb470 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -40,6 +40,11 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base render :partial => @developers end + def render_with_record_collection_and_spacer + @developer = Developer.find(1) + render :partial => @developer.projects, :spacer => 'inline spacer' + end + def render_with_record_collection_and_spacer_template @developer = Developer.find(1) render :partial => @developer.projects, :spacer_template => 'test/partial_only' @@ -86,6 +91,11 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body end + def test_render_with_record_collection_and_spacer + get :render_with_record_collection_and_spacer + assert_equal 'Active Recordinline spacerActive Controller', @response.body + end + def test_render_with_record_collection_and_spacer_template get :render_with_record_collection_and_spacer_template assert_equal 'Active Recordonly partialActive Controller', @response.body diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index af7b5dd..306f4d4 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -538,6 +538,10 @@ class TestController < ActionController::Base end def partial_collection_with_spacer + render :partial => "customer", :spacer => "inline spacer", :collection => [ Customer.new("david"), Customer.new("mary") ] + end + + def partial_collection_with_spacer_template render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ] end @@ -1242,6 +1246,11 @@ class RenderTest < Test::Unit::TestCase def test_partial_collection_with_spacer get :partial_collection_with_spacer + assert_equal "Hello: davidinline spacerHello: mary", @response.body + end + + def test_partial_collection_with_spacer_template + get :partial_collection_with_spacer_template assert_equal "Hello: davidonly partialHello: mary", @response.body end -- 1.5.4.5