Module: Folio
- Extended by:
- PerPage, PerPageIncluder
- Includes:
- PerPage
- Included in:
- Ordinal
- Defined in:
- lib/folio.rb,
lib/folio/page.rb,
lib/folio/ordinal.rb,
lib/folio/version.rb,
lib/folio/per_page.rb,
lib/folio/invalid_page.rb,
lib/folio/ordinal/page.rb,
lib/folio/core_ext/enumerable.rb,
lib/folio/will_paginate/view_helpers.rb,
lib/folio/will_paginate/active_record.rb,
lib/folio/will_paginate/view_helpers/link_renderer.rb
Overview
Mix in to an Enumerable to provide the same methods as Folio::Page but with the following overrides:
* ordinal_pages is always true
* first_page is always 1
* current_page is forced to an integer
* previous_page is always either current_page-1 or nil, depending on how
current_page relates to first_page.
* next_page can only be set if total_pages is unknown. if total_pages is
known, next_page will be either current_page+1 or nil, depending on how
current_page relates to last_page. if total_pages is unknown and next_page
is unset (vs. explicitly set to nil), it will default to current_page+1.
if next_page is set to a non-nil value, that value will be forced to an
integer.
* last_page is deterministic: always total_pages if total_pages is known,
current_page if total_pages is unknown and next_page is nil, nil otherwise
(indicating the page sequence continues until next_page is nil).
Defined Under Namespace
Modules: Enumerable, Ordinal, Page, PerPage, PerPageIncluder, WillPaginate Classes: BasicPage, InvalidPage
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Method Summary collapse
- #configure_pagination(page, options) ⇒ Object
- #default_per_page ⇒ Object
-
#paginate(options = {}) ⇒ Object
Returns a page worth of items from the folio in a Folio::Page.
Methods included from PerPageIncluder
Methods included from PerPage
Instance Method Details
#configure_pagination(page, options) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/folio.rb', line 47 def configure_pagination(page, ) current_page = .fetch(:page) { nil } current_page = page.first_page if current_page.nil? page.current_page = current_page page.per_page = .fetch(:per_page) { self.per_page } page.total_entries = .fetch(:total_entries) { self.respond_to?(:count) ? self.count : nil } page end |
#default_per_page ⇒ Object
56 57 58 |
# File 'lib/folio.rb', line 56 def default_per_page self.class.per_page end |
#paginate(options = {}) ⇒ Object
Returns a page worth of items from the folio in a Folio::Page. accepts the following parameters:
page
: a page identifier addressing which page of the folio to return. if not present, the first page will be returned. will raise Folio::InvalidPage if the provided value cannot be used to address a page.
per_page
: number of items to attempt to include in the page. if not present, defaults to the folio’s per_page value. should only include fewer items if the end of the folio is reached.
total_entries
: pre-calculated value for the total number of items in the folio. may be nil, indicating the returned page should have total_entries nil.
if the folio implements a count method and the total_entries parameter is not supplied, the page’s total_entries will be set from the count method.
40 41 42 43 44 45 |
# File 'lib/folio.rb', line 40 def paginate(={}) page = self.build_page page = self.configure_pagination(page, ) page = self.fill_page(page) page end |