# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic
# 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 = pagy_link_proc(pagy, 'class="item"')
html = +%(
)
html << pagy_semantic_prev_html(pagy, link)
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << case item
when Integer then link.call item # page link
when String then %(#{item}) # current page
when :gap then %(
...
) # page gap
end
end
html << pagy_semantic_next_html(pagy, link)
html << %(
)
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 = pagy_link_proc(pagy, 'class="item"')
tags = { 'before' => pagy_semantic_prev_html(pagy, link),
'link' => link.call(PAGE_PLACEHOLDER),
'active' => %(#{pagy.page}),
'gap' => %(
#{pagy_t('pagy.nav.gap')}
),
'after' => pagy_semantic_next_html(pagy, link) }
html = %()
html << 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 = pagy_link_proc(pagy, 'class="item"')
p_page = pagy.page
p_pages = pagy.pages
input = %()
%(