# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
# encoding: utf-8
# frozen_string_literal: true
require 'pagy/extras/shared'
class Pagy
module Frontend
# Pagination for bootstrap: it returns the html with the series of links to the pages
def pagy_bootstrap_nav(pagy)
link, p_prev, p_next = pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
html = EMPTY + (p_prev ? %(
#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'})
: %(#{pagy_t('pagy.nav.prev')}))
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << if item.is_a?(Integer); %(#{link.call item}) # page link
elsif item.is_a?(String) ; %(#{link.call item}) # active page
elsif item == :gap ; %(#{pagy_t('pagy.nav.gap')}) # page gap
end
end
html << (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'})
: %(#{pagy_t('pagy.nav.next')}))
%()
end
# Compact pagination for bootstrap: 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_bootstrap_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
# Responsive pagination for bootstrap: it returns the html with the series of links to the pages
# rendered by the Pagy.responsive javascript
def pagy_bootstrap_responsive_nav(pagy, id=pagy_id)
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
tags['before'] = EMPTY + ''
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
%(#{script})
end
end
end