lib/pagy/extras/materialize.rb in pagy-5.3.1 vs lib/pagy/extras/materialize.rb in pagy-5.4.0

- old
+ new

@@ -6,17 +6,17 @@ 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, pagy_id: nil, link_extra: '') + def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '', **vars) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">) html << pagy_materialize_prev_html(pagy, link) - pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] + pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] html << case item when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link when String then %(<li class="active">#{link.call item}</li>) # active page when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" @@ -25,21 +25,21 @@ html << pagy_materialize_next_html(pagy, link) html << %(</ul></div>) 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, pagy_id: nil, link_extra: '', steps: nil) + def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '', **vars) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: link_extra) tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}), 'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</li>), 'active' => %(<li class="active">#{mark}</li>), 'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>), 'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) } %(<div#{p_id} class="pagy-njs pagy-materialize-nav-js" role="navigation" aria-label="pager" #{ - pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(steps)), pagy.label_sequels(sequels))}></div>) + pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></div>) 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, pagy_id: nil, link_extra: '') p_id = %( id="#{pagy_id}") if pagy_id