# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic # encoding: utf-8 # frozen_string_literal: true require 'pagy/extras/shared' class Pagy module Frontend # Pagination for semantic: it returns the html with the series of links to the pages def pagy_semantic_nav(pagy) link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next html = (p_prev ? %(#{link.call p_prev, '', 'aria-label="previous"'}) : +%(
)) 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) ; %(#{item}) # current page elsif item == :gap ; %(
...
) # page gap end end html << (p_next ? %(#{link.call p_next, '', 'aria-label="next"'}) : %(
)) %() end # Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript def pagy_semantic_nav_js(pagy, id=pagy_id) link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next tags = { 'before' => (p_prev ? %(#{link.call(p_prev, '', 'aria-label="previous"')}) : %(
)), 'link' => %(#{link.call(PAGE_PLACEHOLDER)}), 'active' => %(#{pagy.page}), 'gap' => %(
#{pagy_t('pagy.nav.gap')}
), 'after' => (p_next ? %(#{link.call(p_next, '', 'aria-label="next"')}) : %(
)) } %(#{pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)}) end # Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript def pagy_semantic_combo_nav_js(pagy, id=pagy_id) link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages html = %(#{pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))}) end end end