# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma # encoding: utf-8 # 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, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next html = (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') : %(#{pagy_t('pagy.nav.prev')})) \ + (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') : %(#{pagy_t('pagy.nav.next')})) html << '' %() end # Javascript pagination for bulma: it returns a nav and a JSON tag used by the Pagy.nav javascript def pagy_bulma_nav_js(pagy, id=pagy_id) link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next tags = { 'before' => ( (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') : %(#{pagy_t('pagy.nav.prev')})) \ + (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') : %(#{pagy_t('pagy.nav.next')})) \ + '' } %(#{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, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), 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