# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bulma
# frozen_string_literal: true
require 'pagy/extras/frontend_helpers'
class Pagy # :nodoc:
DEFAULT[:bulma_nav_classes] = 'is-centered'
# Frontend modules are specially optimized for performance.
# The resulting code may not look very elegant, but produces the best benchmarks
module BulmaExtra
# 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: '',
nav_aria_label: nil, nav_i18n_key: nil, **vars)
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra:)
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, pagy_id: nil, link_extra: '',
nav_aria_label: nil, nav_i18n_key: nil, **vars)
sequels = pagy.sequels(**vars)
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra:)
tags = { 'before' => %(#{bulma_prev_next_html(pagy, link)}
' }
%()
end
# Javascript combo pagination for bulma: it returns a nav and a JSON tag used by the pagy.js file
def pagy_bulma_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
nav_aria_label: nil, nav_i18n_key: nil)
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra:)
p_page = pagy.page
p_pages = pagy.pages
input = %()
html = %()
end
private
def bulma_prev_next_html(pagy, link)
html = +if (p_prev = pagy.prev)
link.call(p_prev, pagy_t('pagy.prev'), %(#{prev_aria_label_attr} class="pagination-previous"))
else
%(#{pagy_t 'pagy.prev'})
end
html << if (p_next = pagy.next)
link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="pagination-next"))
else
%(#{pagy_t('pagy.next')})
end
end
end
Frontend.prepend BulmaExtra
end