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,25 +1,24 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/materialize
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 MaterializeExtra
10
10
  # Pagination for materialize: it returns the html with the series of links to the pages
11
- def pagy_materialize_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_materialize_nav(pagy, id: nil, aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
15
14
 
16
- html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" #{
17
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><ul class="pagination">)
18
- html << materialize_prev_html(pagy, link)
15
+ html = +%(<div#{id} class="pagy-materialize nav pagination" role="navigation" #{
16
+ nav_aria_label(pagy, aria_label:)}><ul class="pagination">#{
17
+ materialize_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 class="waves-effect">#{link.call(item)}</li>)
21
+ %(<li class="waves-effect">#{a.(item)}</li>)
23
22
  when String
24
23
  %(<li class="active"><a role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</a></li>)
25
24
  when :gap
@@ -28,67 +27,69 @@ 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 << materialize_next_html(pagy, link)
32
- html << %(</ul></div>)
30
+ html << %(#{materialize_next_html(pagy, a)}</ul></div>)
33
31
  end
34
32
 
35
- # Javascript pagination for materialize: it returns a nav and a JSON tag used by the pagy.js file
36
- def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '',
37
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
33
+ # Javascript pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file
34
+ def pagy_materialize_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:)
36
+ id = %( id="#{id}") if id
37
+ a = pagy_anchor(pagy)
41
38
 
42
- tags = { 'before' => %(<ul class="pagination">#{materialize_prev_html pagy, link}),
43
- 'link' => %(<li class="waves-effect">#{link.call(PAGE_TOKEN, LABEL_TOKEN)}</li>),
44
- 'active' => %(<li class="active"><a role="link" aria-current="page" aria-disabled="true">#{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, link}</ul>) }
39
+ tokens = { 'before' => %(<ul class="pagination">#{materialize_prev_html pagy, a}),
40
+ 'a' => %(<li class="waves-effect">#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
41
+ 'current' => %(<li class="active"><a role="link" aria-current="page" aria-disabled="true">#{
42
+ LABEL_TOKEN}</a></li>),
43
+ 'gap' => %(<li class="gap disabled"><a role="link" aria-disabled="true">#{pagy_t 'pagy.gap'}</a></li>),
44
+ 'after' => %(#{materialize_next_html pagy, a}</ul>) }
47
45
 
48
- %(<div#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize-nav-js" role="navigation" #{
49
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
50
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></div>)
46
+ %(<div#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize nav-js" role="navigation" #{
47
+ nav_aria_label(pagy, aria_label:)} #{
48
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
49
+ }></div>)
51
50
  end
52
51
 
53
- # Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the pagy.js file
54
- def pagy_materialize_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
55
- nav_aria_label: nil, nav_i18n_key: nil)
56
- p_id = %( id="#{pagy_id}") if pagy_id
57
- link = pagy_link_proc(pagy, link_extra:)
58
- p_page = pagy.page
59
- p_pages = pagy.pages
60
- style = ' style="vertical-align: middle"'
61
- input = %(<input name="page" type="number" class="browser-default" min="1" max="#{p_pages}" value="#{
62
- p_page}" style="text-align: center; width: #{p_pages.to_s.length + 1}rem;" aria-current="page">)
52
+ # Javascript combo pagination for materialize: it returns a nav with a data-pagy attribute used by the pagy.js file
53
+ def pagy_materialize_combo_nav_js(pagy, id: nil, aria_label: nil)
54
+ id = %( id="#{id}") if id
55
+ a = pagy_anchor(pagy)
56
+ pages = pagy.pages
63
57
 
64
- html = %(<ul#{p_id} class="pagy-materialize-combo-nav-js pagination chip" role="navigation" #{
65
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)})
66
- %(#{html} style="padding-right: 0" #{
67
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}>#{
68
- materialize_prev_html pagy, link, style}<li class="pagy-combo-input">#{
69
- pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</li>#{
70
- materialize_next_html pagy, link, style}</ul>)
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; height: 1.5rem; font-size: 1.2rem; ) <<
60
+ %(border: none; border-radius: 2px; color: white; background-color: #ee6e73;" class="browser-default">)
61
+
62
+ %(<ul#{id} class="pagy-materialize combo-nav-js pagination" role="navigation" style="padding-right: 0;" #{
63
+ nav_aria_label(pagy, aria_label:)} #{
64
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
65
+ }>#{
66
+ materialize_prev_html(pagy, a)
67
+ }<li style="vertical-align: -webkit-baseline-middle;"><label style="font-size: 1.2rem;">#{
68
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
69
+ }</label></li>#{
70
+ materialize_next_html(pagy, a)
71
+ }</ul>)
71
72
  end
72
73
 
73
74
  private
74
75
 
75
- def materialize_prev_html(pagy, link, style = '')
76
+ def materialize_prev_html(pagy, a)
76
77
  if (p_prev = pagy.prev)
77
- %(<li class="waves-effect prev"#{style}>#{
78
- link.call(p_prev, '<i class="material-icons">chevron_left</i>', prev_aria_label_attr)}</li>)
78
+ %(<li class="waves-effect prev">#{
79
+ a.(p_prev, '<i class="material-icons">chevron_left</i>', aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
79
80
  else
80
- %(<li class="prev disabled"#{style}><a role="link" aria-disabled="true" #{
81
- prev_aria_label_attr}><i class="material-icons">chevron_left</i></a></li>)
81
+ %(<li class="prev disabled"><a role="link" aria-disabled="true" aria-label="#{
82
+ pagy_t('pagy.aria_label.prev')}"><i class="material-icons">chevron_left</i></a></li>)
82
83
  end
83
84
  end
84
85
 
85
- def materialize_next_html(pagy, link, style = '')
86
+ def materialize_next_html(pagy, a)
86
87
  if (p_next = pagy.next)
87
- %(<li class="waves-effect next"#{style}>#{
88
- link.call(p_next, '<i class="material-icons">chevron_right</i>', next_aria_label_attr)}</li>)
88
+ %(<li class="waves-effect next">#{
89
+ a.(p_next, '<i class="material-icons">chevron_right</i>', aria_label: pagy_t('pagy.aria_label.next'))}</li>)
89
90
  else
90
- %(<li class="next disabled"#{style}><a role="link" aria-disabled="true" #{
91
- next_aria_label_attr}><i class="material-icons">chevron_right</i></a></li>)
91
+ %(<li class="next disabled"#><a role="link" aria-disabled="true" aria-label="#{
92
+ pagy_t('pagy.aria_label.next')}><i class="material-icons">chevron_right</i></a></li>)
92
93
  end
93
94
  end
94
95
  end
@@ -0,0 +1,82 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/pagy
2
+ # frozen_string_literal: true
3
+
4
+ require 'pagy/extras/js_tools'
5
+
6
+ class Pagy # :nodoc:
7
+ # Frontend modules are specially optimized for performance.
8
+ # The resulting code may not look very elegant, but produces the best benchmarks
9
+ module PagyExtra
10
+ # pagy_nav is defined in the Frontend itself
11
+ # Javascript pagination: it returns a nav with a data-pagy attribute used by the pagy.js file
12
+ def pagy_nav_js(pagy, id: nil, aria_label: nil, **vars)
13
+ sequels = pagy.sequels(**vars)
14
+ id = %( id="#{id}") if id
15
+ a = pagy_anchor(pagy)
16
+ tokens = { 'before' => prev_a(pagy, a),
17
+ 'a' => a.(PAGE_TOKEN, LABEL_TOKEN),
18
+ 'current' => %(<a class="current" role="link" aria-current="page" aria-disabled="true">#{
19
+ LABEL_TOKEN}</a>),
20
+ 'gap' => %(<a class="gap" role="link" aria-disabled="true">#{pagy_t('pagy.gap')}</a>),
21
+ 'after' => next_a(pagy, a) }
22
+
23
+ %(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy nav-js" #{
24
+ nav_aria_label(pagy, aria_label:)} #{
25
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
26
+ }></nav>)
27
+ end
28
+
29
+ # Javascript combo pagination: it returns a nav with a data-pagy attribute used by the pagy.js file
30
+ def pagy_combo_nav_js(pagy, id: nil, aria_label: nil)
31
+ id = %( id="#{id}") if id
32
+ a = pagy_anchor(pagy)
33
+ pages = pagy.pages
34
+
35
+ page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) <<
36
+ %(style="text-align: center; width: #{pages.to_s.length + 1}rem; padding: 0;">)
37
+
38
+ %(<nav#{id} class="pagy combo-nav-js" #{
39
+ nav_aria_label(pagy, aria_label:)} #{
40
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}>#{
41
+ prev_a(pagy, a)
42
+ }<label>#{
43
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
44
+ }</label>#{
45
+ next_a(pagy, a)
46
+ }</nav>)
47
+ end
48
+
49
+ # Return the previous page URL string or nil
50
+ def pagy_prev_url(pagy, absolute: false)
51
+ pagy_url_for(pagy, pagy.prev, absolute:) if pagy.prev
52
+ end
53
+
54
+ # Return the next page URL string or nil
55
+ def pagy_next_url(pagy, absolute: false)
56
+ pagy_url_for(pagy, pagy.next, absolute:) if pagy.next
57
+ end
58
+
59
+ # Return the enabled/disabled previous page anchor tag
60
+ def pagy_prev_a(pagy, text: pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))
61
+ a = pagy_anchor(pagy)
62
+ prev_a(pagy, a, text:, aria_label:)
63
+ end
64
+
65
+ # Return the enabled/disabled next page anchor tag
66
+ def pagy_next_a(pagy, text: pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.prev'))
67
+ a = pagy_anchor(pagy)
68
+ next_a(pagy, a, text:, aria_label:)
69
+ end
70
+
71
+ # Conditionally return the previous page link tag
72
+ def pagy_prev_link(pagy, absolute: false)
73
+ %(<link href="#{pagy_url_for(pagy, pagy.prev, absolute:)}"/>) if pagy.prev
74
+ end
75
+
76
+ # Conditionally return the next page link tag
77
+ def pagy_next_link(pagy, absolute: false)
78
+ %(<link href="#{pagy_url_for(pagy, pagy.next, absolute:)}"/>) if pagy.next
79
+ end
80
+ end
81
+ Frontend.prepend PagyExtra
82
+ end
@@ -1,25 +1,23 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/semantic
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 SemanticExtra
10
10
  # Pagination for semantic: it returns the html with the series of links to the pages
11
- def pagy_semantic_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_semantic_nav(pagy, id: nil, aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
15
14
 
16
- html = +%(<div#{p_id} role="navigation" class="pagy-semantic-nav ui pagination menu" #{
17
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>)
18
- html << semantic_prev_html(pagy, link)
15
+ html = %(<div#{id} role="navigation" class="pagy-semantic nav ui pagination menu" #{
16
+ nav_aria_label(pagy, aria_label:)}>#{semantic_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
- link.call(item, pagy.label_for(item), %(class="item"))
20
+ a.(item, pagy.label_for(item), classes: 'item')
23
21
  when String
24
22
  %(<a role="link" class="item active" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</a>)
25
23
  when :gap
@@ -28,66 +26,64 @@ class Pagy # :nodoc:
28
26
  raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
29
27
  end
30
28
  end
31
- html << semantic_next_html(pagy, link)
32
- html << %(</div>)
29
+ html << %(#{semantic_next_html(pagy, a)}</div>)
33
30
  end
34
31
 
35
- # Javascript pagination for semantic: it returns a nav and a JSON tag used by the pagy.js file
36
- def pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '',
37
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
32
+ # Javascript pagination for semantic: it returns a nav with a data-pagy attribute used by the pagy.js file
33
+ def pagy_semantic_nav_js(pagy, id: nil, aria_label: nil, **vars)
38
34
  sequels = pagy.sequels(**vars)
39
- p_id = %( id="#{pagy_id}") if pagy_id
40
- link = pagy_link_proc(pagy, link_extra:)
41
- tags = { 'before' => semantic_prev_html(pagy, link),
42
- 'link' => link.call(PAGE_TOKEN, LABEL_TOKEN, %(class="item")),
43
- 'active' => %(<a role="link" class="item active" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a>),
44
- 'gap' => %(<div class="disabled item">#{pagy_t('pagy.gap')}</div>),
45
- 'after' => semantic_next_html(pagy, link) }
35
+ id = %( id="#{id}") if id
36
+ a = pagy_anchor(pagy)
37
+ tokens = { 'before' => semantic_prev_html(pagy, a),
38
+ 'a' => a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'item'),
39
+ 'current' => %(<a role="link" class="item active" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a>),
40
+ 'gap' => %(<div class="disabled item">#{pagy_t('pagy.gap')}</div>),
41
+ 'after' => semantic_next_html(pagy, a) }
46
42
 
47
- %(<div#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-semantic-nav-js ui pagination menu" role="navigation" #{
48
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
49
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></div>)
43
+ %(<div#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-semantic nav-js ui pagination menu" role="navigation" #{
44
+ nav_aria_label(pagy, aria_label:)} #{
45
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
46
+ }></div>)
50
47
  end
51
48
 
52
- # Combo pagination for semantic: it returns a nav and a JSON tag used by the pagy.js file
53
- def pagy_semantic_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: %(class="item" #{link_extra}))
57
- p_page = pagy.page
58
- p_pages = pagy.pages
59
- input = %(<input name="page" type="number" min="1" max="#{p_pages}" value="#{
60
- p_page}" style="padding: 0; text-align: center; width: #{
61
- p_pages.to_s.length + 1}rem; margin: 0 0.3rem" aria-current="page">)
49
+ # Combo pagination for semantic: it returns a nav with a data-pagy attribute used by the pagy.js file
50
+ def pagy_semantic_combo_nav_js(pagy, id: nil, aria_label: nil)
51
+ id = %( id="#{id}") if id
52
+ a = pagy_anchor(pagy)
53
+ pages = pagy.pages
62
54
 
63
- %(<div#{p_id} class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" #{
64
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
65
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}>#{
66
- semantic_prev_html pagy, link
67
- }<div class="pagy-combo-input item">#{
68
- pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
69
- }</div> #{
70
- semantic_next_html pagy, link
55
+ page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page") <<
56
+ %(style="text-align: center; width: #{pages.to_s.length + 1}rem; padding: 0; margin: 0 0.3rem">)
57
+
58
+ %(<div#{id} class="pagy-semantic combo-nav-js ui compact menu" role="navigation" #{
59
+ nav_aria_label(pagy, aria_label:)} #{
60
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
61
+ }>#{
62
+ semantic_prev_html(pagy, a)
63
+ }<div class="item"><label>#{
64
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
65
+ }</label></div> #{
66
+ semantic_next_html(pagy, a)
71
67
  }</div>)
72
68
  end
73
69
 
74
70
  private
75
71
 
76
- def semantic_prev_html(pagy, link)
72
+ def semantic_prev_html(pagy, a)
77
73
  if (p_prev = pagy.prev)
78
- link.call(p_prev, pagy_t('pagy.prev'), %(#{prev_aria_label_attr} class="item"))
74
+ a.(p_prev, pagy_t('pagy.prev'), classes: 'item', aria_label: pagy_t('pagy.aria_label.prev'))
79
75
  else
80
- +%(<div class="item disabled" role="link" aria-disabled="true" #{
81
- prev_aria_label_attr}>#{pagy_t('pagy.prev')}</div>)
76
+ %(<div class="item disabled" role="a" aria-disabled="true" aria-label="#{
77
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</div>)
82
78
  end
83
79
  end
84
80
 
85
- def semantic_next_html(pagy, link)
81
+ def semantic_next_html(pagy, a)
86
82
  if (p_next = pagy.next)
87
- link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="item"))
83
+ a.(p_next, pagy_t('pagy.next'), classes: 'item', aria_label: pagy_t('pagy.aria_label.next'))
88
84
  else
89
- +%(<div class="item disabled" role="link" aria-disabled="true" #{
90
- next_aria_label_attr}>#{pagy_t('pagy.next')}</div>)
85
+ %(<div class="item disabled" role="link" aria-disabled="true" aria=label="#{
86
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.next')}</div>)
91
87
  end
92
88
  end
93
89
  end
@@ -6,23 +6,23 @@ class Pagy # :nodoc:
6
6
 
7
7
  # Remove the page=1 param from the first page link
8
8
  module TrimExtra
9
- # Override the original pagy_link_proc.
10
- # Call the pagy_trim method if the trim_extra is enabled.
11
- def pagy_link_proc(pagy, link_extra: '')
12
- link_proc = super(pagy, link_extra:)
13
- return link_proc unless pagy.vars[:trim_extra]
9
+ # Override the original pagy_a_proc.
10
+ # Call the pagy_trim method for page 1 if the trim_extra is enabled
11
+ def pagy_anchor(pagy)
12
+ a_proc = super(pagy)
13
+ return a_proc unless pagy.vars[:trim_extra]
14
14
 
15
- lambda do |page, text = pagy.label_for(page), extra = ''|
16
- link = +link_proc.call(page, text, extra)
17
- return link unless page.to_s == '1'
15
+ lambda do |page, text = pagy.label_for(page), **opts|
16
+ a = +a_proc.(page, text, **opts)
17
+ return a unless page.to_s == '1'
18
18
 
19
- pagy_trim(pagy, link)
19
+ pagy_trim(pagy, a) # in method for isolated testing
20
20
  end
21
21
  end
22
22
 
23
- # Remove the the :page_param param from the first page link
24
- def pagy_trim(pagy, link)
25
- link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
23
+ # Remove the the :page_param param from the first page anchor
24
+ def pagy_trim(pagy, a)
25
+ a.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
26
26
  end
27
27
  end
28
28
  Frontend.prepend TrimExtra
@@ -1,25 +1,24 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/uikit
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 UikitExtra
10
10
  # Pagination for uikit: it returns the html with the series of links to the pages
11
- def pagy_uikit_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_uikit_nav(pagy, id: nil, aria_label: nil, **vars)
12
+ id = %( id="#{id}") if id
13
+ a = pagy_anchor(pagy)
15
14
 
16
- html = +%(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center" role="navigation" #{
17
-
18
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>#{uikit_prev_html(pagy, link)})
15
+ html = %(<ul#{id} class="pagy-uikit nav uk-pagination uk-flex-center" role="navigation" #{
16
+ nav_aria_label(pagy, aria_label:)}>#{
17
+ uikit_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="uk-active"><span role="link" aria-current="page" aria-disabled="true">#{
25
24
  pagy.label_for(item)}</span></li>)
@@ -29,67 +28,67 @@ class Pagy # :nodoc:
29
28
  raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
30
29
  end
31
30
  end
32
- html << uikit_next_html(pagy, link)
33
- html << %(</ul>)
31
+ html << %(#{uikit_next_html(pagy, a)}</ul>)
34
32
  end
35
33
 
36
- # Javascript pagination for uikit: it returns a nav and a JSON tag used by the pagy.js file
37
- def pagy_uikit_nav_js(pagy, pagy_id: nil, link_extra: '',
38
- nav_aria_label: nil, nav_i18n_key: nil, **vars)
34
+ # Javascript pagination for uikit: it returns a nav with a data-pagy attribute used by the pagy.js file
35
+ def pagy_uikit_nav_js(pagy, id: nil, aria_label: nil, **vars)
39
36
  sequels = pagy.sequels(**vars)
40
- p_id = %( id="#{pagy_id}") if pagy_id
41
- link = pagy_link_proc(pagy, link_extra:)
42
- tags = { 'before' => uikit_prev_html(pagy, link),
43
- 'link' => %(<li>#{link.call(PAGE_TOKEN, LABEL_TOKEN)}</li>),
44
- 'active' => %(<li class="uk-active"><span role="link" aria-current="page" aria-disabled="true">#{
45
- LABEL_TOKEN}</span></li>),
46
- 'gap' => %(<li class="uk-disabled"><span>#{pagy_t 'pagy.gap'}</span></li>),
47
- 'after' => uikit_next_html(pagy, link) }
37
+ id = %( id="#{id}") if id
38
+ a = pagy_anchor(pagy)
39
+ tokens = { 'before' => uikit_prev_html(pagy, a),
40
+ 'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
41
+ 'current' => %(<li class="uk-active"><span role="link" aria-current="page" aria-disabled="true">#{
42
+ LABEL_TOKEN}</span></li>),
43
+ 'gap' => %(<li class="uk-disabled"><span>#{pagy_t 'pagy.gap'}</span></li>),
44
+ 'after' => uikit_next_html(pagy, a) }
48
45
 
49
- %(<ul#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-uikit-nav-js uk-pagination uk-flex-center" role="navigation" #{
50
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
51
- pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></ul>)
46
+ %(<ul#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-uikit nav-js uk-pagination uk-flex-center" role="navigation" #{
47
+ nav_aria_label(pagy, aria_label:)} #{
48
+ pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
49
+ }></ul>)
52
50
  end
53
51
 
54
- # Javascript combo pagination for uikit: it returns a nav and a JSON tag used by the pagy.js file
55
- def pagy_uikit_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
56
- nav_aria_label: nil, nav_i18n_key: nil)
57
- p_id = %( id="#{pagy_id}") if pagy_id
58
- link = pagy_link_proc(pagy, link_extra:)
59
- p_page = pagy.page
60
- p_pages = pagy.pages
61
- input = %(<input name="page" type="number" min="1" max="#{p_pages}" value="#{
62
- p_page}" style="text-align: center; width: #{p_pages.to_s.length + 1}rem;" aria-current="page">)
52
+ # Javascript combo pagination for uikit: it returns a nav with a data-pagy attribute used by the pagy.js file
53
+ def pagy_uikit_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;">)
63
60
 
64
- %(<ul#{p_id} class="pagy-uikit-combo-nav-js uk-button-group uk-pagination uk-flex-center" role="navigation" #{
65
- nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
61
+ %(<ul#{id} class="pagy-uikit combo-nav-js uk-button-group uk-pagination uk-flex-center" role="navigation" #{
62
+ nav_aria_label(pagy, aria_label:)} #{
66
63
  pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
67
64
  }>#{
68
- uikit_prev_html pagy, link
69
- }<li>#{
70
- pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
71
- }</li>#{
72
- uikit_next_html pagy, link
65
+ uikit_prev_html(pagy, a)
66
+ }<li><label>#{
67
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
68
+ }</label></li>#{
69
+ uikit_next_html(pagy, a)
73
70
  }</ul>)
74
71
  end
75
72
 
76
73
  private
77
74
 
78
- def uikit_prev_html(pagy, link)
79
- previous_span = %(<span uk-pagination-previous></span>)
75
+ def uikit_prev_html(pagy, a)
76
+ span = %(<span uk-pagination-previous></span>)
80
77
  if (p_prev = pagy.prev)
81
- %(<li>#{link.call(p_prev, previous_span, prev_aria_label_attr)}</li>)
78
+ %(<li>#{a.(p_prev, span, aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
82
79
  else
83
- %(<li class="uk-disabled"><span role="link" aria-disabled="true" #{prev_aria_label_attr}>#{previous_span}</a></li>)
80
+ %(<li class="uk-disabled"><a role="link" aria-disabled="true" aria-label="#{
81
+ pagy_t('pagy.aria_label.prev')}">#{span}</a></li>)
84
82
  end
85
83
  end
86
84
 
87
- def uikit_next_html(pagy, link)
88
- next_span = %(<span uk-pagination-next></span>)
85
+ def uikit_next_html(pagy, a)
86
+ span = %(<span uk-pagination-next></span>)
89
87
  if (p_next = pagy.next)
90
- %(<li>#{link.call(p_next, next_span, next_aria_label_attr)}</li>)
88
+ %(<li>#{a.(p_next, span, aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
91
89
  else
92
- %(<li class="uk-disabled"><span role="link" aria-disabled="true" #{prev_aria_label_attr}>#{next_span}</span></li>)
90
+ %(<li class="uk-disabled"><a role="link" aria-disabled="true" aria-label="#{
91
+ pagy_t('pagy.aria_label.next')}">#{span}</a></li>)
93
92
  end
94
93
  end
95
94
  end