# frozen_string_literal: true warn '[PAGY WARNING] The materialize extra has been discontinued and it will be removed in v9 ' \ '(https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328)' require_relative 'js_tools' class Pagy # :nodoc: # Frontend modules are specially optimized for performance. # The resulting code may not look very elegant, but produces the best benchmarks module MaterializeExtra # Pagination for materialize: it returns the html with the series of links to the pages def pagy_materialize_nav(pagy, id: nil, aria_label: nil, **vars) id = %( id="#{id}") if id a = pagy_anchor(pagy) html = +%() end # Javascript pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file def pagy_materialize_nav_js(pagy, id: nil, aria_label: nil, **vars) sequels = pagy.sequels(**vars) id = %( id="#{id}") if id a = pagy_anchor(pagy) tokens = { 'before' => %() } %() end # Javascript combo pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file def pagy_materialize_combo_nav_js(pagy, id: nil, aria_label: nil) id = %( id="#{id}") if id a = pagy_anchor(pagy) pages = pagy.pages page_input = %( ) << JSTools::A_TAG %(#{ materialize_prev_html(pagy, a) }
  • #{ materialize_next_html(pagy, a) }) end private def materialize_prev_html(pagy, a) if (p_prev = pagy.prev) %() else %() end end def materialize_next_html(pagy, a) if (p_next = pagy.next) %() else %() end end end Frontend.prepend MaterializeExtra end