module BootstrapPager::Helpers::SinatraHelpers::HelperMethods

Public Instance Methods

paginate(scope, options = {}, &block) click to toggle source

A helper that renders the pagination links - for Sinatra.

<%= paginate @articles %>

Options

  • :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/bootstrap_pager/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 = BootstrapPager::Helpers::Paginator.new(
    ActionViewTemplateProxy.new(:current_params => current_params, :current_path => current_path, :param_name => options[:param_name] || BootstrapPager.config.param_name),
    options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => BootstrapPager.config.param_name, :remote => false)
  )
  paginator.to_s
end