# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize # 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, pagy_id: nil, link_extra: '') p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) html = +%() 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, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil) pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) tags = { 'before' => %() } html = %() html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps)) 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, deprecated_id=nil, pagy_id: nil, link_extra: '') pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) p_page = pagy.page p_pages = pagy.pages style = ' style="vertical-align: middle;"' input = %() %(
    #{ pagy_materialize_prev_html pagy, link, style }
    #{ pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages }
    #{ pagy_materialize_next_html pagy, link, style }
#{ pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link) }) end private def pagy_materialize_prev_html(pagy, link, style='') if (p_prev = pagy.prev) %() else %() end end def pagy_materialize_next_html(pagy, link, style='') if (p_next = pagy.next) %() else %() end end end end