pagy 7.0.11 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apps/calendar.ru +2196 -0
- data/lib/apps/demo.ru +452 -0
- data/lib/apps/rails.ru +205 -0
- data/lib/apps/repro.ru +168 -0
- data/lib/bin/pagy +83 -0
- data/lib/config/pagy.rb +6 -17
- data/lib/javascripts/pagy-dev.js +10 -10
- data/lib/javascripts/pagy-module.js +9 -9
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/ar.yml +2 -2
- data/lib/locales/be.yml +4 -4
- data/lib/locales/bg.yml +4 -4
- data/lib/locales/bs.yml +4 -4
- data/lib/locales/ca.yml +4 -4
- data/lib/locales/ckb.yml +4 -4
- data/lib/locales/cs.yml +4 -4
- data/lib/locales/da.yml +4 -4
- data/lib/locales/de.yml +4 -4
- data/lib/locales/en.yml +4 -4
- data/lib/locales/es.yml +2 -2
- data/lib/locales/fr.yml +4 -4
- data/lib/locales/hr.yml +4 -4
- data/lib/locales/id.yml +4 -4
- data/lib/locales/it.yml +4 -4
- data/lib/locales/ja.yml +4 -4
- data/lib/locales/km.yml +4 -4
- data/lib/locales/ko.yml +4 -4
- data/lib/locales/nb.yml +4 -4
- data/lib/locales/nl.yml +4 -4
- data/lib/locales/nn.yml +4 -4
- data/lib/locales/pl.yml +4 -4
- data/lib/locales/pt-BR.yml +2 -2
- data/lib/locales/pt.yml +2 -2
- data/lib/locales/ru.yml +4 -4
- data/lib/locales/sr.yml +4 -4
- data/lib/locales/sv-SE.yml +4 -4
- data/lib/locales/sv.yml +4 -4
- data/lib/locales/sw.yml +4 -4
- data/lib/locales/ta.yml +4 -4
- data/lib/locales/tr.yml +4 -4
- data/lib/locales/uk.yml +4 -4
- data/lib/locales/vi.yml +4 -4
- data/lib/locales/zh-CN.yml +4 -4
- data/lib/locales/zh-HK.yml +4 -4
- data/lib/locales/zh-TW.yml +4 -4
- data/lib/optimist.rb +1022 -0
- data/lib/pagy/extras/bootstrap.rb +52 -63
- data/lib/pagy/extras/bulma.rb +48 -64
- data/lib/pagy/extras/foundation.rb +49 -61
- data/lib/pagy/extras/items.rb +21 -18
- data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +1 -1
- data/lib/pagy/extras/materialize.rb +52 -51
- data/lib/pagy/extras/pagy.rb +82 -0
- data/lib/pagy/extras/semantic.rb +46 -50
- data/lib/pagy/extras/trim.rb +12 -12
- data/lib/pagy/extras/uikit.rb +48 -49
- data/lib/pagy/frontend.rb +31 -48
- data/lib/pagy/url_helpers.rb +1 -2
- data/lib/pagy.rb +10 -9
- data/lib/stylesheets/pagy.css +19 -34
- data/lib/stylesheets/pagy.scss +17 -19
- data/lib/stylesheets/pagy.tailwind.css +21 -0
- metadata +25 -9
- data/lib/pagy/extras/navs.rb +0 -51
- data/lib/pagy/extras/support.rb +0 -40
- 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/
|
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,
|
12
|
-
|
13
|
-
|
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#{
|
17
|
-
|
18
|
-
|
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">#{
|
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,
|
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
|
36
|
-
def pagy_materialize_nav_js(pagy,
|
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
|
-
|
40
|
-
|
36
|
+
id = %( id="#{id}") if id
|
37
|
+
a = pagy_anchor(pagy)
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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#{
|
49
|
-
|
50
|
-
pagy_data(pagy, :nav,
|
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
|
54
|
-
def pagy_materialize_combo_nav_js(pagy,
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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,
|
76
|
+
def materialize_prev_html(pagy, a)
|
76
77
|
if (p_prev = pagy.prev)
|
77
|
-
%(<li class="waves-effect prev"
|
78
|
-
|
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"
|
81
|
-
|
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,
|
86
|
+
def materialize_next_html(pagy, a)
|
86
87
|
if (p_next = pagy.next)
|
87
|
-
%(<li class="waves-effect next"
|
88
|
-
|
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"
|
91
|
-
|
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
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -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/
|
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,
|
12
|
-
|
13
|
-
|
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 =
|
17
|
-
|
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
|
-
|
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,
|
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
|
36
|
-
def pagy_semantic_nav_js(pagy,
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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#{
|
48
|
-
|
49
|
-
pagy_data(pagy, :nav,
|
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
|
53
|
-
def pagy_semantic_combo_nav_js(pagy,
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
%(<
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
|
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,
|
72
|
+
def semantic_prev_html(pagy, a)
|
77
73
|
if (p_prev = pagy.prev)
|
78
|
-
|
74
|
+
a.(p_prev, pagy_t('pagy.prev'), classes: 'item', aria_label: pagy_t('pagy.aria_label.prev'))
|
79
75
|
else
|
80
|
-
|
81
|
-
|
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,
|
81
|
+
def semantic_next_html(pagy, a)
|
86
82
|
if (p_next = pagy.next)
|
87
|
-
|
83
|
+
a.(p_next, pagy_t('pagy.next'), classes: 'item', aria_label: pagy_t('pagy.aria_label.next'))
|
88
84
|
else
|
89
|
-
|
90
|
-
|
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
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -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
|
10
|
-
# Call the pagy_trim method if the trim_extra is enabled
|
11
|
-
def
|
12
|
-
|
13
|
-
return
|
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),
|
16
|
-
|
17
|
-
return
|
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,
|
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
|
24
|
-
def pagy_trim(pagy,
|
25
|
-
|
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
|
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -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/
|
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,
|
12
|
-
|
13
|
-
|
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 =
|
17
|
-
|
18
|
-
|
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>#{
|
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,
|
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
|
37
|
-
def pagy_uikit_nav_js(pagy,
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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#{
|
50
|
-
|
51
|
-
pagy_data(pagy, :nav,
|
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
|
55
|
-
def pagy_uikit_combo_nav_js(pagy,
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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#{
|
65
|
-
|
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
|
69
|
-
}<li>#{
|
70
|
-
pagy_t
|
71
|
-
}</li>#{
|
72
|
-
uikit_next_html
|
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,
|
79
|
-
|
75
|
+
def uikit_prev_html(pagy, a)
|
76
|
+
span = %(<span uk-pagination-previous></span>)
|
80
77
|
if (p_prev = pagy.prev)
|
81
|
-
%(<li>#{
|
78
|
+
%(<li>#{a.(p_prev, span, aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
|
82
79
|
else
|
83
|
-
%(<li class="uk-disabled"><
|
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,
|
88
|
-
|
85
|
+
def uikit_next_html(pagy, a)
|
86
|
+
span = %(<span uk-pagination-next></span>)
|
89
87
|
if (p_next = pagy.next)
|
90
|
-
%(<li>#{
|
88
|
+
%(<li>#{a.(p_next, span, aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
|
91
89
|
else
|
92
|
-
%(<li class="uk-disabled"><
|
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
|