A simple “Twitter like” pagination link that creates a link to the next page. Works on Sinatra.
Basic usage:
<%= link_to_next_page @items, 'Next Page' %>
Ajax:
<%= link_to_next_page @items, 'Next Page', :remote => true %>
By default, it renders nothing if there are no more results on the next page. You can customize this output by passing a parameter :placeholder.
<%= link_to_next_page @items, 'Next Page', :placeholder => %{<span>No More Pages</span>} %>
# File lib/kaminari/helpers/sinatra_helpers.rb, line 143 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) 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.to_s.html_safe end end
A simple “Twitter like” pagination link that creates a link to the previous page. Works on Sinatra.
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 :placeholder.
<%= link_to_previous_page @users, 'Previous Page', :placeholder => %{<span>At the Beginning</span>} %>
# File lib/kaminari/helpers/sinatra_helpers.rb, line 113 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 helper that renders the pagination links - for Sinatra.
<%= paginate @articles %>
:window - The "inner window" size (4 by default).
:outer_window - The "outer window" size (0 by default).
:left - The "left outer window" size (0 by default).
:right - The "right outer window" size (0 by default).
:params - url_for parameters for the links (:id, :locale, etc.)
:param_name - parameter name for page number in the links (:page by default)
:remote - Ajax? (false by default)
:ANY_OTHER_VALUES - Any other hash key & values would be directly passed into each tag as :locals value.
# File lib/kaminari/helpers/sinatra_helpers.rb, line 86 def paginate(scope, options = {}, &block) current_path = env['PATH_INFO'] rescue nil current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {} paginator = Kaminari::Helpers::Paginator.new( ActionViewTemplateProxy.new(:current_params => current_params, :current_path => current_path, :param_name => options[:param_name] || Kaminari.config.param_name), 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
Generated with the Darkfish Rdoc Generator 2.