VERSION | = | '1.1.0' |
VERSION | = | '1.1.0' |
pager | [RW] | DataMapper::Pager instance. |
pager | [RW] | DataMapper::Pager instance. |
Default pagination values.
:per_page Records per page; defaults to 6 :size Number of intermediate page number links to be shown; Defaults to 7 :pager_class Class for the div that contains the pagination links, defaults to 'pager' :previous_text Text for the 'previous' link, defaults to 'Previous' :next_text Text for the 'next' link, defaults to 'Next' :first_text Text for the 'first' link, defaults to 'First' :last_text Text for the 'last' link, defaults to 'Last' :more_text Text for the 'more' indicator, defaults to '...'
DataMapper::Pagination.defaults[:size] = 5
# File lib/dm-pager/defaults.rb, line 36 36: def self.defaults 37: @defaults 38: end
Default pagination values.
:per_page Records per page; defaults to 6 :size Number of intermediate page number links to be shown; Defaults to 7 :pager_class Class for the div that contains the pagination links, defaults to 'pager' :previous_text Text for the 'previous' link, defaults to 'Previous' :next_text Text for the 'next' link, defaults to 'Next' :first_text Text for the 'first' link, defaults to 'First' :last_text Text for the 'last' link, defaults to 'Last' :more_text Text for the 'more' indicator, defaults to '...'
DataMapper::Pagination.defaults[:size] = 5
# File lib/dm-pager/defaults.rb, line 36 36: def self.defaults 37: @defaults 38: end
Page collection by the page number and options provided.
Since pagers will commonly be used with query strings, we coerce all numeric strings such as ‘12’ to their integer value 12. This is the case for page, :per_page, :page, etc.
:page Current page number :per_page Results per page; defaults to 6 :order Defaults to [:id.desc] :page_param The paramter to use to encode the page. Default :page
User.all.page User.all.page(2) User.all.page(2, :per_page => 5) User.all.page(:page => 2, :per_page => 5) User.all.page(:page => 2, :page_param => :user_page)
# File lib/dm-pager/pagination.rb, line 33 33: def page page = nil, options = {} 34: options, page = page, nil if page.is_a? Hash 35: page_param = pager_option(:page_param, options) 36: page ||= pager_option page_param, options 37: options.delete page_param 38: page = 1 unless (page = page.to_i) && page > 1 39: per_page = pager_option(:per_page, options).to_i 40: query = options.dup 41: collection = new_collection scoped_query(options = { 42: :limit => per_page, 43: :offset => (page - 1) * per_page, 44: :order => [:id.desc] 45: }.merge(query)) 46: query.delete :order 47: options.merge! :total => count(query), page_param => page, :page_param => page_param 48: collection.pager = DataMapper::Pager.new options 49: collection 50: end
Page collection by the page number and options provided.
Since pagers will commonly be used with query strings, we coerce all numeric strings such as ‘12’ to their integer value 12. This is the case for page, :per_page, :page, etc.
:page Current page number :per_page Results per page; defaults to 6 :order Defaults to [:id.desc] :page_param The paramter to use to encode the page. Default :page
User.all.page User.all.page(2) User.all.page(2, :per_page => 5) User.all.page(:page => 2, :per_page => 5) User.all.page(:page => 2, :page_param => :user_page)
# File lib/dm-pager/pagination.rb, line 33 33: def page page = nil, options = {} 34: options, page = page, nil if page.is_a? Hash 35: page_param = pager_option(:page_param, options) 36: page ||= pager_option page_param, options 37: options.delete page_param 38: page = 1 unless (page = page.to_i) && page > 1 39: per_page = pager_option(:per_page, options).to_i 40: query = options.dup 41: collection = new_collection scoped_query(options = { 42: :limit => per_page, 43: :offset => (page - 1) * per_page, 44: :order => [:id.desc] 45: }.merge(query)) 46: query.delete :order 47: options.merge! :total => count(query), page_param => page, :page_param => page_param 48: collection.pager = DataMapper::Pager.new options 49: collection 50: end