Module: Pagy::TrimExtra
- Included in:
- Frontend
- Defined in:
- lib/pagy/extras/trim.rb
Overview
Remove the page=1 param from the first page link
Instance Method Summary collapse
-
#pagy_link_proc(pagy, link_extra: '') ⇒ Object
Override the original pagy_link_proc.
-
#pagy_trim(pagy, link) ⇒ Object
Remove the the :page_param param from the first page link.
Instance Method Details
#pagy_link_proc(pagy, link_extra: '') ⇒ Object
Override the original pagy_link_proc. Call the pagy_trim method if the trim_extra is enabled.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pagy/extras/trim.rb', line 11 def pagy_link_proc(pagy, link_extra: '') link_proc = super(pagy, link_extra: link_extra) return link_proc unless pagy.vars[:trim_extra] lambda do |page, text = pagy.label_for(page), extra = ''| link = +link_proc.call(page, text, extra) return link unless page == 1 pagy_trim(pagy, link) end end |
#pagy_trim(pagy, link) ⇒ Object
Remove the the :page_param param from the first page link
24 25 26 |
# File 'lib/pagy/extras/trim.rb', line 24 def pagy_trim(pagy, link) link.sub!(/(\?|&)#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '') end |