1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Simplify page_entries_info by adding entry_name interface to each ORM

This commit is contained in:
Yuki Nishijima 2014-03-16 11:19:20 -07:00
parent 9194e53d87
commit 754edd3cf0
6 changed files with 21 additions and 11 deletions

View file

@ -86,17 +86,7 @@ module Kaminari
# <%= page_entries_info @posts, :entry_name => 'item' %>
# #-> Displaying items 6 - 10 of 26 in total
def page_entries_info(collection, options = {})
entry_name = if options[:entry_name]
options[:entry_name]
elsif collection.is_a?(::Kaminari::PaginatableArray)
'entry'
else
if collection.respond_to? :model # DataMapper
collection.model.model_name.human.downcase
else # AR
collection.model_name.human.downcase
end
end
entry_name = options[:entry_name] || collection.entry_name
entry_name = entry_name.pluralize unless collection.total_count == 1
if collection.total_pages < 2

View file

@ -8,6 +8,10 @@ module Kaminari
end
end
def entry_name
model_name.human.downcase
end
def total_count(column_name = :all, options = {}) #:nodoc:
# #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
@total_count ||= begin

View file

@ -24,6 +24,10 @@ module Kaminari
end
end
def entry_name
"entry"
end
# items at the specified "page"
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{Kaminari.config.page_method_name}(num = 1)

View file

@ -1,5 +1,9 @@
module Kaminari
module DataMapperCollectionMethods
def entry_name
model.model_name.human.downcase
end
def limit_value #:nodoc:
query.options[:limit] || 0
end

View file

@ -1,5 +1,9 @@
module Kaminari
module MongoidCriteriaMethods
def entry_name
model_name.human.downcase
end
def limit_value #:nodoc:
options[:limit]
end

View file

@ -4,6 +4,10 @@ module Kaminari
delegate :default_per_page, :max_per_page, :max_pages, :to => :model
def entry_name
model.model_name.human.downcase
end
def limit_value #:nodoc:
options[:limit]
end