lib/kaminari/helpers/sinatra_helpers.rb in kaminari-0.15.1 vs lib/kaminari/helpers/sinatra_helpers.rb in kaminari-0.16.0
- old
+ new
@@ -91,10 +91,40 @@
options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
)
paginator.to_s
end
+ # A simple "Twitter like" pagination link that creates a link to the previous page.
+ # Works on Sinatra.
+ #
+ # ==== Examples
+ # Basic usage:
+ #
+ # <%= link_to_previous_page @items, 'Previous Page' %>
+ #
+ # Ajax:
+ #
+ # <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
+ #
+ # By default, it renders nothing if there are no more results on the previous page.
+ # You can customize this output by passing a parameter <tt>:placeholder</tt>.
+ #
+ # <%= link_to_previous_page @users, 'Previous Page', :placeholder => %{<span>At the Beginning</span>} %>
+ #
+ def link_to_previous_page(scope, name, options = {})
+ params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
+ param_name = options.delete(:param_name) || Kaminari.config.param_name
+ placeholder = options.delete(:placeholder)
+
+ unless scope.first_page?
+ query = params.merge(param_name => scope.prev_page)
+ link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'previous')
+ else
+ placeholder.to_s.html_safe
+ end
+ end
+
# A simple "Twitter like" pagination link that creates a link to the next page.
# Works on Sinatra.
#
# ==== Examples
# Basic usage:
@@ -112,14 +142,15 @@
#
def link_to_next_page(scope, name, options = {})
params = options.delete(:params) || (Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
param_name = options.delete(:param_name) || Kaminari.config.param_name
placeholder = options.delete(:placeholder)
- query = params.merge(param_name => (scope.current_page + 1))
+
unless scope.last_page?
+ query = params.merge(param_name => scope.next_page)
link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'next')
else
- placeholder
+ placeholder.to_s.html_safe
end
end
end
end
end