From fc98c7a2d3531a2aa2d69573a131c55870ba6b29 Mon Sep 17 00:00:00 2001 From: Sebastian Staudt Date: Tue, 5 Oct 2010 08:26:51 +0200 Subject: [PATCH] Added helper option :show_always This option will force rendering the pagination even if there is only one page to display. --- lib/will_paginate/view_helpers.rb | 7 +++++-- spec/view_helpers/base_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/will_paginate/view_helpers.rb b/lib/will_paginate/view_helpers.rb index b814e3691..ddc347fbe 100644 --- a/lib/will_paginate/view_helpers.rb +++ b/lib/will_paginate/view_helpers.rb @@ -30,7 +30,8 @@ class << self :params => nil, :renderer => nil, :page_links => true, - :container => true + :container => true, + :show_always => false } include WillPaginate::I18n @@ -54,6 +55,8 @@ class << self # * :page_links -- when false, only previous/next links are rendered (default: true) # * :container -- toggles rendering of the DIV container for pagination links, set to # false only when you are rendering your own pagination markup (default: true) + # * :show_always -- when true, display the pagination even if + # there is not more than one page (default: false) # # All options not recognized by will_paginate will become HTML attributes on the container # element for pagination links (the DIV). For example: @@ -66,7 +69,7 @@ class << self # def will_paginate(collection, options = {}) # early exit if there is nothing to render - return nil unless collection.total_pages > 1 + return nil unless collection.total_pages > 1 || options[:show_always] options = WillPaginate::ViewHelpers.pagination_options.merge(options) diff --git a/spec/view_helpers/base_spec.rb b/spec/view_helpers/base_spec.rb index 57236eab6..8acafae76 100644 --- a/spec/view_helpers/base_spec.rb +++ b/spec/view_helpers/base_spec.rb @@ -32,6 +32,16 @@ collection = mock 'Collection', :total_pages => 1 will_paginate(collection).should be_nil end + + it "should render for single-page collections if :show_always is set" do + collection = mock 'Collection', :total_pages => 1 + renderer = mock 'Renderer' + renderer.expects(:prepare).with(collection, instance_of(Hash), self) + renderer.expects(:to_html).returns('') + + will_paginate(collection, :renderer => renderer, :show_always => true). + should == '' + end end describe "page_entries_info" do