pagy 7.0.11 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/apps/calendar.ru +2196 -0
  3. data/lib/apps/demo.ru +452 -0
  4. data/lib/apps/rails.ru +205 -0
  5. data/lib/apps/repro.ru +168 -0
  6. data/lib/bin/pagy +83 -0
  7. data/lib/config/pagy.rb +6 -17
  8. data/lib/javascripts/pagy-dev.js +10 -10
  9. data/lib/javascripts/pagy-module.js +9 -9
  10. data/lib/javascripts/pagy.js +1 -1
  11. data/lib/locales/ar.yml +2 -2
  12. data/lib/locales/be.yml +4 -4
  13. data/lib/locales/bg.yml +4 -4
  14. data/lib/locales/bs.yml +4 -4
  15. data/lib/locales/ca.yml +4 -4
  16. data/lib/locales/ckb.yml +4 -4
  17. data/lib/locales/cs.yml +4 -4
  18. data/lib/locales/da.yml +4 -4
  19. data/lib/locales/de.yml +4 -4
  20. data/lib/locales/en.yml +4 -4
  21. data/lib/locales/es.yml +2 -2
  22. data/lib/locales/fr.yml +4 -4
  23. data/lib/locales/hr.yml +4 -4
  24. data/lib/locales/id.yml +4 -4
  25. data/lib/locales/it.yml +4 -4
  26. data/lib/locales/ja.yml +4 -4
  27. data/lib/locales/km.yml +4 -4
  28. data/lib/locales/ko.yml +4 -4
  29. data/lib/locales/nb.yml +4 -4
  30. data/lib/locales/nl.yml +4 -4
  31. data/lib/locales/nn.yml +4 -4
  32. data/lib/locales/pl.yml +4 -4
  33. data/lib/locales/pt-BR.yml +2 -2
  34. data/lib/locales/pt.yml +2 -2
  35. data/lib/locales/ru.yml +4 -4
  36. data/lib/locales/sr.yml +4 -4
  37. data/lib/locales/sv-SE.yml +4 -4
  38. data/lib/locales/sv.yml +4 -4
  39. data/lib/locales/sw.yml +4 -4
  40. data/lib/locales/ta.yml +4 -4
  41. data/lib/locales/tr.yml +4 -4
  42. data/lib/locales/uk.yml +4 -4
  43. data/lib/locales/vi.yml +4 -4
  44. data/lib/locales/zh-CN.yml +4 -4
  45. data/lib/locales/zh-HK.yml +4 -4
  46. data/lib/locales/zh-TW.yml +4 -4
  47. data/lib/optimist.rb +1022 -0
  48. data/lib/pagy/extras/bootstrap.rb +52 -63
  49. data/lib/pagy/extras/bulma.rb +48 -64
  50. data/lib/pagy/extras/foundation.rb +49 -61
  51. data/lib/pagy/extras/items.rb +21 -18
  52. data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +1 -1
  53. data/lib/pagy/extras/materialize.rb +52 -51
  54. data/lib/pagy/extras/pagy.rb +82 -0
  55. data/lib/pagy/extras/semantic.rb +46 -50
  56. data/lib/pagy/extras/trim.rb +12 -12
  57. data/lib/pagy/extras/uikit.rb +48 -49
  58. data/lib/pagy/frontend.rb +31 -48
  59. data/lib/pagy/url_helpers.rb +1 -2
  60. data/lib/pagy.rb +10 -9
  61. data/lib/stylesheets/pagy.css +19 -34
  62. data/lib/stylesheets/pagy.scss +17 -19
  63. data/lib/stylesheets/pagy.tailwind.css +21 -0
  64. metadata +25 -9
  65. data/lib/pagy/extras/navs.rb +0 -51
  66. data/lib/pagy/extras/support.rb +0 -40
  67. data/lib/stylesheets/pagy.tailwind.scss +0 -24
@@ -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 'pagy/extras/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">)
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 'pagy/extras/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,58 @@ 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; background-color: #485fc7;">)
65
60
 
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>)
61
+ %(<nav#{id} class="#{classes}" #{
62
+ nav_aria_label(pagy, aria_label:)} #{
63
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
64
+ }>#{
65
+ bulma_prev_next_html(pagy, a)
66
+ }<ul class="pagination-list"><li class="pagination-link"><label>#{
67
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
68
+ }</label></li></ul></nav>)
85
69
  end
86
70
 
87
71
  private
88
72
 
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
73
+ def bulma_prev_next_html(pagy, a)
74
+ html = if (p_prev = pagy.prev)
75
+ a.(p_prev, pagy_t('pagy.prev'), classes: 'pagination-previous', aria_label: pagy_t('pagy.aria_label.prev'))
76
+ else
77
+ %(<a role="link" class="pagination-previous" disabled aria-disabled="true" aria-label="#{
78
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t 'pagy.prev'}</a>)
79
+ end
96
80
  html << if (p_next = pagy.next)
97
- link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="pagination-next"))
81
+ a.(p_next, pagy_t('pagy.next'), classes: 'pagination-next', aria_label: pagy_t('pagy.aria_label.next'))
98
82
  else
99
- %(<a role="link" class="pagination-next" disabled aria-disabled="true" #{
100
- next_aria_label_attr}>#{pagy_t('pagy.next')}</a>)
83
+ %(<a role="link" class="pagination-next" disabled aria-disabled="true" aria-label="#{
84
+ pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</a>)
101
85
  end
102
86
  end
103
87
  end
@@ -1,25 +1,24 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/foundation
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/frontend_helpers'
4
+ require 'pagy/extras/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 FoundationExtra
10
10
  # 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:)
11
+ def pagy_foundation_nav(pagy, id: nil, aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
15
14
 
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)
15
+ html = +%(<nav#{id} class="pagy-foundation-nav" #{
16
+ nav_aria_label(pagy, aria_label:)}><ul class="pagination"> #{
17
+ foundation_prev_html(pagy, a)})
19
18
  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
19
  html << case item
21
20
  when Integer
22
- %(<li>#{link.call item}</li>)
21
+ %(<li>#{a.(item)}</li>)
23
22
  when String
24
23
  %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</li>)
25
24
  when :gap
@@ -28,76 +27,65 @@ class Pagy # :nodoc:
28
27
  raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
29
28
  end
30
29
  end
31
- html << pagy_foundation_next_html(pagy, link)
32
- html << %(</ul></nav>)
30
+ html << %(#{foundation_next_html(pagy, a)}</ul></nav>)
33
31
  end
34
32
 
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)
33
+ # Javascript pagination for foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
34
+ def pagy_foundation_nav_js(pagy, id: nil, aria_label: nil, **vars)
38
35
  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>) }
36
+ id = %( id="#{id}") if id
37
+ a = pagy_anchor(pagy)
38
+ tokens = { 'before' => %(<ul class="pagination">#{foundation_prev_html pagy, a}),
39
+ 'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
40
+ 'current' => %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</li>),
41
+ 'gap' => %(<li class="ellipsis gap"></li>),
42
+ 'after' => %(#{foundation_next_html pagy, a}</ul>) }
46
43
 
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>)
44
+ %(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-foundation-nav-js" #{
45
+ nav_aria_label(pagy, aria_label:)} #{
46
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
47
+ }></nav>)
50
48
  end
51
49
 
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">)
50
+ # Javascript combo pagination for Foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
51
+ def pagy_foundation_combo_nav_js(pagy, id: nil, aria_label: nil)
52
+ id = %( id="#{id}") if id
53
+ a = pagy_anchor(pagy)
54
+ pages = pagy.pages
62
55
 
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>)
56
+ page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) <<
57
+ %(style="text-align: center; width: #{pages.to_s.length + 1}rem; ) <<
58
+ %(height: 1.5rem; padding: .5rem; margin: 0 .4rem; font-size: .875rem;" class="current">)
59
+
60
+ %(<nav#{id} class="pagy-foundation-combo-nav-js" #{
61
+ nav_aria_label(pagy, aria_label:)} #{
62
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
63
+ }><ul class="pagination">#{
64
+ foundation_prev_html(pagy, a)
65
+ }<li style="padding: 0 .3rem"><label style="display: flex; align-items: center; white-space: nowrap">#{
66
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
67
+ }</label></li>#{
68
+ foundation_next_html(pagy, a)
69
+ }</ul></nav>)
84
70
  end
85
71
 
86
72
  private
87
73
 
88
- def foundation_prev_html(pagy, link)
74
+ def foundation_prev_html(pagy, a)
89
75
  if (p_prev = pagy.prev)
90
- %(<li class="prev">#{link.call(p_prev, pagy_t('pagy.prev'), prev_aria_label_attr)}</li>)
76
+ %(<li class="prev">#{a.(p_prev, pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
91
77
  else
92
- %(<li class="prev disabled" role="link" aria-disabled="true" #{prev_aria_label_attr}>#{pagy_t('pagy.prev')}</li>)
78
+ %(<li class="prev disabled" role="link" aria-disabled="true" #{
79
+ pagy_t('pagy.aria_label.prev')}>#{pagy_t('pagy.prev')}</li>)
93
80
  end
94
81
  end
95
82
 
96
- def pagy_foundation_next_html(pagy, link)
83
+ def foundation_next_html(pagy, a)
97
84
  if (p_next = pagy.next)
98
- %(<li class="next">#{link.call(p_next, pagy_t('pagy.next'), next_aria_label_attr)}</li>)
85
+ %(<li class="next">#{a.(p_next, pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.next'))}</li>)
99
86
  else
100
- %(<li class="next disabled" role="link" aria-disabled="true" #{next_aria_label_attr}>#{pagy_t('pagy.next')}</li>)
87
+ %(<li class="next disabled" role="link" aria-disabled="true" #{
88
+ pagy_t('pagy.aria_label.next')}>#{pagy_t('pagy.next')}</li>)
101
89
  end
102
90
  end
103
91
  end
@@ -1,7 +1,7 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/items
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/frontend_helpers'
4
+ require 'pagy/extras/js_tools'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  DEFAULT[:items_param] = :items
@@ -33,27 +33,30 @@ class Pagy # :nodoc:
33
33
 
34
34
  # Additions for the Frontend module
35
35
  module FrontendAddOn
36
- ITEMS_PLACEHOLDER = '__pagy_items__'
36
+ ITEMS_TOKEN = '__pagy_items__'
37
37
 
38
38
  # Return the items selector HTML. For example "Show [20] items per page"
39
- def pagy_items_selector_js(pagy, pagy_id: nil, item_name: nil, item_i18n_key: nil)
39
+ def pagy_items_selector_js(pagy, id: nil, item_name: nil)
40
40
  return '' unless pagy.vars[:items_extra]
41
41
 
42
- p_id = %( id="#{pagy_id}") if pagy_id
43
- p_vars = pagy.vars
44
- p_items = p_vars[:items]
45
- p_vars[:items] = ITEMS_PLACEHOLDER
46
- url_token = pagy_url_for(pagy, PAGE_TOKEN)
47
- p_vars[:items] = p_items # restore the items
48
-
49
- html = +%(<span#{p_id} class="pagy pagy-items-selector-js" #{pagy_data(pagy, :selector, pagy.from, url_token)}>)
50
- input = %(<input name="items" type="number" min="1" max="#{p_vars[:max_items]}" value="#{
51
- p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length + 1}rem;">)
52
- html << pagy_t('pagy.items_selector_js',
53
- item_name: item_name || pagy_t(item_i18n_key || p_vars[:item_i18n_key], count: p_items),
54
- items_input: input,
55
- count: p_items)
56
- html << %(</span>)
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;">)
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>)
57
60
  end
58
61
  end
59
62
  Frontend.prepend ItemsExtra::FrontendAddOn
@@ -4,7 +4,7 @@ class Pagy # :nodoc:
4
4
  DEFAULT[:steps] = false # default false will use {0 => @vars[:size]}
5
5
 
6
6
  # Private module documented in the main classes
7
- module FrontendHelpers
7
+ module JSTools
8
8
  # Additions for the Pagy class
9
9
  module PagyAddOn
10
10
  # `Pagy` instance method used by the `pagy*_nav_js` helpers.