Module: Kaminari::PageScopeMethods

Defined in:
lib/locomotive/kaminari.rb

Instance Method Summary collapse

Instance Method Details

#to_liquid(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/locomotive/kaminari.rb', line 35

def to_liquid(options = {})
  {
    collection:       to_a,
    current_page:     current_page,
    previous_page:    first_page? ? nil : current_page - 1,
    total_entries:    total_count,
    per_page:         limit_value
  }.tap do |hash|
    # note: very important to avoid extra and useless mongodb requests
    hash[:total_pages] = (hash[:total_entries].to_f / limit_value).ceil
    hash[:next_page]   = current_page >= hash[:total_pages] ? nil : current_page + 1
  end
end