Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to always display pagination #76

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/will_paginate/view_helpers.rb
Expand Up @@ -30,7 +30,8 @@ class << self
:params => nil, :params => nil,
:renderer => nil, :renderer => nil,
:page_links => true, :page_links => true,
:container => true :container => true,
:show_always => false
} }


include WillPaginate::I18n include WillPaginate::I18n
Expand All @@ -54,6 +55,8 @@ class << self
# * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true) # * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true)
# * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to # * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to
# false only when you are rendering your own pagination markup (default: true) # false only when you are rendering your own pagination markup (default: true)
# * <tt>:show_always</tt> -- 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 # All options not recognized by will_paginate will become HTML attributes on the container
# element for pagination links (the DIV). For example: # element for pagination links (the DIV). For example:
Expand All @@ -66,7 +69,7 @@ class << self
# #
def will_paginate(collection, options = {}) def will_paginate(collection, options = {})
# early exit if there is nothing to render # 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) options = WillPaginate::ViewHelpers.pagination_options.merge(options)


Expand Down
10 changes: 10 additions & 0 deletions spec/view_helpers/base_spec.rb
Expand Up @@ -32,6 +32,16 @@
collection = mock 'Collection', :total_pages => 1 collection = mock 'Collection', :total_pages => 1
will_paginate(collection).should be_nil will_paginate(collection).should be_nil
end 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('<PAGES>')

will_paginate(collection, :renderer => renderer, :show_always => true).
should == '<PAGES>'
end
end end


describe "page_entries_info" do describe "page_entries_info" do
Expand Down