# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize # encoding: utf-8 # frozen_string_literal: true require 'pagy/extras/shared' class Pagy module Frontend # Pagination for materialize: it returns the html with the series of links to the pages def pagy_materialize_nav(pagy) link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next html = EMPTY + (p_prev ? %() : %()) pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] html << if item.is_a?(Integer); %(
  • #{link.call item}
  • ) # page link elsif item.is_a?(String) ; %(
  • #{link.call item}
  • ) # active page elsif item == :gap ; %(
  • #{pagy_t('pagy.nav.gap')}
  • ) # page gap end end html << (p_next ? %() : %()) %() end # Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript def pagy_materialize_nav_js(pagy, id=pagy_id) link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next tags = { 'before' => ( '' ) } %(#{pagy_json_tag(:nav, id, tags, pagy.sequels, defined?(TRIM) && pagy.vars[:page_param])}) end # Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript def pagy_materialize_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 = %(