Parent

Methods

DataMapper::Pager

Attributes

current_page[R]

Current page number.

next_page[R]

Next page or nil when no more pages are available.

per_page[R]

Records per page.

previous_page[R]

Previous page or nil when no previous page is available.

total[R]

Total number of un-limited records.

total_pages[R]

Total number of pages.

Public Class Methods

new(options = {}) click to toggle source

Initialize with options.

# File lib/dm-pager/pager.rb, line 38
def initialize options = {}
  @page_param = options.delete(:page_param) || :page
  @total = options.delete :total
  @per_page = options.delete :limit
  @current_page = options.delete @page_param
  @total_pages = total.quo(per_page).ceil
  @next_page = current_page + 1 unless current_page >= total_pages
  @previous_page = current_page - 1 unless current_page <= 1
end

Public Instance Methods

to_html(uri, options = {}) click to toggle source

Render the pager with the given uri and options.

Examples

User.page(2).pager.to_html('/users')
User.page(2).pager.to_html('/users', :size => 3)

Options

:size   Number of intermediate page number links to be shown; Defaults to 7
# File lib/dm-pager/pager.rb, line 61
def to_html uri, options = {}
  return unless total_pages > 1
  @uri, @options = uri, options
  @size = option :size
  raise ArgumentError, 'invalid :size; must be an odd number' if @size % 2 == 0
  @size /= 2
  [%(<ul class="#{Pagination.defaults[:pager_class]}">),
    first_link,
    previous_link,
    more(:before),
    intermediate_links.join("\n"),
    more(:after),
    next_link,
    last_link,
  '</ul>'].join
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.