pagy 8.6.3 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +1 -1
  3. data/apps/demo.ru +4 -4
  4. data/apps/keyset_ar.ru +236 -0
  5. data/apps/keyset_s.ru +238 -0
  6. data/apps/rails.ru +5 -5
  7. data/apps/repro.ru +4 -4
  8. data/apps/tmp/calendar.sqlite3 +0 -0
  9. data/apps/tmp/calendar.sqlite3-shm +0 -0
  10. data/apps/tmp/calendar.sqlite3-wal +0 -0
  11. data/apps/tmp/local_secret.txt +1 -1
  12. data/apps/tmp/{pagy-keyset.sqlite3 → pagy-keyset-ar.sqlite3} +0 -0
  13. data/apps/tmp/{pagy-keyset.sqlite3-shm → pagy-keyset-ar.sqlite3-shm} +0 -0
  14. data/apps/tmp/{pagy-keyset.sqlite3-wal → pagy-keyset-ar.sqlite3-wal} +0 -0
  15. data/apps/tmp/pagy-keyset-s.sqlite3 +0 -0
  16. data/bin/pagy +4 -2
  17. data/config/pagy.rb +13 -13
  18. data/javascripts/pagy.min.js +2 -2
  19. data/javascripts/pagy.min.js.map +2 -2
  20. data/javascripts/pagy.mjs +2 -2
  21. data/lib/pagy/b64.rb +33 -0
  22. data/lib/pagy/backend.rb +21 -17
  23. data/lib/pagy/calendar/day.rb +1 -1
  24. data/lib/pagy/calendar/month.rb +1 -1
  25. data/lib/pagy/calendar/quarter.rb +1 -1
  26. data/lib/pagy/calendar/unit.rb +7 -10
  27. data/lib/pagy/calendar/week.rb +1 -1
  28. data/lib/pagy/calendar/year.rb +1 -1
  29. data/lib/pagy/calendar.rb +5 -5
  30. data/lib/pagy/countless.rb +10 -14
  31. data/lib/pagy/extras/arel.rb +8 -10
  32. data/lib/pagy/extras/array.rb +4 -6
  33. data/lib/pagy/extras/bootstrap.rb +5 -5
  34. data/lib/pagy/extras/bulma.rb +10 -7
  35. data/lib/pagy/extras/calendar.rb +4 -5
  36. data/lib/pagy/extras/countless.rb +6 -13
  37. data/lib/pagy/extras/elasticsearch_rails.rb +15 -15
  38. data/lib/pagy/extras/gearbox.rb +18 -18
  39. data/lib/pagy/extras/headers.rb +25 -24
  40. data/lib/pagy/extras/js_tools.rb +4 -4
  41. data/lib/pagy/extras/jsonapi.rb +26 -16
  42. data/lib/pagy/extras/keyset.rb +26 -0
  43. data/lib/pagy/extras/limit.rb +63 -0
  44. data/lib/pagy/extras/meilisearch.rb +11 -11
  45. data/lib/pagy/extras/metadata.rb +2 -2
  46. data/lib/pagy/extras/overflow.rb +5 -5
  47. data/lib/pagy/extras/pagy.rb +16 -16
  48. data/lib/pagy/extras/searchkick.rb +11 -11
  49. data/lib/pagy/extras/size.rb +1 -1
  50. data/lib/pagy/extras/standalone.rb +6 -6
  51. data/lib/pagy/extras/trim.rb +2 -2
  52. data/lib/pagy/frontend.rb +32 -33
  53. data/lib/pagy/i18n.rb +1 -1
  54. data/lib/pagy/keyset/active_record.rb +38 -0
  55. data/lib/pagy/keyset/sequel.rb +51 -0
  56. data/lib/pagy/keyset.rb +99 -0
  57. data/lib/pagy/url_helpers.rb +5 -5
  58. data/lib/pagy.rb +73 -65
  59. data/locales/ar.yml +1 -1
  60. data/locales/be.yml +1 -1
  61. data/locales/bg.yml +1 -1
  62. data/locales/bs.yml +1 -1
  63. data/locales/ca.yml +1 -1
  64. data/locales/ckb.yml +1 -1
  65. data/locales/cs.yml +1 -1
  66. data/locales/da.yml +1 -1
  67. data/locales/de.yml +1 -1
  68. data/locales/en.yml +1 -1
  69. data/locales/es.yml +1 -1
  70. data/locales/fr.yml +1 -1
  71. data/locales/hr.yml +1 -1
  72. data/locales/id.yml +1 -1
  73. data/locales/it.yml +1 -1
  74. data/locales/ja.yml +1 -1
  75. data/locales/km.yml +1 -1
  76. data/locales/ko.yml +1 -1
  77. data/locales/nb.yml +1 -1
  78. data/locales/nl.yml +1 -1
  79. data/locales/nn.yml +1 -1
  80. data/locales/pl.yml +1 -1
  81. data/locales/pt-BR.yml +1 -1
  82. data/locales/pt.yml +1 -1
  83. data/locales/ru.yml +1 -1
  84. data/locales/sr.yml +1 -1
  85. data/locales/sv-SE.yml +1 -1
  86. data/locales/sv.yml +1 -1
  87. data/locales/sw.yml +1 -1
  88. data/locales/ta.yml +1 -1
  89. data/locales/tr.yml +1 -1
  90. data/locales/uk.yml +1 -1
  91. data/locales/vi.yml +1 -1
  92. data/locales/zh-CN.yml +1 -1
  93. data/locales/zh-HK.yml +1 -1
  94. data/locales/zh-TW.yml +1 -1
  95. data/pkg/pagy-9.0.0.gem +0 -0
  96. metadata +16 -18
  97. data/lib/pagy/extras/foundation.rb +0 -95
  98. data/lib/pagy/extras/items.rb +0 -64
  99. data/lib/pagy/extras/materialize.rb +0 -100
  100. data/lib/pagy/extras/semantic.rb +0 -94
  101. data/lib/pagy/extras/uikit.rb +0 -98
data/locales/ja.yml CHANGED
@@ -16,4 +16,4 @@ ja:
16
16
  single_page: "%{count} 件の%{item_name}"
17
17
  multiple_pages: "%{count} 件中 %{from}-%{to} 件目の%{item_name}を表示中"
18
18
  combo_nav_js: "%{page_input} / %{pages} ページ"
19
- items_selector_js: "%{items_input} 件ずつ表示"
19
+ limit_selector_js: "%{limit_input} 件ずつ表示"
data/locales/km.yml CHANGED
@@ -16,4 +16,4 @@ km:
16
16
  single_page: "បង្ហាញ %{count} %{item_name}"
17
17
  multiple_pages: "បង្ហាញ %{item_name} %{from}-%{to} នៃ %{count} ជាចំនួនសរុប"
18
18
  combo_nav_js: "ទំព័រ %{page_input} នៃ %{pages}"
19
- items_selector_js: "បង្ហាញ %{items_input} %{item_name} ក្នុង ១ ទំព័រ"
19
+ limit_selector_js: "បង្ហាញ %{limit_input} %{item_name} ក្នុង ១ ទំព័រ"
data/locales/ko.yml CHANGED
@@ -14,4 +14,4 @@ ko:
14
14
  single_page: "%{count}개의 %{item_name} 표시됨"
15
15
  multiple_pages: "총 %{count}개의 %{item_name} 중 %{from}-%{to}"
16
16
  combo_nav_js: "총 %{pages} 중 %{page_input} 페이지"
17
- items_selector_js: "페이지 당 %{items_input}개 표시%"
17
+ limit_selector_js: "페이지 당 %{limit_input}개 표시%"
data/locales/nb.yml CHANGED
@@ -18,4 +18,4 @@ nb:
18
18
  single_page: "Viser %{count} %{item_name}"
19
19
  multiple_pages: "Viser %{item_name} %{from}-%{to} av totalt %{count}"
20
20
  combo_nav_js: "Side %{page_input} av %{pages}"
21
- items_selector_js: "Vis %{items_input} %{item_name} per side"
21
+ limit_selector_js: "Vis %{limit_input} %{item_name} per side"
data/locales/nl.yml CHANGED
@@ -18,4 +18,4 @@ nl:
18
18
  single_page: "Toont %{count} %{item_name}"
19
19
  multiple_pages: "Toont %{from}-%{to} %{item_name} van %{count} in totaal"
20
20
  combo_nav_js: "Pagina %{page_input} van %{pages}"
21
- items_selector_js: "Toont %{items_input} %{item_name} per pagina"
21
+ limit_selector_js: "Toont %{limit_input} %{item_name} per pagina"
data/locales/nn.yml CHANGED
@@ -18,4 +18,4 @@ nn:
18
18
  single_page: "Viser %{count} %{item_name}"
19
19
  multiple_pages: "Viser %{item_name} %{from}-%{to} av totalt %{count}"
20
20
  combo_nav_js: "Side %{page_input} av %{pages}"
21
- items_selector_js: "Vis %{items_input} %{item_name} per side"
21
+ limit_selector_js: "Vis %{limit_input} %{item_name} per side"
data/locales/pl.yml CHANGED
@@ -22,4 +22,4 @@ pl:
22
22
  single_page: "Wyświetlono %{count} %{item_name}"
23
23
  multiple_pages: "Wyświetlono %{item_name} %{from}-%{to} z wszystkich %{count}"
24
24
  combo_nav_js: "Strona %{page_input} z %{pages}"
25
- items_selector_js: "Pokaż %{items_input} %{item_name} na stronie"
25
+ limit_selector_js: "Pokaż %{limit_input} %{item_name} na stronie"
data/locales/pt-BR.yml CHANGED
@@ -18,4 +18,4 @@ pt-BR:
18
18
  single_page: "Mostrando %{count} %{item_name}"
19
19
  multiple_pages: "Mostrando %{item_name} %{from}-%{to} do total de %{count}"
20
20
  combo_nav_js: "Página %{page_input} de %{pages}"
21
- items_selector_js: "Mostrar %{items_input} %{item_name} por página"
21
+ limit_selector_js: "Mostrar %{limit_input} %{item_name} por página"
data/locales/pt.yml CHANGED
@@ -18,4 +18,4 @@ pt:
18
18
  single_page: "Mostrando %{count} %{item_name}"
19
19
  multiple_pages: "Mostrando %{item_name} %{from}-%{to} de um total de %{count}"
20
20
  combo_nav_js: "Página %{page_input} de %{pages}"
21
- items_selector_js: "Mostrar %{items_input} %{item_name} por página"
21
+ limit_selector_js: "Mostrar %{limit_input} %{item_name} por página"
data/locales/ru.yml CHANGED
@@ -22,4 +22,4 @@ ru:
22
22
  single_page: "%{count} %{item_name}"
23
23
  multiple_pages: "Всего %{count} %{item_name}, показаны с %{from} по %{to}"
24
24
  combo_nav_js: "Страница %{page_input} из %{pages}"
25
- items_selector_js: "Показать %{items_input} %{item_name} на странице"
25
+ limit_selector_js: "Показать %{limit_input} %{item_name} на странице"
data/locales/sr.yml CHANGED
@@ -22,4 +22,4 @@ sr:
22
22
  single_page: "Приказује се %{count} %{item_name}"
23
23
  multiple_pages: "Приказ %{item_name} %{from}-%{to} од %{count} укупно"
24
24
  combo_nav_js: "Страниca %{page_input} од %{pages}"
25
- items_selector_js: "Прикажи %{items_input} %{item_name} по страниcи"
25
+ limit_selector_js: "Прикажи %{limit_input} %{item_name} по страниcи"
data/locales/sv-SE.yml CHANGED
@@ -18,4 +18,4 @@ sv-SE:
18
18
  single_page: "Visar %{count} %{item_name}"
19
19
  multiple_pages: "Visar %{item_name} %{from}-%{to} av %{count} totalt"
20
20
  combo_nav_js: "Sida %{page_input} av %{pages}"
21
- items_selector_js: "Visa %{items_input} %{item_name} per sida"
21
+ limit_selector_js: "Visa %{limit_input} %{item_name} per sida"
data/locales/sv.yml CHANGED
@@ -18,4 +18,4 @@ sv:
18
18
  single_page: "Visar %{count} %{item_name}"
19
19
  multiple_pages: "Visar %{item_name} %{from}-%{to} av %{count} totalt"
20
20
  combo_nav_js: "Sida %{page_input} av %{pages}"
21
- items_selector_js: "Visa %{items_input} %{item_name} per sida"
21
+ limit_selector_js: "Visa %{limit_input} %{item_name} per sida"
data/locales/sw.yml CHANGED
@@ -20,4 +20,4 @@ sw:
20
20
  single_page: "Inaonyesha %{item_name} %{count}"
21
21
  multiple_pages: "Inaonyesha %{item_name} %{from}-%{to} ya %{count} kwa jumla"
22
22
  combo_nav_js: "Kurasa %{page_input} ya %{pages}"
23
- items_selector_js: "Onyesha %{items_input} %{item_name} kwa kila ukurasa"
23
+ limit_selector_js: "Onyesha %{limit_input} %{item_name} kwa kila ukurasa"
data/locales/ta.yml CHANGED
@@ -20,4 +20,4 @@ ta:
20
20
  single_page: "%{count} %{item_name} காட்டப்படுகின்றது"
21
21
  multiple_pages: "மொத்தம் %{count} %{item_name}, காட்டப்படுபவை %{from}-%{to}"
22
22
  combo_nav_js: "%{pages}-இல் %{page_input}-வது பக்கம்"
23
- items_selector_js: "ஒரு பக்கத்திற்கு %{items_input} %{item_name} காட்டு"
23
+ limit_selector_js: "ஒரு பக்கத்திற்கு %{limit_input} %{item_name} காட்டு"
data/locales/tr.yml CHANGED
@@ -16,4 +16,4 @@ tr:
16
16
  single_page: "Toplam %{count} %{item_name} gösteriliyor"
17
17
  multiple_pages: "%{count} %{item_name} içerisinden %{from}-%{to} kadarı gösteriliyor"
18
18
  combo_nav_js: "Sayfa %{page_input} / %{pages}"
19
- items_selector_js: "Sayfada %{items_input} %{item_name} göster"
19
+ limit_selector_js: "Sayfada %{limit_input} %{item_name} göster"
data/locales/uk.yml CHANGED
@@ -22,4 +22,4 @@ uk:
22
22
  single_page: "%{count} %{item_name}"
23
23
  multiple_pages: "Загалом %{count} %{item_name}, показані з %{from} по %{to}"
24
24
  combo_nav_js: "Сторінка %{page_input} з %{pages}"
25
- items_selector_js: "Показати %{items_input} %{item_name} на сторінці"
25
+ limit_selector_js: "Показати %{limit_input} %{item_name} на сторінці"
data/locales/vi.yml CHANGED
@@ -14,4 +14,4 @@ vi:
14
14
  single_page: "%{count} %{item_name}"
15
15
  multiple_pages: "Đang hiển thị %{from}-%{to} trong tổng số %{count} %{item_name}"
16
16
  combo_nav_js: "Trang %{page_input} trên %{pages}"
17
- items_selector_js: "Hiển thị %{items_input} %{item_name} mỗi trang"
17
+ limit_selector_js: "Hiển thị %{limit_input} %{item_name} mỗi trang"
data/locales/zh-CN.yml CHANGED
@@ -16,4 +16,4 @@ zh-CN:
16
16
  single_page: "显示%{count} 项%{item_name}"
17
17
  multiple_pages: "共 %{count} 项%{item_name},显示 %{from}-%{to}"
18
18
  combo_nav_js: "第 %{page_input} / %{pages} 页"
19
- items_selector_js: "每页显示 %{items_input} 条%"
19
+ limit_selector_js: "每页显示 %{limit_input} 条%"
data/locales/zh-HK.yml CHANGED
@@ -16,4 +16,4 @@ zh-HK:
16
16
  single_page: "顯示 %{count} %{item_name}"
17
17
  multiple_pages: "共 %{count} %{item_name},顯示 %{from}-%{to}"
18
18
  combo_nav_js: "第 %{page_input} / %{pages} 頁"
19
- items_selector_js: "每頁顯示 %{items_input} 記錄"
19
+ limit_selector_js: "每頁顯示 %{limit_input} 記錄"
data/locales/zh-TW.yml CHANGED
@@ -16,4 +16,4 @@ zh-TW:
16
16
  single_page: "顯示 %{count} 項%{item_name}"
17
17
  multiple_pages: "共 %{count} 項%{item_name},顯示 %{from}-%{to}"
18
18
  combo_nav_js: "第 %{page_input} / %{pages} 頁"
19
- items_selector_js: "每頁顯示 %{items_input} 項%{item_name}"
19
+ limit_selector_js: "每頁顯示 %{limit_input} 項%{item_name}"
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.3
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-03 00:00:00.000000000 Z
11
+ date: 2024-07-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Agnostic pagination in plain ruby. It does it all. Better.
14
14
  email:
@@ -21,15 +21,18 @@ files:
21
21
  - LICENSE.txt
22
22
  - apps/calendar.ru
23
23
  - apps/demo.ru
24
+ - apps/keyset_ar.ru
25
+ - apps/keyset_s.ru
24
26
  - apps/rails.ru
25
27
  - apps/repro.ru
26
28
  - apps/tmp/calendar.sqlite3
27
29
  - apps/tmp/calendar.sqlite3-shm
28
30
  - apps/tmp/calendar.sqlite3-wal
29
31
  - apps/tmp/local_secret.txt
30
- - apps/tmp/pagy-keyset.sqlite3
31
- - apps/tmp/pagy-keyset.sqlite3-shm
32
- - apps/tmp/pagy-keyset.sqlite3-wal
32
+ - apps/tmp/pagy-keyset-ar.sqlite3
33
+ - apps/tmp/pagy-keyset-ar.sqlite3-shm
34
+ - apps/tmp/pagy-keyset-ar.sqlite3-wal
35
+ - apps/tmp/pagy-keyset-s.sqlite3
33
36
  - bin/pagy
34
37
  - config/pagy.rb
35
38
  - javascripts/pagy-module.js
@@ -40,6 +43,7 @@ files:
40
43
  - javascripts/pagy.mjs
41
44
  - lib/optimist.rb
42
45
  - lib/pagy.rb
46
+ - lib/pagy/b64.rb
43
47
  - lib/pagy/backend.rb
44
48
  - lib/pagy/calendar.rb
45
49
  - lib/pagy/calendar/day.rb
@@ -58,26 +62,26 @@ files:
58
62
  - lib/pagy/extras/calendar.rb
59
63
  - lib/pagy/extras/countless.rb
60
64
  - lib/pagy/extras/elasticsearch_rails.rb
61
- - lib/pagy/extras/foundation.rb
62
65
  - lib/pagy/extras/gearbox.rb
63
66
  - lib/pagy/extras/headers.rb
64
67
  - lib/pagy/extras/i18n.rb
65
- - lib/pagy/extras/items.rb
66
68
  - lib/pagy/extras/js_tools.rb
67
69
  - lib/pagy/extras/jsonapi.rb
68
- - lib/pagy/extras/materialize.rb
70
+ - lib/pagy/extras/keyset.rb
71
+ - lib/pagy/extras/limit.rb
69
72
  - lib/pagy/extras/meilisearch.rb
70
73
  - lib/pagy/extras/metadata.rb
71
74
  - lib/pagy/extras/overflow.rb
72
75
  - lib/pagy/extras/pagy.rb
73
76
  - lib/pagy/extras/searchkick.rb
74
- - lib/pagy/extras/semantic.rb
75
77
  - lib/pagy/extras/size.rb
76
78
  - lib/pagy/extras/standalone.rb
77
79
  - lib/pagy/extras/trim.rb
78
- - lib/pagy/extras/uikit.rb
79
80
  - lib/pagy/frontend.rb
80
81
  - lib/pagy/i18n.rb
82
+ - lib/pagy/keyset.rb
83
+ - lib/pagy/keyset/active_record.rb
84
+ - lib/pagy/keyset/sequel.rb
81
85
  - lib/pagy/url_helpers.rb
82
86
  - locales/ar.yml
83
87
  - locales/be.yml
@@ -115,6 +119,7 @@ files:
115
119
  - locales/zh-CN.yml
116
120
  - locales/zh-HK.yml
117
121
  - locales/zh-TW.yml
122
+ - pkg/pagy-9.0.0.gem
118
123
  - stylesheets/pagy.css
119
124
  - stylesheets/pagy.scss
120
125
  - stylesheets/pagy.tailwind.css
@@ -128,14 +133,7 @@ metadata:
128
133
  bug_tracker_uri: https://github.com/ddnexus/pagy/issues
129
134
  changelog_uri: https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md
130
135
  support: https://github.com/ddnexus/pagy/discussions/categories/q-a
131
- post_install_message: |
132
- *********************** PAGY WARNING! ***********************
133
- The foundation, materialize, semantic and uikit CSS extras
134
- have been discontinued and will be removed in v9
135
- https://github.com/ddnexus/pagy/discussions/672
136
- The javascript files have been deprecated/renamed
137
- https://ddnexus.github.io/pagy/changelog/#deprecations
138
- *************************************************************
136
+ post_install_message:
139
137
  rdoc_options: []
140
138
  require_paths:
141
139
  - lib
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- warn '[PAGY WARNING] The foundation extra has been discontinued and it will be removed in v9 ' \
4
- '(https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328)'
5
-
6
- require_relative 'js_tools'
7
-
8
- class Pagy # :nodoc:
9
- # Frontend modules are specially optimized for performance.
10
- # The resulting code may not look very elegant, but produces the best benchmarks
11
- module FoundationExtra
12
- # Pagination for Foundation: it returns the html with the series of links to the pages
13
- def pagy_foundation_nav(pagy, id: nil, aria_label: nil, **vars)
14
- id = %( id="#{id}") if id
15
- a = pagy_anchor(pagy)
16
-
17
- html = +%(<nav#{id} class="pagy-foundation-nav" #{
18
- nav_aria_label(pagy, aria_label:)}><ul class="pagination"> #{
19
- foundation_prev_html(pagy, a)})
20
- pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
21
- html << case item
22
- when Integer
23
- %(<li>#{a.(item)}</li>)
24
- when String
25
- %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</li>)
26
- when :gap
27
- %(<li class="ellipsis gap"></li>)
28
- else
29
- raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
30
- end
31
- end
32
- html << %(#{foundation_next_html(pagy, a)}</ul></nav>)
33
- end
34
-
35
- # Javascript pagination for foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
36
- def pagy_foundation_nav_js(pagy, id: nil, aria_label: nil, **vars)
37
- sequels = pagy.sequels(**vars)
38
- id = %( id="#{id}") if id
39
- a = pagy_anchor(pagy)
40
- tokens = { 'before' => %(<ul class="pagination">#{foundation_prev_html pagy, a}),
41
- 'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
42
- 'current' => %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</li>),
43
- 'gap' => %(<li class="ellipsis gap"></li>),
44
- 'after' => %(#{foundation_next_html pagy, a}</ul>) }
45
-
46
- %(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-foundation-nav-js" #{
47
- nav_aria_label(pagy, aria_label:)} #{
48
- pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
49
- }></nav>)
50
- end
51
-
52
- # Javascript combo pagination for Foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
53
- def pagy_foundation_combo_nav_js(pagy, id: nil, aria_label: nil)
54
- id = %( id="#{id}") if id
55
- a = pagy_anchor(pagy)
56
- pages = pagy.pages
57
-
58
- page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) <<
59
- %(style="text-align: center; width: #{pages.to_s.length + 1}rem; ) <<
60
- %(height: 1.5rem; padding: .5rem; margin: 0 .4rem; font-size: .875rem;" class="current">#{JSTools::A_TAG})
61
-
62
- %(<nav#{id} class="pagy-foundation-combo-nav-js" #{
63
- nav_aria_label(pagy, aria_label:)} #{
64
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
65
- }><ul class="pagination">#{
66
- foundation_prev_html(pagy, a)
67
- }<li style="padding: 0 .3rem"><label style="display: flex; align-items: center; white-space: nowrap">#{
68
- pagy_t('pagy.combo_nav_js', page_input:, pages:)
69
- }</label></li>#{
70
- foundation_next_html(pagy, a)
71
- }</ul></nav>)
72
- end
73
-
74
- private
75
-
76
- def foundation_prev_html(pagy, a)
77
- if (p_prev = pagy.prev)
78
- %(<li class="prev">#{a.(p_prev, pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
79
- else
80
- %(<li class="prev disabled" role="link" aria-disabled="true" aria-label="#{
81
- pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</li>)
82
- end
83
- end
84
-
85
- def foundation_next_html(pagy, a)
86
- if (p_next = pagy.next)
87
- %(<li class="next">#{a.(p_next, pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.next'))}</li>)
88
- else
89
- %(<li class="next disabled" role="link" aria-disabled="true" aria-label="#{
90
- pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</li>)
91
- end
92
- end
93
- end
94
- Frontend.prepend FoundationExtra
95
- end
@@ -1,64 +0,0 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/items
2
- # frozen_string_literal: true
3
-
4
- require_relative 'js_tools'
5
-
6
- class Pagy # :nodoc:
7
- DEFAULT[:items_param] = :items
8
- DEFAULT[:max_items] = 100
9
- DEFAULT[:items_extra] = true # extra enabled by default
10
-
11
- # Allow the client to request a custom number of items per page with an optional selector UI
12
- module ItemsExtra
13
- # Additions for the Backend module
14
- module BackendAddOn
15
- private
16
-
17
- # Set the items variable considering the params and other pagy variables
18
- def pagy_set_items_from_params(vars)
19
- return if vars[:items] # :items explicitly set
20
- return unless vars.key?(:items_extra) ? vars[:items_extra] : DEFAULT[:items_extra] # :items_extra is false
21
- return unless (items_count = pagy_get_items_size(vars)) # no items from request params
22
-
23
- vars[:items] = [items_count.to_i, vars.key?(:max_items) ? vars[:max_items] : DEFAULT[:max_items]].compact.min
24
- end
25
-
26
- # Get the items count from the params
27
- # Overridable by the jsonapi extra
28
- def pagy_get_items_size(vars)
29
- params[vars[:items_param] || DEFAULT[:items_param]]
30
- end
31
- end
32
- Backend.prepend ItemsExtra::BackendAddOn
33
-
34
- # Additions for the Frontend module
35
- module FrontendAddOn
36
- ITEMS_TOKEN = '__pagy_items__'
37
-
38
- # Return the items selector HTML. For example "Show [20] items per page"
39
- def pagy_items_selector_js(pagy, id: nil, item_name: nil)
40
- return '' unless pagy.vars[:items_extra]
41
-
42
- id = %( id="#{id}") if id
43
- vars = pagy.vars
44
- items = vars[:items]
45
- vars[:items] = ITEMS_TOKEN
46
- url_token = pagy_url_for(pagy, PAGE_TOKEN)
47
- vars[:items] = items # restore the items
48
-
49
- items_input = %(<input name="items" type="number" min="1" max="#{vars[:max_items]}" value="#{
50
- items}" style="padding: 0; text-align: center; width: #{items.to_s.length + 1}rem;">#{JSTools::A_TAG})
51
-
52
- %(<span#{id} class="pagy items-selector-js" #{
53
- pagy_data(pagy, :selector, pagy.from, url_token)
54
- }><label>#{
55
- pagy_t('pagy.items_selector_js',
56
- item_name: item_name || pagy_t('pagy.item_name', count: items),
57
- items_input:,
58
- count: items)
59
- }</label></span>)
60
- end
61
- end
62
- Frontend.prepend ItemsExtra::FrontendAddOn
63
- end
64
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- warn '[PAGY WARNING] The materialize extra has been discontinued and it will be removed in v9 ' \
4
- '(https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328)'
5
-
6
- require_relative 'js_tools'
7
-
8
- class Pagy # :nodoc:
9
- # Frontend modules are specially optimized for performance.
10
- # The resulting code may not look very elegant, but produces the best benchmarks
11
- module MaterializeExtra
12
- # Pagination for materialize: it returns the html with the series of links to the pages
13
- def pagy_materialize_nav(pagy, id: nil, aria_label: nil, **vars)
14
- id = %( id="#{id}") if id
15
- a = pagy_anchor(pagy)
16
-
17
- html = +%(<div#{id} class="pagy-materialize nav pagination" role="navigation" #{
18
- nav_aria_label(pagy, aria_label:)}><ul class="pagination">#{
19
- materialize_prev_html(pagy, a)})
20
- pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
21
- html << case item
22
- when Integer
23
- %(<li class="waves-effect">#{a.(item)}</li>)
24
- when String
25
- %(<li class="active"><a role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</a></li>)
26
- when :gap
27
- %(<li class="gap disabled"><a role="link" aria-disabled="true">#{pagy_t 'pagy.gap'}</a></li>)
28
- else
29
- raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
30
- end
31
- end
32
- html << %(#{materialize_next_html(pagy, a)}</ul></div>)
33
- end
34
-
35
- # Javascript pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file
36
- def pagy_materialize_nav_js(pagy, id: nil, aria_label: nil, **vars)
37
- sequels = pagy.sequels(**vars)
38
- id = %( id="#{id}") if id
39
- a = pagy_anchor(pagy)
40
-
41
- tokens = { 'before' => %(<ul class="pagination">#{materialize_prev_html pagy, a}),
42
- 'a' => %(<li class="waves-effect">#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
43
- 'current' => %(<li class="active"><a role="link" aria-current="page" aria-disabled="true">#{
44
- LABEL_TOKEN}</a></li>),
45
- 'gap' => %(<li class="gap disabled"><a role="link" aria-disabled="true">#{pagy_t 'pagy.gap'}</a></li>),
46
- 'after' => %(#{materialize_next_html pagy, a}</ul>) }
47
-
48
- %(<div#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize nav-js" role="navigation" #{
49
- nav_aria_label(pagy, aria_label:)} #{
50
- pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
51
- }></div>)
52
- end
53
-
54
- # Javascript combo pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file
55
- def pagy_materialize_combo_nav_js(pagy, id: nil, aria_label: nil)
56
- id = %( id="#{id}") if id
57
- a = pagy_anchor(pagy)
58
- pages = pagy.pages
59
-
60
- page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) <<
61
- %(style="text-align: center; width: #{pages.to_s.length + 1}rem; height: 1.5rem; font-size: 1.2rem; ) <<
62
- %(border: none; border-radius: 2px; color: white; background-color: #ee6e73;" class="browser-default"> ) <<
63
- JSTools::A_TAG
64
-
65
- %(<ul#{id} class="pagy-materialize combo-nav-js pagination" role="navigation" style="padding-right: 0;" #{
66
- nav_aria_label(pagy, aria_label:)} #{
67
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
68
- }>#{
69
- materialize_prev_html(pagy, a)
70
- }<li style="vertical-align: -webkit-baseline-middle;"><label style="font-size: 1.2rem;">#{
71
- pagy_t('pagy.combo_nav_js', page_input:, pages:)
72
- }</label></li>#{
73
- materialize_next_html(pagy, a)
74
- }</ul>)
75
- end
76
-
77
- private
78
-
79
- def materialize_prev_html(pagy, a)
80
- if (p_prev = pagy.prev)
81
- %(<li class="waves-effect prev">#{
82
- a.(p_prev, '<i class="material-icons">chevron_left</i>', aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
83
- else
84
- %(<li class="prev disabled"><a role="link" aria-disabled="true" aria-label="#{
85
- pagy_t('pagy.aria_label.prev')}"><i class="material-icons">chevron_left</i></a></li>)
86
- end
87
- end
88
-
89
- def materialize_next_html(pagy, a)
90
- if (p_next = pagy.next)
91
- %(<li class="waves-effect next">#{
92
- a.(p_next, '<i class="material-icons">chevron_right</i>', aria_label: pagy_t('pagy.aria_label.next'))}</li>)
93
- else
94
- %(<li class="next disabled"#><a role="link" aria-disabled="true" aria-label="#{
95
- pagy_t('pagy.aria_label.next')}><i class="material-icons">chevron_right</i></a></li>)
96
- end
97
- end
98
- end
99
- Frontend.prepend MaterializeExtra
100
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- warn '[PAGY WARNING] The semantic extra has been discontinued and it will be removed in v9 ' \
4
- '(https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328)'
5
-
6
- require_relative 'js_tools'
7
-
8
- class Pagy # :nodoc:
9
- # Frontend modules are specially optimized for performance.
10
- # The resulting code may not look very elegant, but produces the best benchmarks
11
- module SemanticExtra
12
- # Pagination for semantic: it returns the html with the series of links to the pages
13
- def pagy_semantic_nav(pagy, id: nil, aria_label: nil, **vars)
14
- id = %( id="#{id}") if id
15
- a = pagy_anchor(pagy)
16
-
17
- html = %(<div#{id} role="navigation" class="pagy-semantic nav ui pagination menu" #{
18
- nav_aria_label(pagy, aria_label:)}>#{semantic_prev_html(pagy, a)})
19
- pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
- html << case item
21
- when Integer
22
- a.(item, pagy.label_for(item), classes: 'item')
23
- when String
24
- %(<a role="link" class="item active" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</a>)
25
- when :gap
26
- %(<div class="disabled item">#{pagy_t 'pagy.gap'}</div>)
27
- else
28
- raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
29
- end
30
- end
31
- html << %(#{semantic_next_html(pagy, a)}</div>)
32
- end
33
-
34
- # Javascript pagination for semantic: it returns a nav with a data-pagy attribute used by the pagy.js file
35
- def pagy_semantic_nav_js(pagy, id: nil, aria_label: nil, **vars)
36
- sequels = pagy.sequels(**vars)
37
- id = %( id="#{id}") if id
38
- a = pagy_anchor(pagy)
39
- tokens = { 'before' => semantic_prev_html(pagy, a),
40
- 'a' => a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'item'),
41
- 'current' => %(<a role="link" class="item active" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a>),
42
- 'gap' => %(<div class="disabled item">#{pagy_t('pagy.gap')}</div>),
43
- 'after' => semantic_next_html(pagy, a) }
44
-
45
- %(<div#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-semantic nav-js ui pagination menu" role="navigation" #{
46
- nav_aria_label(pagy, aria_label:)} #{
47
- pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
48
- }></div>)
49
- end
50
-
51
- # Combo pagination for semantic: it returns a nav with a data-pagy attribute used by the pagy.js file
52
- def pagy_semantic_combo_nav_js(pagy, id: nil, aria_label: nil)
53
- id = %( id="#{id}") if id
54
- a = pagy_anchor(pagy)
55
- pages = pagy.pages
56
-
57
- page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page") <<
58
- %(style="text-align: center; width: #{pages.to_s.length + 1}rem; padding: 0; margin: 0 0.3rem">) <<
59
- JSTools::A_TAG
60
-
61
- %(<div#{id} class="pagy-semantic combo-nav-js ui compact menu" role="navigation" #{
62
- nav_aria_label(pagy, aria_label:)} #{
63
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
64
- }>#{
65
- semantic_prev_html(pagy, a)
66
- }<div class="item"><label>#{
67
- pagy_t('pagy.combo_nav_js', page_input:, pages:)
68
- }</label></div> #{
69
- semantic_next_html(pagy, a)
70
- }</div>)
71
- end
72
-
73
- private
74
-
75
- def semantic_prev_html(pagy, a)
76
- if (p_prev = pagy.prev)
77
- a.(p_prev, pagy_t('pagy.prev'), classes: 'item', aria_label: pagy_t('pagy.aria_label.prev'))
78
- else
79
- %(<div class="item disabled" role="a" aria-disabled="true" aria-label="#{
80
- pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</div>)
81
- end
82
- end
83
-
84
- def semantic_next_html(pagy, a)
85
- if (p_next = pagy.next)
86
- a.(p_next, pagy_t('pagy.next'), classes: 'item', aria_label: pagy_t('pagy.aria_label.next'))
87
- else
88
- %(<div class="item disabled" role="link" aria-disabled="true" aria=label="#{
89
- pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.next')}</div>)
90
- end
91
- end
92
- end
93
- Frontend.prepend SemanticExtra
94
- end