# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/plain
# encoding: utf-8
# frozen_string_literal: true
require 'pagy/extras/shared'
class Pagy
module Frontend
# added alias for symmetry
alias :pagy_plain_nav :pagy_nav
# Plain compact pagination: it returns the html with the series of links to the pages
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
def pagy_plain_compact_nav(pagy, id=pagy_id)
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
html = EMPTY + %(#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
end
# Plain responsive pagination: it returns the html with the series of links to the pages
# rendered by the Pagy.responsive javascript
def pagy_plain_responsive_nav(pagy, id=pagy_id)
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
tags['before'] = (p_prev ? %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} )
: %(#{pagy_t('pagy.nav.prev')} ))
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
tags[item.to_s] = if item.is_a?(Integer); %(#{link.call item} ) # page link
elsif item.is_a?(String) ; %(#{item} ) # current page
elsif item == :gap ; %(#{pagy_t('pagy.nav.gap')} ) # page gap
end
end
tags['after'] = (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'})
: %(#{pagy_t('pagy.nav.next')}))
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
%(#{script})
end
end
end