# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
# frozen_string_literal: true
require 'pagy/extras/shared'
class Pagy
module Frontend
# Generic 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_nav_compact(pagy, id=caller(1,1)[0].hash)
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
html << %()
end
# Generic responsive pagination: it returns the html with the series of links to the pages
# rendered by the Pagy.responsive javascript
def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
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 = %()
%(#{script})
end
end
end