# 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) link = pagy_link_proc(pagy) html = +%() end def pagy_bulma_nav_js(pagy, id=pagy_id) link = pagy_link_proc(pagy) tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}' } html = %() html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels) 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, id=pagy_id) link = pagy_link_proc(pagy) p_page = pagy.page p_pages = pagy.pages input = %() %(#{ pagy_json_tag pagy, :combo_nav, id, 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