lib/pagy/extras/shared.rb in pagy-3.0.0 vs lib/pagy/extras/shared.rb in pagy-3.1.0

- old
+ new

@@ -24,24 +24,31 @@ end module Frontend if defined?(Oj) - # returns a script tag with the JSON-serialized args generated with the faster oj gem + # it returns a script tag with the JSON-serialized args generated with the faster oj gem def pagy_json_tag(*args) %(<script type="application/json" class="pagy-json">#{Oj.dump(args, mode: :strict)}</script>) end else require 'json' - # returns a script tag with the JSON-serialized args generated with the slower to_json + # it returns a script tag with the JSON-serialized args generated with the slower to_json def pagy_json_tag(*args) %(<script type="application/json" class="pagy-json">#{args.to_json}</script>) end end - # returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags + # it returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags def pagy_id "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}" + end + + # it return the links hash to used by pagy.js + def pagy_links(link) + links = { 'standard' => link.call(MARK, '', 'style="display: none;"') } + links['trimmed'] = link.call(1, '', 'style="display: none;"') if defined?(TRIM) + links end end end