pagy 7.0.11 → 8.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +2196 -0
  3. data/apps/demo.ru +452 -0
  4. data/apps/rails.ru +205 -0
  5. data/apps/repro.ru +168 -0
  6. data/bin/pagy +83 -0
  7. data/{lib/config → config}/pagy.rb +6 -17
  8. data/javascripts/pagy-dev.js +114 -0
  9. data/{lib/javascripts → javascripts}/pagy-module.js +12 -10
  10. data/javascripts/pagy.js +1 -0
  11. data/lib/optimist.rb +1022 -0
  12. data/lib/pagy/calendar.rb +1 -1
  13. data/lib/pagy/console.rb +2 -2
  14. data/lib/pagy/countless.rb +1 -1
  15. data/lib/pagy/extras/bootstrap.rb +52 -63
  16. data/lib/pagy/extras/bulma.rb +49 -64
  17. data/lib/pagy/extras/calendar.rb +2 -2
  18. data/lib/pagy/extras/countless.rb +1 -1
  19. data/lib/pagy/extras/foundation.rb +49 -61
  20. data/lib/pagy/extras/headers.rb +1 -1
  21. data/lib/pagy/extras/items.rb +21 -18
  22. data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +4 -1
  23. data/lib/pagy/extras/jsonapi.rb +1 -1
  24. data/lib/pagy/extras/materialize.rb +53 -51
  25. data/lib/pagy/extras/metadata.rb +1 -1
  26. data/lib/pagy/extras/pagy.rb +82 -0
  27. data/lib/pagy/extras/semantic.rb +47 -50
  28. data/lib/pagy/extras/trim.rb +12 -12
  29. data/lib/pagy/extras/uikit.rb +48 -49
  30. data/lib/pagy/frontend.rb +33 -50
  31. data/lib/pagy/url_helpers.rb +1 -2
  32. data/lib/pagy.rb +15 -14
  33. data/{lib/locales → locales}/ar.yml +2 -2
  34. data/{lib/locales → locales}/be.yml +4 -4
  35. data/{lib/locales → locales}/bg.yml +4 -4
  36. data/{lib/locales → locales}/bs.yml +4 -4
  37. data/{lib/locales → locales}/ca.yml +4 -4
  38. data/locales/ckb.yml +18 -0
  39. data/{lib/locales → locales}/cs.yml +4 -4
  40. data/{lib/locales → locales}/da.yml +4 -4
  41. data/{lib/locales → locales}/de.yml +4 -4
  42. data/{lib/locales → locales}/en.yml +4 -4
  43. data/{lib/locales → locales}/es.yml +2 -2
  44. data/{lib/locales → locales}/fr.yml +4 -4
  45. data/{lib/locales → locales}/hr.yml +4 -4
  46. data/{lib/locales → locales}/id.yml +4 -4
  47. data/{lib/locales → locales}/it.yml +4 -4
  48. data/{lib/locales → locales}/ja.yml +4 -4
  49. data/{lib/locales → locales}/km.yml +4 -4
  50. data/{lib/locales → locales}/ko.yml +4 -4
  51. data/{lib/locales → locales}/nb.yml +4 -4
  52. data/{lib/locales → locales}/nl.yml +4 -4
  53. data/{lib/locales → locales}/nn.yml +4 -4
  54. data/{lib/locales → locales}/pl.yml +4 -4
  55. data/{lib/locales → locales}/pt-BR.yml +2 -2
  56. data/{lib/locales → locales}/pt.yml +2 -2
  57. data/locales/ru.yml +25 -0
  58. data/{lib/locales → locales}/sr.yml +4 -4
  59. data/{lib/locales → locales}/sv-SE.yml +4 -4
  60. data/{lib/locales → locales}/sv.yml +4 -4
  61. data/{lib/locales → locales}/sw.yml +4 -4
  62. data/{lib/locales → locales}/ta.yml +4 -4
  63. data/{lib/locales → locales}/tr.yml +4 -4
  64. data/{lib/locales → locales}/uk.yml +4 -4
  65. data/{lib/locales → locales}/vi.yml +4 -4
  66. data/{lib/locales → locales}/zh-CN.yml +4 -4
  67. data/{lib/locales → locales}/zh-HK.yml +4 -4
  68. data/{lib/locales → locales}/zh-TW.yml +4 -4
  69. data/pkg/pagy-8.0.1.gem +0 -0
  70. data/{lib/stylesheets → stylesheets}/pagy.css +19 -34
  71. data/{lib/stylesheets → stylesheets}/pagy.scss +17 -19
  72. data/stylesheets/pagy.tailwind.css +21 -0
  73. metadata +65 -51
  74. data/lib/javascripts/pagy-dev.js +0 -112
  75. data/lib/javascripts/pagy.js +0 -1
  76. data/lib/locales/ckb.yml +0 -18
  77. data/lib/locales/ru.yml +0 -27
  78. data/lib/pagy/extras/navs.rb +0 -51
  79. data/lib/pagy/extras/support.rb +0 -40
  80. data/lib/stylesheets/pagy.tailwind.scss +0 -24
  81. /data/{lib/javascripts → javascripts}/pagy-module.d.ts +0 -0
@@ -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_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 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,70 @@ 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
+ JSTools::A_TAG
62
+
63
+ %(<ul#{id} class="pagy-materialize combo-nav-js pagination" role="navigation" style="padding-right: 0;" #{
64
+ nav_aria_label(pagy, aria_label:)} #{
65
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
66
+ }>#{
67
+ materialize_prev_html(pagy, a)
68
+ }<li style="vertical-align: -webkit-baseline-middle;"><label style="font-size: 1.2rem;">#{
69
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
70
+ }</label></li>#{
71
+ materialize_next_html(pagy, a)
72
+ }</ul>)
71
73
  end
72
74
 
73
75
  private
74
76
 
75
- def materialize_prev_html(pagy, link, style = '')
77
+ def materialize_prev_html(pagy, a)
76
78
  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>)
79
+ %(<li class="waves-effect prev">#{
80
+ a.(p_prev, '<i class="material-icons">chevron_left</i>', aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
79
81
  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>)
82
+ %(<li class="prev disabled"><a role="link" aria-disabled="true" aria-label="#{
83
+ pagy_t('pagy.aria_label.prev')}"><i class="material-icons">chevron_left</i></a></li>)
82
84
  end
83
85
  end
84
86
 
85
- def materialize_next_html(pagy, link, style = '')
87
+ def materialize_next_html(pagy, a)
86
88
  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>)
89
+ %(<li class="waves-effect next">#{
90
+ a.(p_next, '<i class="material-icons">chevron_right</i>', aria_label: pagy_t('pagy.aria_label.next'))}</li>)
89
91
  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>)
92
+ %(<li class="next disabled"#><a role="link" aria-disabled="true" aria-label="#{
93
+ pagy_t('pagy.aria_label.next')}><i class="material-icons">chevron_right</i></a></li>)
92
94
  end
93
95
  end
94
96
  end
@@ -1,7 +1,7 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/metadata
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/url_helpers'
4
+ require_relative '../url_helpers'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  DEFAULT[:metadata] = %i[ scaffold_url first_url prev_url page_url next_url last_url
@@ -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_relative '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;">#{JSTools::A_TAG})
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_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 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,65 @@ 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
+ JSTools::A_TAG
58
+
59
+ %(<div#{id} class="pagy-semantic combo-nav-js ui compact menu" role="navigation" #{
60
+ nav_aria_label(pagy, aria_label:)} #{
61
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
62
+ }>#{
63
+ semantic_prev_html(pagy, a)
64
+ }<div class="item"><label>#{
65
+ pagy_t('pagy.combo_nav_js', page_input:, pages:)
66
+ }</label></div> #{
67
+ semantic_next_html(pagy, a)
71
68
  }</div>)
72
69
  end
73
70
 
74
71
  private
75
72
 
76
- def semantic_prev_html(pagy, link)
73
+ def semantic_prev_html(pagy, a)
77
74
  if (p_prev = pagy.prev)
78
- link.call(p_prev, pagy_t('pagy.prev'), %(#{prev_aria_label_attr} class="item"))
75
+ a.(p_prev, pagy_t('pagy.prev'), classes: 'item', aria_label: pagy_t('pagy.aria_label.prev'))
79
76
  else
80
- +%(<div class="item disabled" role="link" aria-disabled="true" #{
81
- prev_aria_label_attr}>#{pagy_t('pagy.prev')}</div>)
77
+ %(<div class="item disabled" role="a" aria-disabled="true" aria-label="#{
78
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</div>)
82
79
  end
83
80
  end
84
81
 
85
- def semantic_next_html(pagy, link)
82
+ def semantic_next_html(pagy, a)
86
83
  if (p_next = pagy.next)
87
- link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="item"))
84
+ a.(p_next, pagy_t('pagy.next'), classes: 'item', aria_label: pagy_t('pagy.aria_label.next'))
88
85
  else
89
- +%(<div class="item disabled" role="link" aria-disabled="true" #{
90
- next_aria_label_attr}>#{pagy_t('pagy.next')}</div>)
86
+ %(<div class="item disabled" role="link" aria-disabled="true" aria=label="#{
87
+ pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.next')}</div>)
91
88
  end
92
89
  end
93
90
  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_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 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;">#{JSTools::A_TAG})
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