Module: Paginate::ViewHelpers

Defined in:
lib/doozer/plugins/paginate/lib/paginate/view_helpers.rb

Constant Summary collapse

@@pagination_options =

default options that can be overridden on the global level

{
  :class          => 'pagination',
  :previous_label => '« Previous',
  :next_label     => 'Next »',
  :inner_window   => 4, # links around the current page
  :outer_window   => 1, # links around beginning and end
  :separator      => ' ', # single space is friendly to spiders and non-graphic browsers
  :param_name     => :page,
  :params         => {},
  :page_links     => true,
  :container      => true,
  :debug          => false
}

Instance Method Summary collapse

Instance Method Details

#paginate(collection, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/doozer/plugins/paginate/lib/paginate/view_helpers.rb', line 19

def paginate(collection, options={})
  #Collection => :current_page, :per_page, :total_entries, :total_pages
  opt = @@pagination_options
  opt.update(options)
  out=[]
  if opt[:debug]
    out.push("current_page:#{collection.current_page} / ")
    out.push("per_page:#{collection.per_page} / ")
    out.push("total_entries:#{collection.total_entries} / ")
    out.push("total_pages:#{collection.total_pages} <br />")
  end
  out.push("<div class=\"pagination_container\">") if opt[:container]
  out.push(link(opt[:previous_label], {:page=>collection.previous_page}.update(opt[:params]), {:class=>opt[:class]}) ) if collection.previous_page
  out.push(link(opt[:next_label], {:page=>collection.next_page}.update(opt[:params]), {:class=>opt[:class]}) ) if collection.next_page
  out.push("</div>") if opt[:container]
  return out.join(opt[:separator])
end