lib/pagy/extras/semantic.rb in pagy-5.2.3 vs lib/pagy/extras/semantic.rb in pagy-5.3.0

- old
+ new

@@ -1,9 +1,9 @@ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic # frozen_string_literal: true -require 'pagy/extras/shared' +require 'pagy/extras/frontend_helpers' class Pagy # :nodoc: # Frontend modules are specially optimized for performance. # The resulting code may not look very elegant, but produces the best benchmarks module SemanticExtra @@ -15,11 +15,11 @@ html = +%(<div#{p_id} class="pagy-semantic-nav ui pagination menu">) html << pagy_semantic_prev_html(pagy, link) pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] html << case item when Integer then link.call item - when String then %(<a class="item active">#{pagy_labeler(pagy, item)}</a>) + when String then %(<a class="item active">#{pagy.label_for(item)}</a>) when :gap then %(<div class="disabled item">#{pagy_t 'pagy.nav.gap'}</div>) else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" end end html << pagy_semantic_next_html(pagy, link) @@ -29,16 +29,16 @@ # Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript def pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '', steps: nil) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra})) tags = { 'before' => pagy_semantic_prev_html(pagy, link), - 'link' => link.call(PAGE_PLACEHOLDER), - 'active' => %(<a class="item active">#{pagy.page}</a>), + 'link' => link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER), + 'active' => %(<a class="item active">#{LABEL_PLACEHOLDER}</a>), 'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>), 'after' => pagy_semantic_next_html(pagy, link) } %(<div#{p_id} class="pagy-njs pagy-semantic-nav-js ui pagination menu" role="navigation" #{ - pagy_json_attr(pagy, :nav, tags, pagy.sequels(steps))}></div>) + pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(steps)), pagy.label_sequels(sequels))}></div>) end # Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript def pagy_semantic_combo_nav_js(pagy, pagy_id: nil, link_extra: '') p_id = %( id="#{pagy_id}") if pagy_id