# 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) html, 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')})) html << (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 Pagy.deprecate self, :pagy_nav_bulma, :pagy_bulma_nav # Compact pagination for Bulma: it returns the html with the series of links to the pages # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate def pagy_bulma_compact_nav(pagy, id=caller(1,1)[0].hash.to_s) html, 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(:compact, id, MARKER, p_page, !!defined?(TRIM))}) end Pagy.deprecate self, :pagy_nav_compact_bulma, :pagy_bulma_compact_nav # Responsive pagination for Bulma: it returns the html with the series of links to the pages # rendered by the Pagy.responsive javascript def pagy_bulma_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s) tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive 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')})) tags['before'] << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"') : %(#{pagy_t('pagy.nav.next')})) tags['before'] << '' script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series]) %(#{script}) end Pagy.deprecate self, :pagy_nav_responsive_bulma, :pagy_bulma_responsive_nav end end