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:
parent
9194e53d87
commit
754edd3cf0
6 changed files with 21 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
module Kaminari
|
||||
module MongoidCriteriaMethods
|
||||
def entry_name
|
||||
model_name.human.downcase
|
||||
end
|
||||
|
||||
def limit_value #:nodoc:
|
||||
options[:limit]
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue