pagy 7.0.11 → 8.6.3

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +745 -0
  3. data/apps/demo.ru +435 -0
  4. data/apps/rails.ru +212 -0
  5. data/apps/repro.ru +177 -0
  6. data/apps/tmp/calendar.sqlite3 +0 -0
  7. data/apps/tmp/calendar.sqlite3-shm +0 -0
  8. data/apps/tmp/calendar.sqlite3-wal +0 -0
  9. data/apps/tmp/local_secret.txt +1 -0
  10. data/apps/tmp/pagy-keyset.sqlite3 +0 -0
  11. data/apps/tmp/pagy-keyset.sqlite3-shm +0 -0
  12. data/apps/tmp/pagy-keyset.sqlite3-wal +0 -0
  13. data/bin/pagy +100 -0
  14. data/{lib/config → config}/pagy.rb +31 -73
  15. data/javascripts/pagy-module.js +100 -0
  16. data/javascripts/pagy.js +4 -0
  17. data/javascripts/pagy.min.js +4 -0
  18. data/javascripts/pagy.min.js.map +10 -0
  19. data/javascripts/pagy.mjs +100 -0
  20. data/lib/optimist.rb +1022 -0
  21. data/lib/pagy/backend.rb +8 -3
  22. data/lib/pagy/calendar/day.rb +4 -3
  23. data/lib/pagy/calendar/month.rb +4 -3
  24. data/lib/pagy/calendar/quarter.rb +4 -3
  25. data/lib/pagy/calendar/unit.rb +106 -0
  26. data/lib/pagy/calendar/week.rb +3 -3
  27. data/lib/pagy/calendar/year.rb +4 -3
  28. data/lib/pagy/calendar.rb +55 -99
  29. data/lib/pagy/console.rb +2 -2
  30. data/lib/pagy/countless.rb +15 -10
  31. data/lib/pagy/extras/arel.rb +1 -1
  32. data/lib/pagy/extras/array.rb +1 -1
  33. data/lib/pagy/extras/bootstrap.rb +52 -63
  34. data/lib/pagy/extras/bulma.rb +49 -64
  35. data/lib/pagy/extras/calendar.rb +35 -5
  36. data/lib/pagy/extras/countless.rb +2 -2
  37. data/lib/pagy/extras/foundation.rb +52 -62
  38. data/lib/pagy/extras/gearbox.rb +28 -27
  39. data/lib/pagy/extras/headers.rb +1 -1
  40. data/lib/pagy/extras/i18n.rb +1 -1
  41. data/lib/pagy/extras/items.rb +21 -18
  42. data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +9 -6
  43. data/lib/pagy/extras/jsonapi.rb +2 -2
  44. data/lib/pagy/extras/materialize.rb +56 -52
  45. data/lib/pagy/extras/metadata.rb +6 -2
  46. data/lib/pagy/extras/overflow.rb +5 -4
  47. data/lib/pagy/extras/pagy.rb +82 -0
  48. data/lib/pagy/extras/semantic.rb +50 -51
  49. data/lib/pagy/extras/size.rb +40 -0
  50. data/lib/pagy/extras/standalone.rb +2 -2
  51. data/lib/pagy/extras/trim.rb +12 -12
  52. data/lib/pagy/extras/uikit.rb +51 -50
  53. data/lib/pagy/frontend.rb +39 -53
  54. data/lib/pagy/url_helpers.rb +9 -10
  55. data/lib/pagy.rb +51 -82
  56. data/{lib/locales → locales}/ar.yml +10 -11
  57. data/{lib/locales → locales}/be.yml +5 -5
  58. data/{lib/locales → locales}/bg.yml +5 -5
  59. data/{lib/locales → locales}/bs.yml +5 -5
  60. data/locales/ca.yml +21 -0
  61. data/locales/ckb.yml +18 -0
  62. data/{lib/locales → locales}/cs.yml +5 -5
  63. data/locales/da.yml +21 -0
  64. data/{lib/locales → locales}/de.yml +5 -5
  65. data/{lib/locales → locales}/en.yml +5 -5
  66. data/{lib/locales → locales}/es.yml +3 -3
  67. data/{lib/locales → locales}/fr.yml +5 -5
  68. data/{lib/locales → locales}/hr.yml +5 -5
  69. data/{lib/locales → locales}/id.yml +5 -5
  70. data/{lib/locales → locales}/it.yml +5 -5
  71. data/{lib/locales → locales}/ja.yml +5 -5
  72. data/{lib/locales → locales}/km.yml +5 -5
  73. data/locales/ko.yml +17 -0
  74. data/{lib/locales → locales}/nb.yml +5 -5
  75. data/{lib/locales → locales}/nl.yml +5 -5
  76. data/{lib/locales → locales}/nn.yml +5 -5
  77. data/{lib/locales → locales}/pl.yml +5 -5
  78. data/{lib/locales → locales}/pt-BR.yml +3 -3
  79. data/{lib/locales → locales}/pt.yml +3 -3
  80. data/locales/ru.yml +25 -0
  81. data/{lib/locales → locales}/sr.yml +5 -5
  82. data/{lib/locales → locales}/sv-SE.yml +5 -5
  83. data/{lib/locales → locales}/sv.yml +5 -5
  84. data/{lib/locales → locales}/sw.yml +5 -5
  85. data/{lib/locales → locales}/ta.yml +5 -5
  86. data/{lib/locales → locales}/tr.yml +5 -5
  87. data/{lib/locales → locales}/uk.yml +5 -5
  88. data/locales/vi.yml +17 -0
  89. data/{lib/locales → locales}/zh-CN.yml +5 -5
  90. data/{lib/locales → locales}/zh-HK.yml +5 -5
  91. data/{lib/locales → locales}/zh-TW.yml +5 -5
  92. data/{lib/stylesheets → stylesheets}/pagy.css +19 -34
  93. data/{lib/stylesheets → stylesheets}/pagy.scss +17 -19
  94. data/stylesheets/pagy.tailwind.css +21 -0
  95. metadata +76 -53
  96. data/lib/javascripts/pagy-dev.js +0 -112
  97. data/lib/javascripts/pagy-module.js +0 -111
  98. data/lib/javascripts/pagy.js +0 -1
  99. data/lib/locales/ca.yml +0 -23
  100. data/lib/locales/ckb.yml +0 -18
  101. data/lib/locales/da.yml +0 -23
  102. data/lib/locales/ko.yml +0 -19
  103. data/lib/locales/ru.yml +0 -27
  104. data/lib/locales/vi.yml +0 -17
  105. data/lib/pagy/calendar/helper.rb +0 -65
  106. data/lib/pagy/extras/navs.rb +0 -51
  107. data/lib/pagy/extras/support.rb +0 -40
  108. data/lib/stylesheets/pagy.tailwind.scss +0 -24
  109. /data/{lib/javascripts/pagy-module.d.ts → javascripts/pagy.d.ts} +0 -0
@@ -1,106 +1,95 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bootstrap
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/frontend_helpers'
4
+ require_relative 'js_tools'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  # Frontend modules are specially optimized for performance.
8
8
  # The resulting code may not look very elegant, but produces the best benchmarks
9
9
  module BootstrapExtra
10
10
  # Pagination for bootstrap: it returns the html with the series of links to the pages
11
- def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '',
12
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
13
- p_id = %( id="#{pagy_id}") if pagy_id
14
- link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
11
+ def pagy_bootstrap_nav(pagy, id: nil, classes: 'pagination', aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
15
14
 
16
- html = +%(<nav#{p_id} class="pagy-bootstrap-nav" #{
17
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><ul class="pagination">)
18
- html << bootstrap_prev_html(pagy, link)
15
+ html = %(<nav#{id} class="pagy-bootstrap nav" #{nav_aria_label(pagy, aria_label:)}><ul class="#{classes}">#{
16
+ bootstrap_prev_html(pagy, a)})
19
17
  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
18
  html << case item
21
19
  when Integer
22
- %(<li class="page-item">#{link.call(item)}</li>)
20
+ %(<li class="page-item">#{a.(item, classes: 'page-link')}</li>)
23
21
  when String
24
22
  %(<li class="page-item active"><a role="link" class="page-link" aria-current="page" aria-disabled="true">#{
25
23
  pagy.label_for(item)}</a></li>)
26
24
  when :gap
27
25
  %(<li class="page-item gap disabled"><a role="link" class="page-link" aria-disabled="true">#{
28
- pagy_t 'pagy.gap'}</a></li>)
26
+ pagy_t('pagy.gap')}</a></li>)
29
27
  else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
30
28
  end
31
29
  end
32
- html << bootstrap_next_html(pagy, link)
33
- html << %(</ul></nav>)
30
+ html << %(#{bootstrap_next_html(pagy, a)}</ul></nav>)
34
31
  end
35
32
 
36
- # Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the pagy.js file
37
- def pagy_bootstrap_nav_js(pagy, pagy_id: nil, link_extra: '',
38
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
33
+ # Javascript pagination for bootstrap: it returns a nav with a data-pagy attribute used by the pagy.js file
34
+ def pagy_bootstrap_nav_js(pagy, id: nil, classes: 'pagination', aria_label: nil, **vars)
39
35
  sequels = pagy.sequels(**vars)
40
- p_id = %( id="#{pagy_id}") if pagy_id
41
- link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
42
- tags = { 'before' => %(<ul class="pagination">#{bootstrap_prev_html pagy, link}),
43
- 'link' => %(<li class="page-item">#{link.call(PAGE_TOKEN, LABEL_TOKEN)}</li>),
44
- 'active' => %(<li class="page-item active"><a role="link" class="page-link" ) +
45
- %(aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a></li>),
46
- 'gap' => %(<li class="page-item gap disabled"><a role="link" class="page-link" aria-disabled="true">#{
47
- pagy_t 'pagy.gap'}</a></li>),
48
- 'after' => %(#{bootstrap_next_html pagy, link}</ul>) }
36
+ id = %( id="#{id}") if id
37
+ a = pagy_anchor(pagy)
38
+ tokens = { 'before' => %(<ul class="#{classes}">#{bootstrap_prev_html(pagy, a)}),
39
+ 'a' => %(<li class="page-item">#{a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'page-link')}</li>),
40
+ 'current' => %(<li class="page-item active"><a role="link" class="page-link" ) +
41
+ %(aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a></li>),
42
+ 'gap' => %(<li class="page-item gap disabled"><a role="link" class="page-link" aria-disabled="true">#{
43
+ pagy_t('pagy.gap')}</a></li>),
44
+ 'after' => %(#{bootstrap_next_html pagy, a}</ul>) }
49
45
 
50
- %(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bootstrap-nav-js" #{
51
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
52
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))
46
+ %(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bootstrap nav-js" #{
47
+ nav_aria_label(pagy, aria_label:)} #{
48
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
53
49
  }></nav>)
54
50
  end
55
51
 
56
- # Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the pagy.js file
57
- def pagy_bootstrap_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
58
- nav_aria_label: nil, nav_i18n_key: nil)
59
- p_id = %( id="#{pagy_id}") if pagy_id
60
- link = pagy_link_proc(pagy, link_extra:)
61
- p_page = pagy.page
62
- p_pages = pagy.pages
63
- input = %(<input name="page" type="number" min="1" max="#{p_pages}" value="#{
64
- p_page}" style="padding: 0; border: none; text-align: center; width: #{
65
- p_pages.to_s.length + 1}rem;" aria-current="page">)
52
+ # Javascript combo pagination for bootstrap: it returns a nav with a data-pagy attribute used by the pagy.js file
53
+ def pagy_bootstrap_combo_nav_js(pagy, id: nil, classes: 'pagination', aria_label: nil)
54
+ id = %( id="#{id}") if id
55
+ a = pagy_anchor(pagy)
56
+ pages = pagy.pages
66
57
 
67
- %(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination" #{
68
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
69
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN)) }><div class="btn-group" role="group">#{
70
- if (p_prev = pagy.prev)
71
- link.call(p_prev, pagy_t('pagy.prev'), %(class="prev btn btn-primary" #{prev_aria_label_attr}))
72
- else
73
- %(<a role="link" class="prev btn btn-primary disabled" aria-disabled="true" #{
74
- prev_aria_label_attr}>#{pagy_t('pagy.prev')}</a>)
75
- end
76
- }<div class="pagy-combo-input btn btn-secondary" style="white-space: nowrap;">#{
77
- pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
78
- if (p_next = pagy.next)
79
- link.call(p_next, pagy_t('pagy.next'), %(class="next btn btn-primary" #{next_aria_label_attr}))
80
- else
81
- %(<a role="link" class="next btn btn-primary disabled" aria-disabled="true" #{
82
- next_aria_label_attr}>#{pagy_t 'pagy.next'}</a>)
83
- end
84
- }</div></nav>)
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; padding: 0; ) <<
60
+ %(border: none; display: inline-block;" class="page-link active">#{JSTools::A_TAG})
61
+
62
+ %(<nav#{id} class="pagy-bootstrap combo-nav-js" #{
63
+ nav_aria_label(pagy, aria_label:)} #{
64
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
65
+ }><ul class="#{classes}">#{
66
+ bootstrap_prev_html(pagy, a)
67
+ }<li class="page-item pagy-bootstrap"><label class="page-link">#{
68
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
69
+ }</label></li>#{
70
+ bootstrap_next_html(pagy, a)
71
+ }</ul></nav>)
85
72
  end
86
73
 
87
74
  private
88
75
 
89
- def bootstrap_prev_html(pagy, link)
76
+ def bootstrap_prev_html(pagy, a)
90
77
  if (p_prev = pagy.prev)
91
- %(<li class="page-item prev">#{link.call(p_prev, pagy_t('pagy.prev'), prev_aria_label_attr)}</li>)
78
+ %(<li class="page-item prev">#{
79
+ a.(p_prev, pagy_t('pagy.prev'), classes: 'page-link', aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
92
80
  else
93
- %(<li class="page-item prev disabled"><a role="link" class="page-link" aria-disabled="true" #{
94
- prev_aria_label_attr}>#{pagy_t('pagy.prev')}</a></li>)
81
+ %(<li class="page-item prev disabled"><a role="link" class="page-link" aria-disabled="true" aria-label="#{
82
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</a></li>)
95
83
  end
96
84
  end
97
85
 
98
- def bootstrap_next_html(pagy, link)
86
+ def bootstrap_next_html(pagy, a)
99
87
  if (p_next = pagy.next)
100
- %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.next'), next_aria_label_attr}</li>)
88
+ %(<li class="page-item next">#{
89
+ a.(p_next, pagy_t('pagy.next'), classes: 'page-link', aria_label: pagy_t('pagy.aria_label.next'))}</li>)
101
90
  else
102
- %(<li class="page-item next disabled"><a role="link" class="page-link" aria-disabled="true" #{
103
- next_aria_label_attr}>#{pagy_t('pagy.next')}</a></li>)
91
+ %(<li class="page-item next disabled"><a role="link" class="page-link" aria-disabled="true" aria-label="#{
92
+ pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</a></li>)
104
93
  end
105
94
  end
106
95
  end
@@ -1,28 +1,24 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bulma
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/frontend_helpers'
4
+ require_relative 'js_tools'
5
5
 
6
6
  class Pagy # :nodoc:
7
- DEFAULT[:bulma_nav_classes] = 'is-centered'
8
-
9
7
  # Frontend modules are specially optimized for performance.
10
8
  # The resulting code may not look very elegant, but produces the best benchmarks
11
9
  module BulmaExtra
12
10
  # Pagination for bulma: it returns the html with the series of links to the pages
13
- def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '',
14
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
15
- p_id = %( id="#{pagy_id}") if pagy_id
16
- link = pagy_link_proc(pagy, link_extra:)
11
+ def pagy_bulma_nav(pagy, id: nil, classes: 'pagy-bulma nav pagination is-centered', aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
17
14
 
18
- html = +%(<nav#{p_id} class="pagy-bulma-nav pagination #{DEFAULT[:bulma_nav_classes]}" #{
19
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>)
20
- html << bulma_prev_next_html(pagy, link)
15
+ html = %(<nav#{id} class="#{classes}" #{nav_aria_label(pagy, aria_label:)}>)
16
+ html << bulma_prev_next_html(pagy, a)
21
17
  html << %(<ul class="pagination-list">)
22
18
  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
23
19
  html << case item
24
20
  when Integer
25
- %(<li>#{link.call(item, pagy.label_for(item), %(class="pagination-link"))}</li>)
21
+ %(<li>#{a.(item, pagy.label_for(item), classes: 'pagination-link')}</li>)
26
22
  when String
27
23
  %(<li><a role="link" class="pagination-link is-current" aria-current="page" aria-disabled="true">#{
28
24
  pagy.label_for(item)}</a></li>)
@@ -34,70 +30,59 @@ class Pagy # :nodoc:
34
30
  html << %(</ul></nav>)
35
31
  end
36
32
 
37
- # Javascript pagination for bulma: it returns a nav and a JSON tag used by the Pagy.nav javascript
38
- def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '',
39
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
33
+ # Javascript pagination for bulma: it returns a nav with a data-pagy attribute used by the Pagy.nav javascript
34
+ def pagy_bulma_nav_js(pagy, id: nil, classes: 'pagy-bulma nav-js pagination is-centered', aria_label: nil, **vars)
40
35
  sequels = pagy.sequels(**vars)
41
- p_id = %( id="#{pagy_id}") if pagy_id
42
- link = pagy_link_proc(pagy, link_extra:)
43
- tags = { 'before' => %(#{bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
44
- 'link' => %(<li>#{link.call(PAGE_TOKEN, LABEL_TOKEN, %(class="pagination-link"))}</li>),
45
- 'active' => %(<li><a role="link" class="pagination-link is-current" aria-current="page" aria-disabled="true">#{
46
- LABEL_TOKEN}</a></li>),
47
- 'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.gap'}</span></li>),
48
- 'after' => '</ul>' }
36
+ id = %( id="#{id}") if id
37
+ a = pagy_anchor(pagy)
38
+ tokens = { 'before' => %(#{bulma_prev_next_html(pagy, a)}<ul class="pagination-list">),
39
+ 'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'pagination-link')}</li>),
40
+ 'current' => %(<li><a role="link" class="pagination-link is-current" aria-current="page" aria-disabled="true">#{
41
+ LABEL_TOKEN}</a></li>),
42
+ 'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.gap'}</span></li>),
43
+ 'after' => '</ul>' }
49
44
 
50
- %(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bulma-nav-js pagination #{DEFAULT[:bulma_nav_classes]}" #{
51
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}#{
52
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
45
+ %(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}#{classes}" #{
46
+ nav_aria_label(pagy, aria_label:)} #{
47
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
48
+ }></nav>)
53
49
  end
54
50
 
55
- # Javascript combo pagination for bulma: it returns a nav and a JSON tag used by the pagy.js file
56
- def pagy_bulma_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
57
- nav_aria_label: nil, nav_i18n_key: nil)
58
- p_id = %( id="#{pagy_id}") if pagy_id
59
- link = pagy_link_proc(pagy, link_extra:)
60
- p_page = pagy.page
61
- p_pages = pagy.pages
62
- input = %(<input name="page" class="input" type="number" min="1" max="#{p_pages}" value="#{
63
- p_page}" style="padding: 0; text-align: center; width: #{
64
- p_pages.to_s.length + 1}rem; margin:0 0.3rem;" aria-current="page">)
51
+ # Javascript combo pagination for bulma: it returns a nav with a data-pagy attribute used by the pagy.js file
52
+ def pagy_bulma_combo_nav_js(pagy, id: nil, classes: 'pagy-bulma combo-nav-js pagination is-centered', 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; height: 1.7rem; margin:0 0.3rem; ) <<
59
+ %(border: none; border-radius: 4px; padding: 0; font-size: 1.1rem; color: white; ) <<
60
+ %(background-color: #485fc7;">#{JSTools::A_TAG})
65
61
 
66
- html = %(<nav#{p_id} class="pagy-bulma-combo-nav-js #{DEFAULT[:bulma_nav_classes]}" #{
67
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
68
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}>)
69
- %(#{html}<div class="field is-grouped is-grouped-centered" role="group">#{
70
- if (p_prev = pagy.prev)
71
- %(<p class="control">#{link.call(p_prev, pagy_t('pagy.prev'), %(class="button" #{prev_aria_label_attr}))}</p>)
72
- else
73
- %(<p class="control"><a role="link" class="button" disabled aria-disabled="true" #{
74
- prev_aria_label_attr}>#{pagy_t 'pagy.prev'}</a></p>)
75
- end
76
- }<div class="pagy-combo-input control level is-mobile">#{
77
- pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
78
- if (p_next = pagy.next)
79
- %(<p class="control">#{link.call(p_next, pagy_t('pagy.next'), %(class="button" #{next_aria_label_attr}))}</p>)
80
- else
81
- %(<p class="control"><a role="link" class="button" disabled aria-disabled="true"#{
82
- next_aria_label_attr}>#{pagy_t 'pagy.next'}</a></p>)
83
- end
84
- }</div></nav>)
62
+ %(<nav#{id} class="#{classes}" #{
63
+ nav_aria_label(pagy, aria_label:)} #{
64
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
65
+ }>#{
66
+ bulma_prev_next_html(pagy, a)
67
+ }<ul class="pagination-list"><li class="pagination-link"><label>#{
68
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
69
+ }</label></li></ul></nav>)
85
70
  end
86
71
 
87
72
  private
88
73
 
89
- def bulma_prev_next_html(pagy, link)
90
- html = +if (p_prev = pagy.prev)
91
- link.call(p_prev, pagy_t('pagy.prev'), %(#{prev_aria_label_attr} class="pagination-previous"))
92
- else
93
- %(<a role="link" class="pagination-previous" disabled aria-disabled="true" #{
94
- prev_aria_label_attr}>#{pagy_t 'pagy.prev'}</a>)
95
- end
74
+ def bulma_prev_next_html(pagy, a)
75
+ html = if (p_prev = pagy.prev)
76
+ a.(p_prev, pagy_t('pagy.prev'), classes: 'pagination-previous', aria_label: pagy_t('pagy.aria_label.prev'))
77
+ else
78
+ %(<a role="link" class="pagination-previous" disabled aria-disabled="true" aria-label="#{
79
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t 'pagy.prev'}</a>)
80
+ end
96
81
  html << if (p_next = pagy.next)
97
- link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="pagination-next"))
82
+ a.(p_next, pagy_t('pagy.next'), classes: 'pagination-next', aria_label: pagy_t('pagy.aria_label.next'))
98
83
  else
99
- %(<a role="link" class="pagination-next" disabled aria-disabled="true" #{
100
- next_aria_label_attr}>#{pagy_t('pagy.next')}</a>)
84
+ %(<a role="link" class="pagination-next" disabled aria-disabled="true" aria-label="#{
85
+ pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</a>)
101
86
  end
102
87
  end
103
88
  end
@@ -1,8 +1,7 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/calendar
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/calendar'
5
- require 'pagy/calendar/helper'
4
+ require_relative '../calendar'
6
5
 
7
6
  class Pagy # :nodoc:
8
7
  # Add pagination filtering by calendar unit (:year, :quarter, :month, :week, :day) to the regular pagination
@@ -20,8 +19,13 @@ class Pagy # :nodoc:
20
19
 
21
20
  conf[:pagy] ||= {}
22
21
  unless conf.key?(:active) && !conf[:active]
23
- calendar, from, to = Calendar::Helper.send(:init, conf, pagy_calendar_period(collection), params)
24
- collection = pagy_calendar_filter(collection, from, to)
22
+ calendar, from, to = Calendar.send(:init, conf, pagy_calendar_period(collection), params)
23
+ if respond_to?(:pagy_calendar_counts)
24
+ calendar.each_key do |unit|
25
+ calendar[unit].vars[:counts] = pagy_calendar_counts(collection, unit, *calendar[unit].vars[:period])
26
+ end
27
+ end
28
+ collection = pagy_calendar_filter(collection, from, to)
25
29
  end
26
30
  pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
27
31
  [calendar, pagy, results]
@@ -40,6 +44,32 @@ class Pagy # :nodoc:
40
44
  end
41
45
  end
42
46
 
47
+ # Override the pagy_anchor
48
+ module FrontendOverride
49
+ # Consider the vars[:count]
50
+ def pagy_anchor(pagy)
51
+ return super unless (counts = pagy.vars[:counts])
52
+
53
+ a_string = pagy.vars[:anchor_string]
54
+ a_string = %( #{a_string}) if a_string
55
+ left, right = %(<a#{a_string} href="#{pagy_url_for(pagy, PAGE_TOKEN)}").split(PAGE_TOKEN, 2)
56
+ # lambda used by all the helpers
57
+ lambda do |page, text = pagy.label_for(page), classes: nil, aria_label: nil|
58
+ count = counts[page - 1]
59
+ item_name = pagy_t('pagy.item_name', count:)
60
+ if count.zero?
61
+ classes = "#{classes && (classes + ' ')}empty-page"
62
+ title = %( title="#{pagy_t('pagy.info.no_items', item_name:, count:)}")
63
+ else
64
+ title = %( title="#{pagy_t('pagy.info.single_page', item_name:, count:)}")
65
+ end
66
+ classes = %( class="#{classes}") if classes
67
+ aria_label = %( aria-label="#{aria_label}") if aria_label
68
+ %(#{left}#{page}#{right}#{title}#{classes}#{aria_label}>#{text}</a>)
69
+ end
70
+ end
71
+ end
72
+
43
73
  # Additions for the Frontend module
44
74
  module UrlHelperAddOn
45
75
  # Return the url for the calendar page at time
@@ -49,5 +79,5 @@ class Pagy # :nodoc:
49
79
  end
50
80
  end
51
81
  Backend.prepend CalendarExtra::BackendAddOn, CalendarExtra::UrlHelperAddOn
52
- Frontend.prepend CalendarExtra::UrlHelperAddOn
82
+ Frontend.prepend CalendarExtra::UrlHelperAddOn, CalendarExtra::FrontendOverride
53
83
  end
@@ -1,7 +1,7 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/countless
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/countless'
4
+ require_relative '../countless'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  DEFAULT[:countless_minimal] = false
@@ -19,7 +19,7 @@ class Pagy # :nodoc:
19
19
  # Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
20
20
  def pagy_countless_get_vars(_collection, vars)
21
21
  pagy_set_items_from_params(vars) if defined?(ItemsExtra)
22
- vars[:page] ||= params[vars[:page_param] || DEFAULT[:page_param]]
22
+ vars[:page] ||= pagy_get_page(vars)
23
23
  vars
24
24
  end
25
25
 
@@ -1,25 +1,26 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/foundation
2
1
  # frozen_string_literal: true
3
2
 
4
- require 'pagy/extras/frontend_helpers'
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'
5
7
 
6
8
  class Pagy # :nodoc:
7
9
  # Frontend modules are specially optimized for performance.
8
10
  # The resulting code may not look very elegant, but produces the best benchmarks
9
11
  module FoundationExtra
10
12
  # Pagination for Foundation: it returns the html with the series of links to the pages
11
- def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '',
12
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
13
- p_id = %( id="#{pagy_id}") if pagy_id
14
- link = pagy_link_proc(pagy, link_extra:)
13
+ def pagy_foundation_nav(pagy, id: nil, aria_label: nil, **vars)
14
+ id = %( id="#{id}") if id
15
+ a = pagy_anchor(pagy)
15
16
 
16
- html = +%(<nav#{p_id} class="pagy-foundation-nav" #{
17
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><ul class="pagination">)
18
- html << foundation_prev_html(pagy, link)
17
+ html = +%(<nav#{id} class="pagy-foundation-nav" #{
18
+ nav_aria_label(pagy, aria_label:)}><ul class="pagination"> #{
19
+ foundation_prev_html(pagy, a)})
19
20
  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
21
  html << case item
21
22
  when Integer
22
- %(<li>#{link.call item}</li>)
23
+ %(<li>#{a.(item)}</li>)
23
24
  when String
24
25
  %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</li>)
25
26
  when :gap
@@ -28,76 +29,65 @@ class Pagy # :nodoc:
28
29
  raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
29
30
  end
30
31
  end
31
- html << pagy_foundation_next_html(pagy, link)
32
- html << %(</ul></nav>)
32
+ html << %(#{foundation_next_html(pagy, a)}</ul></nav>)
33
33
  end
34
34
 
35
- # Javascript pagination for foundation: it returns a nav and a JSON tag used by the pagy.js file
36
- def pagy_foundation_nav_js(pagy, pagy_id: nil, link_extra: '',
37
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
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)
38
37
  sequels = pagy.sequels(**vars)
39
- p_id = %( id="#{pagy_id}") if pagy_id
40
- link = pagy_link_proc(pagy, link_extra:)
41
- tags = { 'before' => %(<ul class="pagination">#{foundation_prev_html pagy, link}),
42
- 'link' => %(<li>#{link.call(PAGE_TOKEN, LABEL_TOKEN)}</li>),
43
- 'active' => %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</li>),
44
- 'gap' => %(<li class="ellipsis gap"></li>),
45
- 'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
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>) }
46
45
 
47
- %(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-foundation-nav-js" #{
48
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
49
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
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
50
  end
51
51
 
52
- # Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the pagy.js file
53
- def pagy_foundation_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
54
- nav_aria_label: nil, nav_i18n_key: nil)
55
- p_id = %( id="#{pagy_id}") if pagy_id
56
- link = pagy_link_proc(pagy, link_extra:)
57
- p_page = pagy.page
58
- p_pages = pagy.pages
59
- input = %(<input name="page" class="input-group-field cell shrink" type="number" min="1" max="#{
60
- p_pages}" value="#{p_page}" style="width: #{
61
- p_pages.to_s.length + 1}rem; padding: 0 0.3rem; margin: 0 0.3rem;" aria-current="page">)
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})
62
61
 
63
- %(<nav#{p_id} class="pagy-foundation-combo-nav-js" #{
64
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
65
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}><div class="input-group">#{
66
- if (p_prev = pagy.prev)
67
- link.call(p_prev, pagy_t('pagy.prev'),
68
- %(style="margin-bottom: 0" class="prev button primary" #{prev_aria_label_attr}))
69
- else
70
- %(<a style="margin-bottom: 0" class="prev button primary disabled" role="link" aria-disabled="true" #{
71
- prev_aria_label_attr}>#{pagy_t('pagy.prev')}</a>)
72
- end
73
- }#{
74
- pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
75
- .sub!('<label>', '<label class="input-group-label">')}#{ # add the class to the official dictionary string
76
- if (p_next = pagy.next)
77
- link.call(p_next, pagy_t('pagy.next'),
78
- %(style="margin-bottom: 0" class="next button primary" #{next_aria_label_attr}))
79
- else
80
- %(<a style="margin-bottom: 0" class="next button primary disabled" role="link" aria-disabled="true" #{
81
- next_aria_label_attr}>#{pagy_t 'pagy.next'}</a>)
82
- end
83
- }</div></nav>)
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>)
84
72
  end
85
73
 
86
74
  private
87
75
 
88
- def foundation_prev_html(pagy, link)
76
+ def foundation_prev_html(pagy, a)
89
77
  if (p_prev = pagy.prev)
90
- %(<li class="prev">#{link.call(p_prev, pagy_t('pagy.prev'), prev_aria_label_attr)}</li>)
78
+ %(<li class="prev">#{a.(p_prev, pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
91
79
  else
92
- %(<li class="prev disabled" role="link" aria-disabled="true" #{prev_aria_label_attr}>#{pagy_t('pagy.prev')}</li>)
80
+ %(<li class="prev disabled" role="link" aria-disabled="true" aria-label="#{
81
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</li>)
93
82
  end
94
83
  end
95
84
 
96
- def pagy_foundation_next_html(pagy, link)
85
+ def foundation_next_html(pagy, a)
97
86
  if (p_next = pagy.next)
98
- %(<li class="next">#{link.call(p_next, pagy_t('pagy.next'), next_aria_label_attr)}</li>)
87
+ %(<li class="next">#{a.(p_next, pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.next'))}</li>)
99
88
  else
100
- %(<li class="next disabled" role="link" aria-disabled="true" #{next_aria_label_attr}>#{pagy_t('pagy.next')}</li>)
89
+ %(<li class="next disabled" role="link" aria-disabled="true" aria-label="#{
90
+ pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</li>)
101
91
  end
102
92
  end
103
93
  end