Sha256: 7535eebf22763d35df4a5e5187862488852588ea3c533f16483616533123c1f0
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
module Pagers module Extensions module ActionView module Base extend ActiveSupport::Concern def page_path(number, options={}) if number == 1 number = nil end url_for request.query_parameters.merge(page: number) end def paginate(collection, options={}) links = (options[:links] || Pagers.configuration.links) if collection.total_pages >= links middle = (links / 2).ceil if collection.current_page > (collection.total_pages - middle) starts_at = (collection.total_pages - links + 1) ends_at = collection.total_pages elsif collection.current_page <= middle starts_at = 1 ends_at = links else starts_at = (collection.current_page - middle) ends_at = (collection.current_page + middle) end else starts_at = 1 ends_at = collection.total_pages end pages = Range.new(starts_at, ends_at) less_pages = (starts_at > 1) more_pages = (ends_at < collection.total_pages) render( 'pagers/main', collection: collection, pages: pages, less_pages: less_pages, more_pages: more_pages, options: options ) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pagers-5.1.0 | lib/pagers/extensions/action_view/base.rb |
pagers-4.0.0.1 | lib/pagers/extensions/action_view/base.rb |
pagers-4.0.0.0 | lib/pagers/extensions/action_view/base.rb |