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
link_to_if(condition, name, options = {}, html_options = {}, &block)
click to toggle source
# File lib/kaminari/helpers/sinatra_helpers.rb, line 72 def link_to_if(condition, name, options = {}, html_options = {}, &block) options = url_for(options) if options.is_a? Hash if condition link_to(name, options, html_options) elsif block_given? capture_html(&block).html_safe else name end end
link_to_unless(condition, name, options = {}, html_options = {}, &block)
click to toggle source
# File lib/kaminari/helpers/sinatra_helpers.rb, line 83 def link_to_unless(condition, name, options = {}, html_options = {}, &block) link_to_if !condition, name, options, html_options, &block end
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