Skip to content

Instantly share code, notes, and snippets.

@dblock

dblock/kaminari.rb

Created Jul 28, 2011
Embed
What would you like to do?
Kaminari pagination information.
# see https://github.com/amatsuda/kaminari/issues/56 and https://github.com/amatsuda/kaminari/pull/140
module Kaminari
# = Helpers
module ActionViewExtension
extend ::ActiveSupport::Concern
module InstanceMethods
def page_entries_info(collection, options = {})
collection_name = options[:collection_name] || (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
if collection.num_pages < 2
case collection.size
when 0; info = "No #{collection_name.pluralize.capitalize} found"
when 1; info = "Displaying <strong>1</strong> #{collection_name.capitalize}"
else; info = "Displaying <strong>All #{collection.size}</strong> #{collection_name.pluralize.capitalize}"
end
else
info = %{Displaying #{collection_name.pluralize.capitalize} <strong>%d&ndash;%d</strong> of <strong>%d</strong> in Total}% [
collection.offset_value + 1,
collection.offset_value + collection.length,
collection.total_count
]
end
info.html_safe
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment