Module: Pagy::StandaloneExtra
Overview
Use pagy without any request object, nor Rack environment/gem, nor any defined params method, even in the irb/rails console without any app or config.
Defined Under Namespace
Modules: QueryUtils
Instance Method Summary collapse
-
#pagy_url_for(pagy, page, absolute: false, html_escaped: false) ⇒ Object
Return the URL for the page.
Instance Method Details
#pagy_url_for(pagy, page, absolute: false, html_escaped: false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pagy/extras/standalone.rb', line 41 def pagy_url_for(pagy, page, absolute: false, html_escaped: false) return super unless pagy.vars[:url] vars = pagy.vars page_param = vars[:page_param].to_s items_param = vars[:items_param].to_s params = pagy.params.is_a?(Hash) ? pagy.params.clone : {} # safe when it gets reused params[page_param] = page params[items_param] = vars[:items] if vars[:items_extra] params = pagy.params.call(params) if pagy.params.is_a?(Proc) query_string = "?#{QueryUtils.build_nested_query(params)}" query_string = query_string.gsub('&', '&') if html_escaped # the only unescaped entity "#{vars[:url]}#{query_string}#{vars[:fragment]}" end |