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,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/
|
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,
|
12
|
-
|
13
|
-
|
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 =
|
17
|
-
|
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">#{
|
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
|
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,
|
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
|
37
|
-
def pagy_bootstrap_nav_js(pagy,
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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#{
|
51
|
-
|
52
|
-
pagy_data(pagy, :nav,
|
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
|
57
|
-
def pagy_bootstrap_combo_nav_js(pagy,
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
%(<
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}<
|
77
|
-
pagy_t
|
78
|
-
|
79
|
-
|
80
|
-
|
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,
|
76
|
+
def bootstrap_prev_html(pagy, a)
|
90
77
|
if (p_prev = pagy.prev)
|
91
|
-
%(<li class="page-item prev">#{
|
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
|
-
|
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,
|
86
|
+
def bootstrap_next_html(pagy, a)
|
99
87
|
if (p_next = pagy.next)
|
100
|
-
%(<li class="page-item next">#{
|
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
|
-
|
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
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -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/
|
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,
|
14
|
-
|
15
|
-
|
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 =
|
19
|
-
|
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>#{
|
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
|
38
|
-
def pagy_bulma_nav_js(pagy,
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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#{
|
51
|
-
|
52
|
-
|
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
|
56
|
-
def pagy_bulma_combo_nav_js(pagy,
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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,
|
90
|
-
html =
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
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
|
-
|
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/
|
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,
|
12
|
-
|
13
|
-
|
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#{
|
17
|
-
|
18
|
-
|
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>#{
|
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 <<
|
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
|
36
|
-
def pagy_foundation_nav_js(pagy,
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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#{
|
48
|
-
|
49
|
-
pagy_data(pagy, :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
|
53
|
-
def pagy_foundation_combo_nav_js(pagy,
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
%(<
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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,
|
74
|
+
def foundation_prev_html(pagy, a)
|
89
75
|
if (p_prev = pagy.prev)
|
90
|
-
%(<li class="prev">#{
|
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" #{
|
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
|
83
|
+
def foundation_next_html(pagy, a)
|
97
84
|
if (p_next = pagy.next)
|
98
|
-
%(<li class="next">#{
|
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" #{
|
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
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -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/
|
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
|
-
|
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,
|
39
|
+
def pagy_items_selector_js(pagy, id: nil, item_name: nil)
|
40
40
|
return '' unless pagy.vars[:items_extra]
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
url_token
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
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.
|