lib/pagy/extras/trim.rb in pagy-4.1.0 vs lib/pagy/extras/trim.rb in pagy-4.2.0
- old
+ new
@@ -1,19 +1,23 @@
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
-# encoding: utf-8
# frozen_string_literal: true
class Pagy
- module Trim
+ module UseTrimExtra
+
def pagy_link_proc(pagy, link_extra='')
link_proc = super(pagy, link_extra)
- re = /[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/
- lambda do |n, text=n, extra=''|
- link = link_proc.call(n, text, extra)
- n == 1 ? link.sub(re, '') : link
+ lambda do |num, text=num, extra=''|
+ link = link_proc.call(num, text, extra)
+ if num == 1
+ link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
+ else
+ link
+ end
end
end
+
end
- Frontend.prepend Trim
+ Frontend.prepend UseTrimExtra
end