Add support for specifying a custom Paginator
This commit is contained in:
parent
1fe2c255be
commit
6080b7a32c
|
@ -18,11 +18,13 @@ module Kaminari
|
|||
# * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
|
||||
# * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
|
||||
# * <tt>:remote</tt> - Ajax? (false by default)
|
||||
# * <tt>:paginator_class</tt> - Specify a custom Paginator (Kaminari::Helpers::Paginator by default)
|
||||
# * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
|
||||
def paginate(scope, options = {})
|
||||
options[:total_pages] ||= scope.total_pages
|
||||
options[:paginator_class] ||= Kaminari::Helpers::Paginator
|
||||
|
||||
paginator = Kaminari::Helpers::Paginator.new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
|
||||
paginator = options[:paginator_class].new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
|
||||
paginator.to_s
|
||||
end
|
||||
|
||||
|
|
|
@ -33,6 +33,19 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(::Rails::Railtie) && d
|
|||
it { should eq(" <b>1</b>\n") }
|
||||
end
|
||||
|
||||
context 'accepts :paginator_class option' do
|
||||
let(:custom_paginator) do
|
||||
Class.new(Kaminari::Helpers::Paginator) do
|
||||
def to_s
|
||||
"CUSTOM PAGINATION"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { helper.paginate @users, :paginator_class => custom_paginator, :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should eq("CUSTOM PAGINATION") }
|
||||
end
|
||||
|
||||
context "total_pages: 3" do
|
||||
subject { helper.paginate @users, :total_pages => 3, :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should match(/<a href="\/users\?page=3">Last/) }
|
||||
|
|
Loading…
Reference in New Issue