pagy 43.4.4 → 43.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/apps/calendar.ru +1 -1
- data/apps/demo.ru +2 -2
- data/apps/keynav+root_key.ru +1 -1
- data/apps/keynav.ru +3 -3
- data/apps/keyset.ru +3 -3
- data/apps/keyset_sequel.ru +2 -2
- data/apps/rails.ru +2 -2
- data/apps/repro.ru +3 -3
- data/config/pagy.rb +9 -18
- data/javascripts/pagy.js +20 -12
- data/javascripts/pagy.min.js +1 -1
- data/javascripts/pagy.mjs +18 -10
- data/lib/pagy/classes/calendar/calendar.rb +6 -8
- data/lib/pagy/classes/calendar/unit.rb +10 -10
- data/lib/pagy/classes/exceptions.rb +3 -3
- data/lib/pagy/classes/keyset/adapters/active_record.rb +0 -6
- data/lib/pagy/classes/keyset/adapters/sequel.rb +1 -7
- data/lib/pagy/classes/keyset/keynav.rb +6 -6
- data/lib/pagy/classes/keyset/keyset.rb +7 -8
- data/lib/pagy/classes/offset/countless.rb +5 -10
- data/lib/pagy/classes/offset/offset.rb +2 -1
- data/lib/pagy/classes/offset/search.rb +1 -1
- data/lib/pagy/classes/request.rb +4 -1
- data/lib/pagy/cli.rb +8 -21
- data/lib/pagy/console.rb +2 -0
- data/lib/pagy/deprecated.rb +84 -0
- data/lib/pagy/modules/abilities/configurable.rb +1 -7
- data/lib/pagy/modules/abilities/countable.rb +1 -2
- data/lib/pagy/modules/abilities/linkable.rb +6 -5
- data/lib/pagy/modules/abilities/rangeable.rb +1 -2
- data/lib/pagy/modules/console.rb +1 -1
- data/lib/pagy/modules/i18n/i18n.rb +1 -1
- data/lib/pagy/modules/searcher.rb +0 -1
- data/lib/pagy/next.rb +25 -0
- data/lib/pagy/tasks/sync.rb +1 -0
- data/lib/pagy/toolbox/helpers/anchor_tags.rb +0 -2
- data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +0 -1
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +0 -1
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +0 -1
- data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +0 -1
- data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/headers_hash.rb +1 -1
- data/lib/pagy/toolbox/helpers/info_tag.rb +2 -2
- data/lib/pagy/toolbox/helpers/input_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/limit_tag_js.rb +3 -4
- data/lib/pagy/toolbox/helpers/loaders.rb +1 -1
- data/lib/pagy/toolbox/helpers/page_url.rb +0 -1
- data/lib/pagy/toolbox/helpers/series_nav.rb +0 -1
- data/lib/pagy/toolbox/helpers/series_nav_js.rb +0 -1
- data/lib/pagy/toolbox/helpers/support/a_lambda.rb +2 -3
- data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +0 -1
- data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +0 -2
- data/lib/pagy/toolbox/helpers/support/series.rb +2 -2
- data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +1 -2
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +1 -2
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +3 -3
- data/lib/pagy/toolbox/helpers/urls_hash.rb +0 -1
- data/lib/pagy/toolbox/paginators/calendar.rb +1 -1
- data/lib/pagy/toolbox/paginators/countish.rb +0 -1
- data/lib/pagy/toolbox/paginators/countless.rb +0 -1
- data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +2 -3
- data/lib/pagy/toolbox/paginators/keynav_js.rb +0 -2
- data/lib/pagy/toolbox/paginators/keyset.rb +0 -1
- data/lib/pagy/toolbox/paginators/meilisearch.rb +0 -1
- data/lib/pagy/toolbox/paginators/method.rb +1 -1
- data/lib/pagy/toolbox/paginators/offset.rb +0 -1
- data/lib/pagy/toolbox/paginators/searchkick.rb +0 -1
- data/lib/pagy/toolbox/paginators/typesense_rails.rb +0 -1
- data/lib/pagy.rb +6 -16
- metadata +5 -4
- data/sig/pagy.rbs +0 -315
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
class Pagy
|
|
4
4
|
module NumericHelpers
|
|
5
|
-
# Instances with count return "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
|
|
6
|
-
# Instances with no count return only page info: "Page 3 of 100"
|
|
5
|
+
# Instances with count return "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total".
|
|
6
|
+
# Instances with no count return only page info: "Page 3 of 100".
|
|
7
7
|
def info_tag(id: nil, item_name: nil)
|
|
8
8
|
i18n_key = if @count.nil?
|
|
9
9
|
'pagy.info_tag.no_count'
|
|
@@ -4,7 +4,6 @@ require_relative 'support/wrap_input_nav_js'
|
|
|
4
4
|
|
|
5
5
|
class Pagy
|
|
6
6
|
module NumericHelpers
|
|
7
|
-
# JavaScript input pagination: it returns a nav with a data-pagy attribute used by the pagy.js file
|
|
8
7
|
def input_nav_js(style = nil, **)
|
|
9
8
|
return send(:"#{style}_input_nav_js", **) if style && style.to_s != 'pagy'
|
|
10
9
|
|
|
@@ -4,11 +4,10 @@ require_relative 'support/data_pagy_attribute'
|
|
|
4
4
|
|
|
5
5
|
class Pagy
|
|
6
6
|
module NumericHelpers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
raise OptionError.new(self, :client_max_limit, 'to be truthy', client_max_limit) unless client_max_limit
|
|
7
|
+
def limit_tag_js(id: nil, item_name: nil, max_limit: @options[:max_limit], **)
|
|
8
|
+
raise OptionError.new(self, :max_limit, 'to be truthy', max_limit) unless max_limit
|
|
10
9
|
|
|
11
|
-
limit_input = %(<input name="limit" type="number" min="1" max="#{
|
|
10
|
+
limit_input = %(<input name="limit" type="number" min="1" max="#{max_limit}" value="#{
|
|
12
11
|
@limit}" style="padding: 0; text-align: center; width: #{@limit.to_s.length + 1}rem;">#{A_TAG})
|
|
13
12
|
|
|
14
13
|
url_token = compose_page_url(PAGE_TOKEN, limit: LIMIT_TOKEN)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
class Pagy
|
|
4
4
|
# The aliaser defines loader methods and aliases them.
|
|
5
|
-
# When a method is called for the first time, its loader will load the full implementation
|
|
5
|
+
# When a method is called for the first time, its loader will load the full implementation,
|
|
6
6
|
# which will overwrite the alias and will be executed.
|
|
7
7
|
# Subsequent calls will run the full implementation directly.
|
|
8
8
|
aliaser = lambda do |receiver, paths|
|
|
@@ -4,7 +4,6 @@ require_relative 'support/wrap_series_nav_js'
|
|
|
4
4
|
|
|
5
5
|
class Pagy
|
|
6
6
|
module NumericHelpers
|
|
7
|
-
# Return a nav with a data-pagy attribute used by the pagy.js file
|
|
8
7
|
def series_nav_js(style = nil, **)
|
|
9
8
|
return send(:"#{style}_series_nav_js", **) if style && style.to_s != 'pagy'
|
|
10
9
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
class Pagy
|
|
4
4
|
protected
|
|
5
5
|
|
|
6
|
-
# Label for any page. Allow the customization of the output
|
|
7
6
|
def page_label(page, **options)
|
|
8
7
|
return page.to_s unless calendar?
|
|
9
8
|
|
|
@@ -11,8 +10,8 @@ class Pagy
|
|
|
11
10
|
localize(starting_time_for(page.to_i), **options) # page could be a string
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
# Return a performance optimized lambda to generate the anchor tag
|
|
15
|
-
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
|
|
13
|
+
# Return a performance optimized lambda to generate the anchor tag.
|
|
14
|
+
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to.
|
|
16
15
|
def a_lambda(anchor_string: @options[:anchor_string], **)
|
|
17
16
|
left, right = %(<a href="#{compose_page_url(PAGE_TOKEN, **)}"#{
|
|
18
17
|
%( #{anchor_string}) if anchor_string}).split(PAGE_TOKEN, 2)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Relegate internal functions. Make overriding navs easier.
|
|
4
3
|
class Pagy
|
|
5
4
|
private
|
|
6
5
|
|
|
7
|
-
# Compose the aria label attribute for the nav
|
|
8
6
|
def nav_aria_label_attribute(aria_label: nil)
|
|
9
7
|
aria_label ||= I18n.translate('pagy.aria_label.nav', count: @last)
|
|
10
8
|
%(aria-label="#{aria_label}")
|
|
@@ -5,7 +5,7 @@ class Pagy
|
|
|
5
5
|
|
|
6
6
|
protected
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# The array of page numbers and :gap e.g. [1, :gap, 8, "9", 10, :gap, 36]
|
|
9
9
|
def series(slots: @options[:slots] || SERIES_SLOTS, compact: @options[:compact], **)
|
|
10
10
|
raise OptionError.new(self, :slots, 'to be an Integer >= 0', slots) unless slots.is_a?(Integer) && slots >= 0
|
|
11
11
|
return [] if slots.zero?
|
|
@@ -14,7 +14,7 @@ class Pagy
|
|
|
14
14
|
if slots >= @last
|
|
15
15
|
series.push(*1..@last)
|
|
16
16
|
else
|
|
17
|
-
half = (slots - 1) / 2 # the left half
|
|
17
|
+
half = (slots - 1) / 2 # even slots makes the left half shorter by 1
|
|
18
18
|
start = if @page <= half # @page in the first half
|
|
19
19
|
1
|
|
20
20
|
elsif @page > (@last - slots + half) # @page in the last half
|
|
@@ -4,11 +4,10 @@ require_relative 'nav_aria_label_attribute'
|
|
|
4
4
|
require_relative 'data_pagy_attribute'
|
|
5
5
|
require_relative 'a_lambda' # inherited use
|
|
6
6
|
|
|
7
|
-
# Relegate internal functions. Make overriding navs easier.
|
|
8
7
|
class Pagy
|
|
9
8
|
private
|
|
10
9
|
|
|
11
|
-
#
|
|
10
|
+
# Common input_nav_js logic
|
|
12
11
|
def wrap_input_nav_js(html, nav_classes, id: nil, aria_label: nil, **)
|
|
13
12
|
%(<nav#{%( id="#{id}") if id} class="#{nav_classes}" #{
|
|
14
13
|
nav_aria_label_attribute(aria_label:)} #{
|
|
@@ -5,11 +5,10 @@ require_relative 'nav_aria_label_attribute'
|
|
|
5
5
|
require_relative 'data_pagy_attribute'
|
|
6
6
|
require_relative 'a_lambda' # inherited use
|
|
7
7
|
|
|
8
|
-
# Relegate internal functions. Make overriding navs easier.
|
|
9
8
|
class Pagy
|
|
10
9
|
private
|
|
11
10
|
|
|
12
|
-
#
|
|
11
|
+
# Common series_nav logic
|
|
13
12
|
def wrap_series_nav(html, nav_classes, id: nil, aria_label: nil, **)
|
|
14
13
|
data = %( #{data_pagy_attribute(:k, @update)}) if keynav?
|
|
15
14
|
|
|
@@ -9,7 +9,7 @@ require_relative 'a_lambda' # inherited use
|
|
|
9
9
|
class Pagy
|
|
10
10
|
private
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# The reverse-sorted array of widths, series, and labels generated from the :steps hash.
|
|
13
13
|
# If :steps is false it will use the single {0 => @options[:slots]} length
|
|
14
14
|
def sequels(steps: @options[:steps] || { 0 => @options[:slots] || SERIES_SLOTS }, **)
|
|
15
15
|
raise OptionError.new(self, :steps, 'to define the 0 width', steps) unless steps.key?(0)
|
|
@@ -18,7 +18,7 @@ class Pagy
|
|
|
18
18
|
[widths, series, page_labels(series)]
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
# Support
|
|
21
|
+
# Support the Calendar API
|
|
22
22
|
def page_labels(series)
|
|
23
23
|
return unless calendar?
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ class Pagy
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
#
|
|
30
|
+
# Common series_nav_js logic
|
|
31
31
|
def wrap_series_nav_js(tokens, nav_classes, id: nil, aria_label: nil, **)
|
|
32
32
|
sequels = sequels(**)
|
|
33
33
|
nav_classes = "pagy-rjs #{nav_classes}" if sequels[0].size > 1
|
|
@@ -4,7 +4,7 @@ class Pagy
|
|
|
4
4
|
module CalendarPaginator
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
|
-
# Take a collection and a
|
|
7
|
+
# Take a collection and a config Hash and return [calendar, pagy, results]
|
|
8
8
|
def paginate(context, collection, config)
|
|
9
9
|
context.instance_eval do
|
|
10
10
|
allowed_options = Calendar::UNITS + %i[offset disabled request]
|
|
@@ -6,7 +6,6 @@ class Pagy
|
|
|
6
6
|
module ElasticsearchRailsPaginator
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
|
-
# Paginate from the search object
|
|
10
9
|
def paginate(search, options)
|
|
11
10
|
if search.is_a?(Search::Arguments) # Active mode
|
|
12
11
|
|
|
@@ -33,7 +32,7 @@ class Pagy
|
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
#
|
|
35
|
+
# Support different versions of ElasticsearchRails
|
|
37
36
|
def pagination_params_from(response_object)
|
|
38
37
|
definition = response_object.search.definition
|
|
39
38
|
definition = definition.to_hash if definition.respond_to?(:to_hash)
|
|
@@ -45,7 +44,7 @@ class Pagy
|
|
|
45
44
|
[from, size]
|
|
46
45
|
end
|
|
47
46
|
|
|
48
|
-
#
|
|
47
|
+
# Support different versions of ElasticsearchRails
|
|
49
48
|
def total_count_from(response_object)
|
|
50
49
|
total = response_object.instance_eval do
|
|
51
50
|
respond_to?(:response) ? response['hits']['total'] : raw_response['hits']['total']
|
|
@@ -6,8 +6,6 @@ class Pagy
|
|
|
6
6
|
module KeynavJsPaginator
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
|
-
# Return the Pagy::Keyset::Keynav instance and paginated records.
|
|
10
|
-
# Fall back to :countless if the :page has no client data.
|
|
11
9
|
def paginate(set, options)
|
|
12
10
|
page = options[:request].resolve_page(force_integer: false) # allow nil
|
|
13
11
|
|
|
@@ -4,7 +4,6 @@ class Pagy
|
|
|
4
4
|
module KeysetPaginator
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
|
-
# Return Pagy::Keyset instance and paginated records
|
|
8
7
|
def paginate(set, options)
|
|
9
8
|
options[:page] ||= options[:request].resolve_page(force_integer: false) # allow nil
|
|
10
9
|
options[:limit] = options[:request].resolve_limit
|
|
@@ -29,7 +29,7 @@ class Pagy
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
options[:root_key] = 'page' if options[:jsonapi] # enforce 'page' root_key for JSON:API
|
|
32
|
-
options[:request] ||= request #
|
|
32
|
+
options[:request] ||= request # custom request Hash or self.request
|
|
33
33
|
options[:request] = Request.new(options) # Pagy::Request
|
|
34
34
|
|
|
35
35
|
Pagy.const_get(paginators[paginator]).paginate(*arguments)
|
data/lib/pagy.rb
CHANGED
|
@@ -7,10 +7,9 @@ require_relative 'pagy/modules/abilities/linkable'
|
|
|
7
7
|
require_relative 'pagy/modules/abilities/configurable'
|
|
8
8
|
require_relative 'pagy/toolbox/helpers/loaders'
|
|
9
9
|
|
|
10
|
-
# Top superclass
|
|
11
|
-
# noinspection RubyMismatchedArgumentType
|
|
10
|
+
# Top superclass
|
|
12
11
|
class Pagy
|
|
13
|
-
VERSION = '43.
|
|
12
|
+
VERSION = '43.5.1'
|
|
14
13
|
ROOT = Pathname.new(__dir__).parent.freeze
|
|
15
14
|
DEFAULT = { limit: 20, limit_key: 'limit', page_key: 'page' }.freeze
|
|
16
15
|
PAGE_TOKEN = EscapedValue.new('P ')
|
|
@@ -34,12 +33,6 @@ class Pagy
|
|
|
34
33
|
|
|
35
34
|
OPTIONS = {} # rubocop:disable Style/MutableConstant
|
|
36
35
|
|
|
37
|
-
def self.options
|
|
38
|
-
OPTIONS.tap do
|
|
39
|
-
warn "[PAGY] 'Pagy.options' is deprecated: use 'Pagy::OPTIONS directly'"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
36
|
extend Configurable
|
|
44
37
|
include Linkable
|
|
45
38
|
include HelperLoader
|
|
@@ -48,7 +41,7 @@ class Pagy
|
|
|
48
41
|
|
|
49
42
|
protected
|
|
50
43
|
|
|
51
|
-
#
|
|
44
|
+
# Instance identity methods, overridden by the respective classes
|
|
52
45
|
def offset? = false
|
|
53
46
|
def countless? = false
|
|
54
47
|
def calendar? = false
|
|
@@ -56,7 +49,7 @@ class Pagy
|
|
|
56
49
|
def keyset? = false
|
|
57
50
|
def keynav? = false
|
|
58
51
|
|
|
59
|
-
#
|
|
52
|
+
# Validate presence and min value of options
|
|
60
53
|
def assign_and_check(name_min)
|
|
61
54
|
name_min.each do |name, min|
|
|
62
55
|
value = @options[name]
|
|
@@ -71,11 +64,6 @@ class Pagy
|
|
|
71
64
|
|
|
72
65
|
# Merge all the DEFAULT constants of the class hierarchy with the options
|
|
73
66
|
def assign_options(**options)
|
|
74
|
-
if options.key?(:max_pages)
|
|
75
|
-
warn "[PAGY] the ':max_pages' option is deprecated: " \
|
|
76
|
-
'use https://ddnexus.github.io/pagy/guides/how-to/#paginate-only-max-records instead.'
|
|
77
|
-
end
|
|
78
|
-
|
|
79
67
|
@request = options.delete(:request) # internal object
|
|
80
68
|
default = {}
|
|
81
69
|
current = self.class
|
|
@@ -95,3 +83,5 @@ class Pagy
|
|
|
95
83
|
include NumericHelperLoader
|
|
96
84
|
end
|
|
97
85
|
end
|
|
86
|
+
|
|
87
|
+
require_relative ENV['PAGY_NEXT'] == 'true' ? 'pagy/next' : 'pagy/deprecated'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pagy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 43.
|
|
4
|
+
version: 43.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Domizio Demichelis
|
|
@@ -98,6 +98,7 @@ files:
|
|
|
98
98
|
- lib/pagy/classes/request.rb
|
|
99
99
|
- lib/pagy/cli.rb
|
|
100
100
|
- lib/pagy/console.rb
|
|
101
|
+
- lib/pagy/deprecated.rb
|
|
101
102
|
- lib/pagy/modules/abilities/configurable.rb
|
|
102
103
|
- lib/pagy/modules/abilities/countable.rb
|
|
103
104
|
- lib/pagy/modules/abilities/linkable.rb
|
|
@@ -115,6 +116,7 @@ files:
|
|
|
115
116
|
- lib/pagy/modules/i18n/p11n/polish.rb
|
|
116
117
|
- lib/pagy/modules/i18n/p11n/west_slavic.rb
|
|
117
118
|
- lib/pagy/modules/searcher.rb
|
|
119
|
+
- lib/pagy/next.rb
|
|
118
120
|
- lib/pagy/tasks/sync.rb
|
|
119
121
|
- lib/pagy/toolbox/helpers/anchor_tags.rb
|
|
120
122
|
- lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb
|
|
@@ -191,7 +193,6 @@ files:
|
|
|
191
193
|
- locales/zh-CN.yml
|
|
192
194
|
- locales/zh-HK.yml
|
|
193
195
|
- locales/zh-TW.yml
|
|
194
|
-
- sig/pagy.rbs
|
|
195
196
|
- stylesheets/pagy-tailwind.css
|
|
196
197
|
- stylesheets/pagy.css
|
|
197
198
|
homepage: https://github.com/ddnexus/pagy
|
|
@@ -211,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
211
212
|
requirements:
|
|
212
213
|
- - ">="
|
|
213
214
|
- !ruby/object:Gem::Version
|
|
214
|
-
version: '3.
|
|
215
|
+
version: '3.3'
|
|
215
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
217
|
requirements:
|
|
217
218
|
- - ">="
|
|
218
219
|
- !ruby/object:Gem::Version
|
|
219
220
|
version: '0'
|
|
220
221
|
requirements: []
|
|
221
|
-
rubygems_version: 4.0.
|
|
222
|
+
rubygems_version: 4.0.6
|
|
222
223
|
specification_version: 4
|
|
223
224
|
summary: "Pagy \U0001F438 The Leaping Gem!"
|
|
224
225
|
test_files: []
|