lib/kaminari/helpers/action_view_extension.rb in kaminari-0.15.1 vs lib/kaminari/helpers/action_view_extension.rb in kaminari-0.16.0
- old
+ new
@@ -37,11 +37,11 @@
# <span>At the Beginning</span>
# <% end %>
def link_to_previous_page(scope, name, options = {}, &block)
params = options.delete(:params) || {}
param_name = options.delete(:param_name) || Kaminari.config.param_name
- link_to_unless scope.first_page?, name, params.merge(param_name => (scope.current_page - 1)), options.reverse_merge(:rel => 'previous') do
+ link_to_unless scope.first_page?, name, params.merge(param_name => scope.prev_page), options.reverse_merge(:rel => 'previous') do
block.call if block
end
end
# A simple "Twitter like" pagination link that creates a link to the next page.
@@ -62,11 +62,11 @@
# <span>No More Pages</span>
# <% end %>
def link_to_next_page(scope, name, options = {}, &block)
params = options.delete(:params) || {}
param_name = options.delete(:param_name) || Kaminari.config.param_name
- link_to_unless scope.last_page?, name, params.merge(param_name => (scope.current_page + 1)), options.reverse_merge(:rel => 'next') do
+ link_to_unless scope.last_page?, name, params.merge(param_name => scope.next_page), options.reverse_merge(:rel => 'next') do
block.call if block
end
end
# Renders a helpful message with numbers of displayed vs. total entries.
@@ -84,21 +84,11 @@
# Override this with the <tt>:entry_name</tt> parameter:
#
# <%= 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
t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
else
@@ -129,21 +119,11 @@
def rel_next_prev_link_tags(scope, options = {})
params = options.delete(:params) || {}
param_name = options.delete(:param_name) || Kaminari.config.param_name
output = ""
-
- if !scope.first_page? && !scope.last_page?
- # If not first and not last, then output both links.
- output << '<link rel="next" href="' + url_for(params.merge(param_name => (scope.current_page + 1), :only_path => true)) + '"/>'
- output << '<link rel="prev" href="' + url_for(params.merge(param_name => (scope.current_page - 1), :only_path => true)) + '"/>'
- elsif scope.first_page?
- # If first page, add next link unless last page.
- output << '<link rel="next" href="' + url_for(params.merge(param_name => (scope.current_page + 1), :only_path => true)) + '"/>' unless scope.last_page?
- else
- # If last page, add prev link unless first page.
- output << '<link rel="prev" href="' + url_for(params.merge(param_name => (scope.current_page - 1), :only_path => true)) + '"/>' unless scope.first_page?
- end
+ output << '<link rel="next" href="' + url_for(params.merge(param_name => scope.next_page, :only_path => true)) + '"/>' if scope.next_page
+ output << '<link rel="prev" href="' + url_for(params.merge(param_name => scope.prev_page, :only_path => true)) + '"/>' if scope.prev_page
output.html_safe
end
end
end