module Kaminari::Helpers::SinatraHelpers::SinatraHelperMethods

Some helper methods that are used in Kaminari::Helpers::HelperMethods. Plus, monkey-patch for `paginate` to pass in an ActionViewTemplateProxy instance.

Public Instance Methods

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

Overriding `paginate` to pass in an Action View renderer. If you're sure your custom template is compatible with Padrino renderer, you might not need it. In that case, please add `template: self` option when calling this method.

Calls superclass method
# File lib/kaminari/helpers/sinatra_helpers.rb, line 90
def paginate(scope, options = {})
  current_path = env['PATH_INFO'] rescue nil
  current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {}

  template = ActionViewTemplateProxy.new current_params: current_params, current_path: current_path, param_name: options[:param_name] || Kaminari.config.param_name

  super scope, {template: template}.merge(options)
end
url_for(params) click to toggle source
# File lib/kaminari/helpers/sinatra_helpers.rb, line 60
def url_for(params)
  current_path = env['PATH_INFO'] rescue nil
  current_params = Rack::Utils.parse_query(env['QUERY_STRING']) rescue {}

  extra_params = params.dup
  extra_params.delete :only_path

  query = current_params.merge(extra_params)
  res = current_path + (query.empty? ? '' : "?#{query.to_query}")
  res
end