mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Less object creation
This commit is contained in:
parent
fd542d6565
commit
8763cad3d7
3 changed files with 30 additions and 17 deletions
|
@ -22,8 +22,9 @@ module Kaminari
|
|||
# * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
|
||||
def paginate(scope, paginator_class: Kaminari::Helpers::Paginator, **options)
|
||||
options[:total_pages] ||= scope.total_pages
|
||||
options.reverse_merge! current_page: scope.current_page, per_page: scope.limit_value, remote: false
|
||||
|
||||
paginator = paginator_class.new(self, options.reverse_merge(current_page: scope.current_page, per_page: scope.limit_value, remote: false))
|
||||
paginator = paginator_class.new self, options
|
||||
paginator.to_s
|
||||
end
|
||||
|
||||
|
@ -44,10 +45,13 @@ module Kaminari
|
|||
# <%= link_to_previous_page @users, 'Previous Page' do %>
|
||||
# <span>At the Beginning</span>
|
||||
# <% end %>
|
||||
def link_to_previous_page(scope, name, options = {})
|
||||
def link_to_previous_page(scope, name, **options)
|
||||
prev_page = path_to_prev_page(scope, options)
|
||||
|
||||
link_to_if prev_page, name, prev_page, options.except(:params, :param_name).reverse_merge(rel: 'prev') do
|
||||
options.except! :params, :param_name
|
||||
options.reverse_merge! rel: 'prev'
|
||||
|
||||
link_to_if prev_page, name, prev_page, options do
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
@ -69,10 +73,13 @@ module Kaminari
|
|||
# <%= link_to_next_page @users, 'Next Page' do %>
|
||||
# <span>No More Pages</span>
|
||||
# <% end %>
|
||||
def link_to_next_page(scope, name, options = {})
|
||||
def link_to_next_page(scope, name, **options)
|
||||
next_page = path_to_next_page(scope, options)
|
||||
|
||||
link_to_if next_page, name, next_page, options.except(:params, :param_name).reverse_merge(rel: 'next') do
|
||||
options.except! :params, :param_name
|
||||
options.reverse_merge! rel: 'next'
|
||||
|
||||
link_to_if next_page, name, next_page, options do
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,14 +7,14 @@ module Kaminari
|
|||
# The main container tag
|
||||
class Paginator < Tag
|
||||
def initialize(template, window: nil, outer_window: nil, left: nil, right: nil, inner_window: nil, **options) #:nodoc:
|
||||
@window_options = {}.tap do |h|
|
||||
h[:window] = window || inner_window || Kaminari.config.window
|
||||
outer_window = outer_window || Kaminari.config.outer_window
|
||||
h[:left] = left || Kaminari.config.left
|
||||
h[:left] = outer_window if h[:left] == 0
|
||||
h[:right] = right || Kaminari.config.right
|
||||
h[:right] = outer_window if h[:right] == 0
|
||||
end
|
||||
@window_options = {}
|
||||
@window_options[:window] = window || inner_window || Kaminari.config.window
|
||||
outer_window ||= Kaminari.config.outer_window
|
||||
@window_options[:left] = left || Kaminari.config.left
|
||||
@window_options[:left] = outer_window if @window_options[:left] == 0
|
||||
@window_options[:right] = right || Kaminari.config.right
|
||||
@window_options[:right] = outer_window if @window_options[:right] == 0
|
||||
|
||||
@template, @options = template, options
|
||||
@theme = @options[:theme]
|
||||
@views_prefix = @options[:views_prefix]
|
||||
|
|
|
@ -22,7 +22,9 @@ module Kaminari
|
|||
@params = template.params
|
||||
# @params in Rails 5 no longer inherits from Hash
|
||||
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
|
||||
@params = @params.with_indifferent_access.except(*PARAM_KEY_BLACKLIST).merge(params)
|
||||
@params = @params.with_indifferent_access
|
||||
@params.except!(*PARAM_KEY_BLACKLIST)
|
||||
@params.merge! params
|
||||
end
|
||||
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
|
@ -31,7 +33,9 @@ module Kaminari
|
|||
end
|
||||
|
||||
def page_url_for(page)
|
||||
@template.url_for params_for(page).merge(only_path: true)
|
||||
params = params_for(page)
|
||||
params[:only_path] = true
|
||||
@template.url_for params
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -76,7 +80,8 @@ module Kaminari
|
|||
page_url_for page
|
||||
end
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
super locals.merge(url: url)
|
||||
locals[:url] = url
|
||||
super locals
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +93,8 @@ module Kaminari
|
|||
@options[:page]
|
||||
end
|
||||
def to_s(locals = {}) #:nodoc:
|
||||
super locals.merge(page: page)
|
||||
locals[:page] = page
|
||||
super locals
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue