Sha256: 9e7d51c02cf065cd3f90cf7973b61809cd084550a5049861307c69b6fbae4e81

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

require 'kaminari'

module Kaminari
  class PaginatableArray < Array
    def to_liquid(options = {})
      {
        :collection       => to_a,
        :current_page     => current_page,
        :previous_page    => first_page? ? nil : current_page - 1,
        :next_page        => last_page? ? nil : current_page + 1,
        :total_entries    => total_count,
        :total_pages      => num_pages,
        :per_page         => limit_value
      }
    end
  end

  module PageScopeMethods

   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

  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
locomotive_cms-2.0.3 lib/locomotive/kaminari.rb
locomotive_cms-2.0.2 lib/locomotive/kaminari.rb
locomotive_cms-2.0.1 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0 lib/locomotive/kaminari.rb
tribeca_cms-0.1.1 lib/locomotive/kaminari.rb
tribeca_cms-2.0.0.rc12 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc12 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc11 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc10 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc9 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc8 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc7 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc6 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc5 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc4 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc2 lib/locomotive/kaminari.rb
locomotive_cms-2.0.0.rc1 lib/locomotive/kaminari.rb