lib/pagy/extras/items.rb in pagy-1.1.0 vs lib/pagy/extras/items.rb in pagy-1.2.0

- old
+ new

@@ -1,8 +1,10 @@ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items # frozen_string_literal: true +require 'pagy/extras/shared' + class Pagy # Default variables for this extra VARS[:items_param] = :items VARS[:max_items] = 100 @@ -42,17 +44,17 @@ "#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}" end alias_method :pagy_url_for, :pagy_url_for_with_items # Return the items selector HTML. For example "Show [20] items per page" - def pagy_items_selector(pagy, id=caller(1,1)[0].hash) + def pagy_items_selector(pagy, id=caller(1,1)[0].hash.to_s) pagy = pagy.clone; p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-" - html = +%(<span id="pagy-items-#{id}">) + html = +%(<span id="#{id}">) html << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>) input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">) html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)}) - html << %(</span><script type="application/json" class="pagy-items-json">["#{id}", "#{MARKER}", #{pagy.from}]</script>) + html << %(</span>#{pagy_json_tag(:items, id, MARKER, pagy.from)}) end end end