Sha256: ee5b17fbcc2e40756ac5240ecc35c36836a65773d17fa24ce26f4ccf7ed2cf2f

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

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

class Pagy
  module SupportExtra
    def pagy_prev_url(pagy)
      pagy_url_for(pagy, pagy.prev) if pagy.prev
    end

    def pagy_next_url(pagy)
      pagy_url_for(pagy, pagy.next) if pagy.next
    end

    def pagy_prev_link(pagy, text: pagy_t('pagy.nav.prev'), link_extra: '')
      if pagy.prev
        %(<span class="page prev"><a href="#{
            pagy_url_for(pagy, pagy.prev)
          }" rel="prev" aria-label="previous" #{
            pagy.vars[:link_extra]
          } #{link_extra}>#{text}</a></span>)
      else
        %(<span class="page prev disabled">#{text}</span>)
      end
    end

    def pagy_next_link(pagy, text: pagy_t('pagy.nav.next'), link_extra: '')
      if pagy.next
        %(<span class="page next"><a href="#{
            pagy_url_for(pagy, pagy.next)
          }" rel="next" aria-label="next" #{
            pagy.vars[:link_extra]
          } #{link_extra}>#{text}</a></span>)
      else
        %(<span class="page next disabled">#{text}</span>)
      end
    end

    def pagy_prev_link_tag(pagy)
      %(<link href="#{pagy_url_for(pagy, pagy.prev)}" rel="prev"/>) if pagy.prev
    end

    def pagy_next_link_tag(pagy)
      %(<link href="#{pagy_url_for(pagy, pagy.next)}" rel="next"/>) if pagy.next
    end
  end
  Frontend.prepend SupportExtra
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagy-5.0.1 lib/pagy/extras/support.rb
pagy-5.0.0 lib/pagy/extras/support.rb