# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma # frozen_string_literal: true require 'pagy/extras/shared' class Pagy module Frontend # Pagination for Bulma: it returns the html with the series of links to the pages def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '') p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) html = +%() html << pagy_bulma_prev_next_html(pagy, link) html << %() end def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil) pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}' } html = %() html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps)) end # Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '') pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) p_page = pagy.page p_pages = pagy.pages input = %() %(
#{ if (p_prev = pagy.prev) %(

#{link.call p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"'}

) else %(

#{pagy_t 'pagy.nav.prev'}

) end }
#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}
#{ if (p_next = pagy.next) %(

#{link.call p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"'}

) else %(

#{pagy_t 'pagy.nav.next'}

) end }
#{ pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link) }) end private def pagy_bulma_prev_next_html(pagy, link) html = if (p_prev = pagy.prev) link.call p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"' else %(#{pagy_t 'pagy.nav.prev'}) end html << if (p_next = pagy.next) link.call p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"' else %(#{pagy_t 'pagy.nav.next' }) end end end end