Sha256: e4b55d5b3ccac057b65085739c207473a36c0c28a272d5758eee760a1ec4ca1b

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
# frozen_string_literal: true

class Pagy

  module Frontend

    # boolean used by the compact navs
    TRIM = true

    def pagy_trim_url(url, param_string)
      url.sub(/((?:[?&])#{param_string}\z|\b(?<=[?&])#{param_string}&)/, '')
    end

    alias_method :pagy_link_proc_without_trim, :pagy_link_proc
    def pagy_link_proc_with_trim(pagy, link_extra='')
      p_prev, p_next, p_vars = pagy.prev, pagy.next, pagy.vars
      url   = pagy_url_for(MARKER, pagy)
      p1url = pagy_trim_url(url, "#{p_vars[:page_param]}=#{MARKER}")
      p1    = %(<a href="#{p1url}" #{p_vars[:link_extra]} #{link_extra})
      a, b = %(<a href="#{url}" #{p_vars[:link_extra]} #{link_extra}).split(MARKER, 2)
      -> (n, text=n, extra='') { start = n.to_i == 1 ? p1 : "#{a}#{n}#{b}"
                                 "#{start}#{ if    n == p_prev ; ' rel="prev"'
                                             elsif n == p_next ; ' rel="next"'
                                             else                           '' end } #{extra}>#{text}</a>" }
    end
    alias_method :pagy_link_proc, :pagy_link_proc_with_trim

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagy-0.19.1 lib/pagy/extras/trim.rb