pagy 9.3.5 → 43.0.0.rc2

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.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +547 -551
  3. data/apps/demo.ru +221 -178
  4. data/apps/index.rb +3 -1
  5. data/apps/keynav.ru +258 -0
  6. data/apps/{keyset_ar.ru → keyset.ru} +27 -32
  7. data/apps/{keyset_s.ru → keyset_sequel.ru} +24 -29
  8. data/apps/rails.ru +51 -48
  9. data/apps/repro.ru +46 -43
  10. data/bin/pagy +20 -21
  11. data/config/pagy.rb +35 -207
  12. data/javascripts/ai_widget.js +76 -0
  13. data/javascripts/pagy.js +151 -0
  14. data/javascripts/pagy.js.map +10 -0
  15. data/javascripts/pagy.min.js +1 -4
  16. data/javascripts/pagy.mjs +111 -63
  17. data/javascripts/wand.js +1166 -0
  18. data/lib/pagy/classes/calendar/calendar.rb +98 -0
  19. data/lib/pagy/{calendar → classes/calendar}/day.rb +7 -11
  20. data/lib/pagy/{calendar → classes/calendar}/month.rb +5 -10
  21. data/lib/pagy/{calendar → classes/calendar}/quarter.rb +10 -15
  22. data/lib/pagy/classes/calendar/unit.rb +92 -0
  23. data/lib/pagy/{calendar → classes/calendar}/week.rb +5 -9
  24. data/lib/pagy/{calendar → classes/calendar}/year.rb +5 -6
  25. data/lib/pagy/classes/exceptions.rb +33 -0
  26. data/lib/pagy/classes/keyset/active_record.rb +11 -0
  27. data/lib/pagy/classes/keyset/adapters/active_record.rb +50 -0
  28. data/lib/pagy/classes/keyset/adapters/sequel.rb +63 -0
  29. data/lib/pagy/classes/keyset/keynav/active_record.rb +13 -0
  30. data/lib/pagy/classes/keyset/keynav/sequel.rb +13 -0
  31. data/lib/pagy/classes/keyset/keynav.rb +77 -0
  32. data/lib/pagy/classes/keyset/keyset.rb +126 -0
  33. data/lib/pagy/classes/keyset/sequel.rb +11 -0
  34. data/lib/pagy/classes/offset/countless.rb +56 -0
  35. data/lib/pagy/classes/offset/offset.rb +54 -0
  36. data/lib/pagy/classes/offset/search.rb +38 -0
  37. data/lib/pagy/classes/request.rb +36 -0
  38. data/lib/pagy/modules/abilities/configurable.rb +36 -0
  39. data/lib/pagy/modules/abilities/linkable.rb +59 -0
  40. data/lib/pagy/modules/abilities/rangeable.rb +15 -0
  41. data/lib/pagy/modules/abilities/shiftable.rb +12 -0
  42. data/lib/pagy/{b64.rb → modules/b64.rb} +3 -7
  43. data/lib/pagy/modules/console.rb +38 -0
  44. data/lib/pagy/modules/i18n/i18n.rb +48 -0
  45. data/lib/pagy/modules/i18n/p11n/arabic.rb +29 -0
  46. data/lib/pagy/modules/i18n/p11n/east_slavic.rb +26 -0
  47. data/lib/pagy/modules/i18n/p11n/one_other.rb +15 -0
  48. data/lib/pagy/modules/i18n/p11n/one_upto_two_other.rb +15 -0
  49. data/lib/pagy/modules/i18n/p11n/other.rb +13 -0
  50. data/lib/pagy/modules/i18n/p11n/polish.rb +26 -0
  51. data/lib/pagy/modules/i18n/p11n/west_slavic.rb +22 -0
  52. data/lib/pagy/modules/i18n/p11n.rb +16 -0
  53. data/lib/pagy/modules/searcher.rb +20 -0
  54. data/lib/pagy/toolbox/helpers/anchor_tags.rb +25 -0
  55. data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +24 -0
  56. data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +18 -0
  57. data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +29 -0
  58. data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +21 -0
  59. data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +21 -0
  60. data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +19 -0
  61. data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +28 -0
  62. data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +20 -0
  63. data/lib/pagy/toolbox/helpers/data_hash.rb +26 -0
  64. data/lib/pagy/toolbox/helpers/headers_hash.rb +20 -0
  65. data/lib/pagy/toolbox/helpers/info_tag.rb +26 -0
  66. data/lib/pagy/toolbox/helpers/input_nav_js.rb +19 -0
  67. data/lib/pagy/toolbox/helpers/limit_tag_js.rb +23 -0
  68. data/lib/pagy/toolbox/helpers/loader.rb +33 -0
  69. data/lib/pagy/toolbox/helpers/page_url.rb +23 -0
  70. data/lib/pagy/toolbox/helpers/series_nav.rb +29 -0
  71. data/lib/pagy/toolbox/helpers/series_nav_js.rb +19 -0
  72. data/lib/pagy/toolbox/helpers/support/a_lambda.rb +34 -0
  73. data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +15 -0
  74. data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +12 -0
  75. data/lib/pagy/toolbox/helpers/support/series.rb +38 -0
  76. data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +20 -0
  77. data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +17 -0
  78. data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +36 -0
  79. data/lib/pagy/toolbox/helpers/urls_hash.rb +13 -0
  80. data/lib/pagy/toolbox/paginators/calendar.rb +30 -0
  81. data/lib/pagy/toolbox/paginators/countless.rb +25 -0
  82. data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +32 -0
  83. data/lib/pagy/toolbox/paginators/keynav_js.rb +29 -0
  84. data/lib/pagy/toolbox/paginators/keyset.rb +18 -0
  85. data/lib/pagy/toolbox/paginators/meilisearch.rb +32 -0
  86. data/lib/pagy/toolbox/paginators/method.rb +26 -0
  87. data/lib/pagy/toolbox/paginators/offset.rb +33 -0
  88. data/lib/pagy/toolbox/paginators/searchkick.rb +32 -0
  89. data/lib/pagy.rb +59 -97
  90. data/locales/ar.yml +9 -6
  91. data/locales/be.yml +9 -6
  92. data/locales/bg.yml +9 -6
  93. data/locales/bs.yml +9 -6
  94. data/locales/ca.yml +9 -6
  95. data/locales/ckb.yml +8 -6
  96. data/locales/cs.yml +9 -6
  97. data/locales/da.yml +9 -6
  98. data/locales/de.yml +9 -6
  99. data/locales/dz.yml +9 -6
  100. data/locales/en.yml +9 -6
  101. data/locales/es.yml +9 -6
  102. data/locales/fr.yml +9 -6
  103. data/locales/hr.yml +9 -6
  104. data/locales/id.yml +9 -6
  105. data/locales/it.yml +9 -6
  106. data/locales/ja.yml +9 -6
  107. data/locales/km.yml +9 -6
  108. data/locales/ko.yml +9 -6
  109. data/locales/nb.yml +9 -6
  110. data/locales/nl.yml +9 -6
  111. data/locales/nn.yml +9 -6
  112. data/locales/pl.yml +9 -6
  113. data/locales/pt-BR.yml +10 -7
  114. data/locales/pt.yml +10 -7
  115. data/locales/ru.yml +9 -6
  116. data/locales/sk.yml +26 -0
  117. data/locales/sr.yml +9 -6
  118. data/locales/sv-SE.yml +9 -6
  119. data/locales/sv.yml +9 -6
  120. data/locales/sw.yml +12 -9
  121. data/locales/ta.yml +12 -13
  122. data/locales/tr.yml +9 -6
  123. data/locales/uk.yml +9 -6
  124. data/locales/vi.yml +9 -6
  125. data/locales/zh-CN.yml +9 -6
  126. data/locales/zh-HK.yml +9 -6
  127. data/locales/zh-TW.yml +9 -6
  128. data/stylesheets/pagy-tailwind.css +64 -0
  129. data/stylesheets/pagy.css +63 -27
  130. metadata +113 -51
  131. data/javascripts/pagy.min.js.map +0 -10
  132. data/lib/pagy/backend.rb +0 -44
  133. data/lib/pagy/calendar/unit.rb +0 -103
  134. data/lib/pagy/calendar.rb +0 -84
  135. data/lib/pagy/console.rb +0 -23
  136. data/lib/pagy/countless.rb +0 -38
  137. data/lib/pagy/exceptions.rb +0 -25
  138. data/lib/pagy/extras/arel.rb +0 -28
  139. data/lib/pagy/extras/array.rb +0 -19
  140. data/lib/pagy/extras/bootstrap.rb +0 -97
  141. data/lib/pagy/extras/bulma.rb +0 -93
  142. data/lib/pagy/extras/calendar.rb +0 -79
  143. data/lib/pagy/extras/countless.rb +0 -32
  144. data/lib/pagy/extras/elasticsearch_rails.rb +0 -71
  145. data/lib/pagy/extras/gearbox.rb +0 -55
  146. data/lib/pagy/extras/headers.rb +0 -54
  147. data/lib/pagy/extras/i18n.rb +0 -26
  148. data/lib/pagy/extras/js_tools.rb +0 -70
  149. data/lib/pagy/extras/jsonapi.rb +0 -88
  150. data/lib/pagy/extras/keyset.rb +0 -30
  151. data/lib/pagy/extras/limit.rb +0 -63
  152. data/lib/pagy/extras/meilisearch.rb +0 -57
  153. data/lib/pagy/extras/metadata.rb +0 -42
  154. data/lib/pagy/extras/overflow.rb +0 -81
  155. data/lib/pagy/extras/pagy.rb +0 -82
  156. data/lib/pagy/extras/searchkick.rb +0 -59
  157. data/lib/pagy/extras/size.rb +0 -40
  158. data/lib/pagy/extras/standalone.rb +0 -60
  159. data/lib/pagy/extras/trim.rb +0 -29
  160. data/lib/pagy/frontend.rb +0 -99
  161. data/lib/pagy/i18n.rb +0 -166
  162. data/lib/pagy/keyset/active_record.rb +0 -44
  163. data/lib/pagy/keyset/sequel.rb +0 -57
  164. data/lib/pagy/keyset.rb +0 -118
  165. data/lib/pagy/shared_methods.rb +0 -26
  166. data/lib/pagy/url_helpers.rb +0 -26
  167. data/stylesheets/pagy.scss +0 -48
  168. data/stylesheets/pagy.tailwind.css +0 -21
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.3.5
4
+ version: 43.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
12
- description: Agnostic pagination in plain ruby. It does it all. Better.
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: yaml
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: Agnostic pagination in plain ruby.
13
41
  email:
14
42
  - dd.nexus@gmail.com
15
43
  executables:
@@ -21,59 +49,93 @@ files:
21
49
  - apps/calendar.ru
22
50
  - apps/demo.ru
23
51
  - apps/index.rb
24
- - apps/keyset_ar.ru
25
- - apps/keyset_s.ru
52
+ - apps/keynav.ru
53
+ - apps/keyset.ru
54
+ - apps/keyset_sequel.ru
26
55
  - apps/rails.ru
27
56
  - apps/repro.ru
28
57
  - bin/pagy
29
58
  - config/pagy.rb
59
+ - javascripts/ai_widget.js
30
60
  - javascripts/pagy.d.ts
61
+ - javascripts/pagy.js
62
+ - javascripts/pagy.js.map
31
63
  - javascripts/pagy.min.js
32
- - javascripts/pagy.min.js.map
33
64
  - javascripts/pagy.mjs
65
+ - javascripts/wand.js
34
66
  - lib/optimist.rb
35
67
  - lib/pagy.rb
36
- - lib/pagy/b64.rb
37
- - lib/pagy/backend.rb
38
- - lib/pagy/calendar.rb
39
- - lib/pagy/calendar/day.rb
40
- - lib/pagy/calendar/month.rb
41
- - lib/pagy/calendar/quarter.rb
42
- - lib/pagy/calendar/unit.rb
43
- - lib/pagy/calendar/week.rb
44
- - lib/pagy/calendar/year.rb
45
- - lib/pagy/console.rb
46
- - lib/pagy/countless.rb
47
- - lib/pagy/exceptions.rb
48
- - lib/pagy/extras/arel.rb
49
- - lib/pagy/extras/array.rb
50
- - lib/pagy/extras/bootstrap.rb
51
- - lib/pagy/extras/bulma.rb
52
- - lib/pagy/extras/calendar.rb
53
- - lib/pagy/extras/countless.rb
54
- - lib/pagy/extras/elasticsearch_rails.rb
55
- - lib/pagy/extras/gearbox.rb
56
- - lib/pagy/extras/headers.rb
57
- - lib/pagy/extras/i18n.rb
58
- - lib/pagy/extras/js_tools.rb
59
- - lib/pagy/extras/jsonapi.rb
60
- - lib/pagy/extras/keyset.rb
61
- - lib/pagy/extras/limit.rb
62
- - lib/pagy/extras/meilisearch.rb
63
- - lib/pagy/extras/metadata.rb
64
- - lib/pagy/extras/overflow.rb
65
- - lib/pagy/extras/pagy.rb
66
- - lib/pagy/extras/searchkick.rb
67
- - lib/pagy/extras/size.rb
68
- - lib/pagy/extras/standalone.rb
69
- - lib/pagy/extras/trim.rb
70
- - lib/pagy/frontend.rb
71
- - lib/pagy/i18n.rb
72
- - lib/pagy/keyset.rb
73
- - lib/pagy/keyset/active_record.rb
74
- - lib/pagy/keyset/sequel.rb
75
- - lib/pagy/shared_methods.rb
76
- - lib/pagy/url_helpers.rb
68
+ - lib/pagy/classes/calendar/calendar.rb
69
+ - lib/pagy/classes/calendar/day.rb
70
+ - lib/pagy/classes/calendar/month.rb
71
+ - lib/pagy/classes/calendar/quarter.rb
72
+ - lib/pagy/classes/calendar/unit.rb
73
+ - lib/pagy/classes/calendar/week.rb
74
+ - lib/pagy/classes/calendar/year.rb
75
+ - lib/pagy/classes/exceptions.rb
76
+ - lib/pagy/classes/keyset/active_record.rb
77
+ - lib/pagy/classes/keyset/adapters/active_record.rb
78
+ - lib/pagy/classes/keyset/adapters/sequel.rb
79
+ - lib/pagy/classes/keyset/keynav.rb
80
+ - lib/pagy/classes/keyset/keynav/active_record.rb
81
+ - lib/pagy/classes/keyset/keynav/sequel.rb
82
+ - lib/pagy/classes/keyset/keyset.rb
83
+ - lib/pagy/classes/keyset/sequel.rb
84
+ - lib/pagy/classes/offset/countless.rb
85
+ - lib/pagy/classes/offset/offset.rb
86
+ - lib/pagy/classes/offset/search.rb
87
+ - lib/pagy/classes/request.rb
88
+ - lib/pagy/modules/abilities/configurable.rb
89
+ - lib/pagy/modules/abilities/linkable.rb
90
+ - lib/pagy/modules/abilities/rangeable.rb
91
+ - lib/pagy/modules/abilities/shiftable.rb
92
+ - lib/pagy/modules/b64.rb
93
+ - lib/pagy/modules/console.rb
94
+ - lib/pagy/modules/i18n/i18n.rb
95
+ - lib/pagy/modules/i18n/p11n.rb
96
+ - lib/pagy/modules/i18n/p11n/arabic.rb
97
+ - lib/pagy/modules/i18n/p11n/east_slavic.rb
98
+ - lib/pagy/modules/i18n/p11n/one_other.rb
99
+ - lib/pagy/modules/i18n/p11n/one_upto_two_other.rb
100
+ - lib/pagy/modules/i18n/p11n/other.rb
101
+ - lib/pagy/modules/i18n/p11n/polish.rb
102
+ - lib/pagy/modules/i18n/p11n/west_slavic.rb
103
+ - lib/pagy/modules/searcher.rb
104
+ - lib/pagy/toolbox/helpers/anchor_tags.rb
105
+ - lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb
106
+ - lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb
107
+ - lib/pagy/toolbox/helpers/bootstrap/series_nav.rb
108
+ - lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb
109
+ - lib/pagy/toolbox/helpers/bulma/input_nav_js.rb
110
+ - lib/pagy/toolbox/helpers/bulma/previous_next_html.rb
111
+ - lib/pagy/toolbox/helpers/bulma/series_nav.rb
112
+ - lib/pagy/toolbox/helpers/bulma/series_nav_js.rb
113
+ - lib/pagy/toolbox/helpers/data_hash.rb
114
+ - lib/pagy/toolbox/helpers/headers_hash.rb
115
+ - lib/pagy/toolbox/helpers/info_tag.rb
116
+ - lib/pagy/toolbox/helpers/input_nav_js.rb
117
+ - lib/pagy/toolbox/helpers/limit_tag_js.rb
118
+ - lib/pagy/toolbox/helpers/loader.rb
119
+ - lib/pagy/toolbox/helpers/page_url.rb
120
+ - lib/pagy/toolbox/helpers/series_nav.rb
121
+ - lib/pagy/toolbox/helpers/series_nav_js.rb
122
+ - lib/pagy/toolbox/helpers/support/a_lambda.rb
123
+ - lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb
124
+ - lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb
125
+ - lib/pagy/toolbox/helpers/support/series.rb
126
+ - lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb
127
+ - lib/pagy/toolbox/helpers/support/wrap_series_nav.rb
128
+ - lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb
129
+ - lib/pagy/toolbox/helpers/urls_hash.rb
130
+ - lib/pagy/toolbox/paginators/calendar.rb
131
+ - lib/pagy/toolbox/paginators/countless.rb
132
+ - lib/pagy/toolbox/paginators/elasticsearch_rails.rb
133
+ - lib/pagy/toolbox/paginators/keynav_js.rb
134
+ - lib/pagy/toolbox/paginators/keyset.rb
135
+ - lib/pagy/toolbox/paginators/meilisearch.rb
136
+ - lib/pagy/toolbox/paginators/method.rb
137
+ - lib/pagy/toolbox/paginators/offset.rb
138
+ - lib/pagy/toolbox/paginators/searchkick.rb
77
139
  - locales/ar.yml
78
140
  - locales/be.yml
79
141
  - locales/bg.yml
@@ -100,6 +162,7 @@ files:
100
162
  - locales/pt-BR.yml
101
163
  - locales/pt.yml
102
164
  - locales/ru.yml
165
+ - locales/sk.yml
103
166
  - locales/sr.yml
104
167
  - locales/sv-SE.yml
105
168
  - locales/sv.yml
@@ -111,9 +174,8 @@ files:
111
174
  - locales/zh-CN.yml
112
175
  - locales/zh-HK.yml
113
176
  - locales/zh-TW.yml
177
+ - stylesheets/pagy-tailwind.css
114
178
  - stylesheets/pagy.css
115
- - stylesheets/pagy.scss
116
- - stylesheets/pagy.tailwind.css
117
179
  homepage: https://github.com/ddnexus/pagy
118
180
  licenses:
119
181
  - MIT
@@ -131,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
193
  requirements:
132
194
  - - ">="
133
195
  - !ruby/object:Gem::Version
134
- version: '3.1'
196
+ version: '3.2'
135
197
  required_rubygems_version: !ruby/object:Gem::Requirement
136
198
  requirements:
137
199
  - - ">="
@@ -140,5 +202,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
202
  requirements: []
141
203
  rubygems_version: 3.6.7
142
204
  specification_version: 4
143
- summary: The best pagination ruby gem
205
+ summary: "Pagy \U0001F438 The Leaping Gem!"
144
206
  test_files: []
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/pagy.ts"],
4
- "sourcesContent": [
5
- "type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll<NavElement>(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the limit_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"9.3.5\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n"
6
- ],
7
- "mappings": "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",
8
- "debugId": "6BE129FEF0BA264664756E2164756E21",
9
- "names": []
10
- }
data/lib/pagy/backend.rb DELETED
@@ -1,44 +0,0 @@
1
- # See Pagy::Backend API documentation: https://ddnexus.github.io/pagy/docs/api/backend
2
- # frozen_string_literal: true
3
-
4
- class Pagy
5
- # Define a few generic methods to paginate a collection out of the box,
6
- # or any collection by overriding any of the `pagy_*` methods in your controller.
7
- # See also the extras if you need specialized methods to paginate Arrays or other collections
8
- module Backend
9
- private
10
-
11
- # Return Pagy object and paginated results
12
- def pagy(collection, **vars)
13
- vars[:count] ||= pagy_get_count(collection, vars)
14
- vars[:limit] ||= pagy_get_limit(vars)
15
- vars[:page] ||= pagy_get_page(vars)
16
- pagy = Pagy.new(**vars)
17
- [pagy, pagy_get_items(collection, pagy)]
18
- end
19
-
20
- # Get the count from the collection
21
- def pagy_get_count(collection, vars)
22
- count_args = vars[:count_args] || DEFAULT[:count_args]
23
- (count = collection.count(*count_args)).is_a?(Hash) ? count.size : count
24
- end
25
-
26
- # Sub-method called only by #pagy: here for easy customization of fetching by overriding
27
- # You may need to override this method for collections without offset|limit
28
- def pagy_get_items(collection, pagy)
29
- collection.offset(pagy.offset).limit(pagy.limit)
30
- end
31
-
32
- # Override for limit extra
33
- def pagy_get_limit(_vars)
34
- DEFAULT[:limit]
35
- end
36
-
37
- # Get the page integer from the params
38
- # Overridable by the jsonapi extra
39
- def pagy_get_page(vars, force_integer: true)
40
- page = params[vars[:page_param] || DEFAULT[:page_param]]
41
- force_integer ? (page || 1).to_i : page
42
- end
43
- end
44
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support'
4
- require 'active_support/core_ext/time'
5
- require 'active_support/core_ext/date_and_time/calculations'
6
- require 'active_support/core_ext/numeric/time'
7
- require 'active_support/core_ext/integer/time'
8
-
9
- class Pagy # :nodoc:
10
- class Calendar < Hash # :nodoc:
11
- # Base class for time units subclasses (Year, Quarter, Month, Week, Day)
12
- class Unit < Pagy
13
- attr_reader :order, :from, :to
14
-
15
- # Merge and validate the options, do some simple arithmetic and set a few instance variables
16
- def initialize(**vars) # rubocop:disable Lint/MissingSuper
17
- raise InternalError, 'Pagy::Calendar::Unit is a base class; use one of its subclasses' \
18
- if instance_of?(Pagy::Calendar::Unit)
19
-
20
- assign_vars({ **Pagy::DEFAULT, **self.class::DEFAULT }, vars)
21
- assign_and_check(page: 1)
22
- assign_unit_vars
23
- check_overflow
24
- assign_prev_and_next
25
- end
26
-
27
- # The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
28
- def label(opts = {})
29
- label_for(@page, opts)
30
- end
31
-
32
- # The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
33
- def label_for(page, opts = {})
34
- opts[:format] ||= @vars[:format]
35
- localize(starting_time_for(page.to_i), opts) # page could be a string
36
- end
37
-
38
- protected
39
-
40
- # The page that includes time
41
- # In case of out of range time, the :fit_time option avoids the outOfRangeError
42
- # and returns the closest page to the passed time argument (first or last page)
43
- def page_at(time, **opts)
44
- fit_time = time
45
- fit_final = @final - 1
46
- unless time.between?(@initial, fit_final)
47
- raise OutOfRangeError.new(self, :time, "between #{@initial} and #{fit_final}", time) unless opts[:fit_time]
48
-
49
- if time < @final
50
- fit_time = @initial
51
- ordinal = 'first'
52
- else
53
- fit_time = fit_final
54
- ordinal = 'last'
55
- end
56
- warn "Pagy::Calendar#page_at: Rescued #{time} out of range by returning the #{ordinal} page."
57
- end
58
- offset = page_offset_at(fit_time) # offset starts from 0
59
- @order == :asc ? offset + 1 : @last - offset
60
- end
61
-
62
- # Base class method for the setup of the unit variables (subclasses must implement it and call super)
63
- def assign_unit_vars
64
- raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
65
- raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
66
- unless %i[asc desc].include?(@order = @vars[:order])
67
-
68
- @starting, @ending = @vars[:period]
69
- raise VariableError.new(self, :period, 'to be a an Array of min and max TimeWithZone instances', @vars[:period]) \
70
- unless @starting.is_a?(ActiveSupport::TimeWithZone) \
71
- && @ending.is_a?(ActiveSupport::TimeWithZone) && @starting <= @ending
72
- end
73
-
74
- # Apply the strftime format to the time (overridden by the i18n extra when localization is required)
75
- def localize(time, opts)
76
- time.strftime(opts[:format])
77
- end
78
-
79
- # Number of time units to offset from the @initial time, in order to get the ordered starting time for the page.
80
- # Used in starting_time_for(page) where page starts from 1 (e.g. page to starting_time means subtracting 1)
81
- def time_offset_for(page)
82
- @order == :asc ? page - 1 : @last - page
83
- end
84
-
85
- # Period of the active page (used internally for nested units)
86
- def active_period
87
- [[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
88
- end
89
-
90
- # :nocov:
91
- # This method must be implemented by the unit subclass
92
- def starting_time_for(*)
93
- raise NoMethodError, 'the starting_time_for method must be implemented by the unit subclass'
94
- end
95
-
96
- # This method must be implemented by the unit subclass
97
- def page_offset_at(*)
98
- raise NoMethodError, 'the page_offset_at method must be implemented by the unit subclass'
99
- end
100
- # :nocov:
101
- end
102
- end
103
- end
data/lib/pagy/calendar.rb DELETED
@@ -1,84 +0,0 @@
1
- # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/calendar
2
- # frozen_string_literal: true
3
-
4
- require_relative '../pagy'
5
- require_relative 'calendar/unit'
6
-
7
- class Pagy # :nodoc:
8
- # Calendar class
9
- class Calendar < Hash
10
- # Specific out of range error
11
- class OutOfRangeError < VariableError; end
12
-
13
- # List of units in desc order of duration. It can be used for custom units.
14
- UNITS = %i[year quarter month week day] # rubocop:disable Style/MutableConstant
15
-
16
- class << self
17
- private
18
-
19
- # Create a unit subclass instance by using the unit name (internal use)
20
- def create(unit, **vars)
21
- raise InternalError, "unit must be in #{UNITS.inspect}; got #{unit}" unless UNITS.include?(unit)
22
-
23
- name = unit.to_s
24
- name[0] = name[0].capitalize
25
- Object.const_get("Pagy::Calendar::#{name}").new(**vars)
26
- end
27
-
28
- # Return calendar, from, to
29
- def init(...)
30
- new.send(:init, ...)
31
- end
32
- end
33
-
34
- # Return the current time of the smallest time unit shown
35
- def showtime
36
- self[@units.last].from
37
- end
38
-
39
- private
40
-
41
- # Create the calendar
42
- def init(conf, period, params)
43
- @conf = Marshal.load(Marshal.dump(conf)) # store a copy
44
- @units = Calendar::UNITS & @conf.keys # get the units in time length desc order
45
- raise ArgumentError, 'no calendar unit found in pagy_calendar @configuration' if @units.empty?
46
-
47
- @period = period
48
- @params = params
49
- @page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
50
- # set all the :page_param vars for later deletion
51
- @units.each { |unit| conf[unit][:page_param] = :"#{unit}_#{@page_param}" }
52
- calendar = {}
53
- object = nil
54
- @units.each_with_index do |unit, index|
55
- params_to_delete = @units[(index + 1), @units.size].map { |sub| conf[sub][:page_param] } + [@page_param]
56
- conf[unit][:params] = ->(up) { up.except(*params_to_delete.map(&:to_s)) }
57
- conf[unit][:period] = object&.send(:active_period) || @period
58
- conf[unit][:page] = @params[:"#{unit}_#{@page_param}"] # requested page
59
- # :nocov:
60
- conf[unit][:counts] = yield(unit, conf[unit][:period]) if block_given? # nocov doesn't need to fail block_given?
61
- # :nocov:
62
- calendar[unit] = object \
63
- = Calendar.send(:create, unit, **conf[unit])
64
- end
65
- [replace(calendar), object.from, object.to]
66
- end
67
-
68
- # Return the calendar object at time
69
- def calendar_at(time, **opts)
70
- conf = Marshal.load(Marshal.dump(@conf))
71
- page_params = {}
72
- @units.inject(nil) do |object, unit|
73
- conf[unit][:period] = object&.send(:active_period) || @period
74
- conf[unit][:page] = page_params[:"#{unit}_#{@page_param}"] \
75
- = Calendar.send(:create, unit, **conf[unit]).send(:page_at, time, **opts)
76
- conf[unit][:params] ||= {}
77
- conf[unit][:params].merge!(page_params)
78
- Calendar.send(:create, unit, **conf[unit])
79
- end
80
- end
81
- end
82
- # Require the subclass files in UNITS (no custom unit at this point yet)
83
- Calendar::UNITS.each { |unit| require "pagy/calendar/#{unit}" }
84
- end
data/lib/pagy/console.rb DELETED
@@ -1,23 +0,0 @@
1
- # See Pagy::Console API documentation: https://ddnexus.github.io/pagy/docs/api/console
2
- # frozen_string_literal: true
3
-
4
- require_relative '../pagy' # so you can require just the extra in the console
5
- require_relative 'extras/standalone'
6
-
7
- class Pagy
8
- # Provide a ready to use pagy environment when included in irb/rails console
9
- module Console
10
- # Include Backend, Frontend and set the default URL
11
- def self.included(main)
12
- main.include(Backend)
13
- main.include(Frontend)
14
- DEFAULT[:url] = 'http://www.example.com/subdir'
15
- end
16
-
17
- # Require the extras passed as arguments
18
- def pagy_extras(*extras)
19
- extras.each { |extra| require "pagy/extras/#{extra}" }
20
- puts "Required extras: #{extras.map(&:inspect).join(', ')}"
21
- end
22
- end
23
- end
@@ -1,38 +0,0 @@
1
- # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/countless
2
- # frozen_string_literal: true
3
-
4
- class Pagy # :nodoc:
5
- # No need to know the count to paginate
6
- class Countless < Pagy
7
- # Merge and validate the options, do some simple arithmetic and set a few instance variables
8
- def initialize(**vars) # rubocop:disable Lint/MissingSuper
9
- assign_vars(DEFAULT, vars)
10
- assign_and_check(page: 1, outset: 0)
11
- assign_limit
12
- assign_offset
13
- end
14
-
15
- # Finalize the instance variables based on the fetched size
16
- def finalize(fetched_size)
17
- raise OverflowError.new(self, :page, "to be < #{@page}", @page) if fetched_size.zero? && @page > 1
18
-
19
- @last = fetched_size > @limit ? @page + 1 : @page
20
- @last = @vars[:max_pages] if @vars[:max_pages] && @last > @vars[:max_pages]
21
- check_overflow
22
- @in = [fetched_size, @limit].min
23
- @from = @in.zero? ? 0 : @offset - @outset + 1
24
- @to = @offset - @outset + @in
25
- assign_prev_and_next
26
- self
27
- end
28
- end
29
-
30
- module SeriesOverride # :nodoc:
31
- # Override the original series.
32
- # Return nil if :countless_minimal is enabled
33
- def series(**)
34
- super unless @vars[:countless_minimal]
35
- end
36
- end
37
- prepend SeriesOverride
38
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Pagy
4
- # Generic variable error
5
- class VariableError < ArgumentError
6
- attr_reader :pagy, :variable, :value
7
-
8
- # Set the variables and prepare the message
9
- def initialize(pagy, variable, description, value)
10
- @pagy = pagy
11
- @variable = variable
12
- @value = value
13
- super("expected :#{@variable} #{description}; got #{@value.inspect}")
14
- end
15
- end
16
-
17
- # Specific overflow error
18
- class OverflowError < VariableError; end
19
-
20
- # I18n configuration error
21
- class I18nError < StandardError; end
22
-
23
- # Generic internal error
24
- class InternalError < StandardError; end
25
- end
@@ -1,28 +0,0 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/arel
2
- # frozen_string_literal: true
3
-
4
- class Pagy # :nodoc:
5
- # Better performance of grouped ActiveRecord collections
6
- module ArelExtra
7
- private
8
-
9
- # Return Pagy object and paginated collection/results
10
- def pagy_arel(collection, **vars)
11
- vars[:count] ||= pagy_arel_count(collection)
12
- pagy(collection, **vars)
13
- end
14
-
15
- # Count using Arel when grouping
16
- def pagy_arel_count(collection)
17
- if collection.group_values.empty?
18
- # COUNT(*)
19
- collection.count(:all)
20
- else
21
- # COUNT(*) OVER ()
22
- sql = Arel.star.count.over(Arel::Nodes::Grouping.new([]))
23
- collection.unscope(:order).pick(sql).to_i
24
- end
25
- end
26
- end
27
- Backend.prepend ArelExtra
28
- end
@@ -1,19 +0,0 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/array
2
- # frozen_string_literal: true
3
-
4
- class Pagy # :nodoc:
5
- # Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
6
- module ArrayExtra
7
- private
8
-
9
- # Return Pagy object and paginated items
10
- def pagy_array(array, **vars)
11
- vars[:limit] ||= pagy_get_limit(vars)
12
- vars[:page] ||= pagy_get_page(vars)
13
- vars[:count] ||= array.size
14
- pagy = Pagy.new(**vars)
15
- [pagy, array[pagy.offset, pagy.limit]]
16
- end
17
- end
18
- Backend.prepend ArrayExtra
19
- end