pagy 7.0.11 → 8.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apps/calendar.ru +745 -0
- data/apps/demo.ru +435 -0
- data/apps/rails.ru +212 -0
- data/apps/repro.ru +177 -0
- data/apps/tmp/calendar.sqlite3 +0 -0
- data/apps/tmp/calendar.sqlite3-shm +0 -0
- data/apps/tmp/calendar.sqlite3-wal +0 -0
- data/apps/tmp/local_secret.txt +1 -0
- data/apps/tmp/pagy-keyset.sqlite3 +0 -0
- data/apps/tmp/pagy-keyset.sqlite3-shm +0 -0
- data/apps/tmp/pagy-keyset.sqlite3-wal +0 -0
- data/bin/pagy +100 -0
- data/{lib/config → config}/pagy.rb +31 -73
- data/javascripts/pagy-module.js +100 -0
- data/javascripts/pagy.js +4 -0
- data/javascripts/pagy.min.js +4 -0
- data/javascripts/pagy.min.js.map +10 -0
- data/javascripts/pagy.mjs +100 -0
- data/lib/optimist.rb +1022 -0
- data/lib/pagy/backend.rb +8 -3
- data/lib/pagy/calendar/day.rb +4 -3
- data/lib/pagy/calendar/month.rb +4 -3
- data/lib/pagy/calendar/quarter.rb +4 -3
- data/lib/pagy/calendar/unit.rb +106 -0
- data/lib/pagy/calendar/week.rb +3 -3
- data/lib/pagy/calendar/year.rb +4 -3
- data/lib/pagy/calendar.rb +55 -99
- data/lib/pagy/console.rb +2 -2
- data/lib/pagy/countless.rb +15 -10
- data/lib/pagy/extras/arel.rb +1 -1
- data/lib/pagy/extras/array.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +52 -63
- data/lib/pagy/extras/bulma.rb +49 -64
- data/lib/pagy/extras/calendar.rb +35 -5
- data/lib/pagy/extras/countless.rb +2 -2
- data/lib/pagy/extras/foundation.rb +52 -62
- data/lib/pagy/extras/gearbox.rb +28 -27
- data/lib/pagy/extras/headers.rb +1 -1
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/items.rb +21 -18
- data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +9 -6
- data/lib/pagy/extras/jsonapi.rb +2 -2
- data/lib/pagy/extras/materialize.rb +56 -52
- data/lib/pagy/extras/metadata.rb +6 -2
- data/lib/pagy/extras/overflow.rb +5 -4
- data/lib/pagy/extras/pagy.rb +82 -0
- data/lib/pagy/extras/semantic.rb +50 -51
- data/lib/pagy/extras/size.rb +40 -0
- data/lib/pagy/extras/standalone.rb +2 -2
- data/lib/pagy/extras/trim.rb +12 -12
- data/lib/pagy/extras/uikit.rb +51 -50
- data/lib/pagy/frontend.rb +39 -53
- data/lib/pagy/url_helpers.rb +9 -10
- data/lib/pagy.rb +51 -82
- data/{lib/locales → locales}/ar.yml +10 -11
- data/{lib/locales → locales}/be.yml +5 -5
- data/{lib/locales → locales}/bg.yml +5 -5
- data/{lib/locales → locales}/bs.yml +5 -5
- data/locales/ca.yml +21 -0
- data/locales/ckb.yml +18 -0
- data/{lib/locales → locales}/cs.yml +5 -5
- data/locales/da.yml +21 -0
- data/{lib/locales → locales}/de.yml +5 -5
- data/{lib/locales → locales}/en.yml +5 -5
- data/{lib/locales → locales}/es.yml +3 -3
- data/{lib/locales → locales}/fr.yml +5 -5
- data/{lib/locales → locales}/hr.yml +5 -5
- data/{lib/locales → locales}/id.yml +5 -5
- data/{lib/locales → locales}/it.yml +5 -5
- data/{lib/locales → locales}/ja.yml +5 -5
- data/{lib/locales → locales}/km.yml +5 -5
- data/locales/ko.yml +17 -0
- data/{lib/locales → locales}/nb.yml +5 -5
- data/{lib/locales → locales}/nl.yml +5 -5
- data/{lib/locales → locales}/nn.yml +5 -5
- data/{lib/locales → locales}/pl.yml +5 -5
- data/{lib/locales → locales}/pt-BR.yml +3 -3
- data/{lib/locales → locales}/pt.yml +3 -3
- data/locales/ru.yml +25 -0
- data/{lib/locales → locales}/sr.yml +5 -5
- data/{lib/locales → locales}/sv-SE.yml +5 -5
- data/{lib/locales → locales}/sv.yml +5 -5
- data/{lib/locales → locales}/sw.yml +5 -5
- data/{lib/locales → locales}/ta.yml +5 -5
- data/{lib/locales → locales}/tr.yml +5 -5
- data/{lib/locales → locales}/uk.yml +5 -5
- data/locales/vi.yml +17 -0
- data/{lib/locales → locales}/zh-CN.yml +5 -5
- data/{lib/locales → locales}/zh-HK.yml +5 -5
- data/{lib/locales → locales}/zh-TW.yml +5 -5
- data/{lib/stylesheets → stylesheets}/pagy.css +19 -34
- data/{lib/stylesheets → stylesheets}/pagy.scss +17 -19
- data/stylesheets/pagy.tailwind.css +21 -0
- metadata +76 -53
- data/lib/javascripts/pagy-dev.js +0 -112
- data/lib/javascripts/pagy-module.js +0 -111
- data/lib/javascripts/pagy.js +0 -1
- data/lib/locales/ca.yml +0 -23
- data/lib/locales/ckb.yml +0 -18
- data/lib/locales/da.yml +0 -23
- data/lib/locales/ko.yml +0 -19
- data/lib/locales/ru.yml +0 -27
- data/lib/locales/vi.yml +0 -17
- data/lib/pagy/calendar/helper.rb +0 -65
- data/lib/pagy/extras/navs.rb +0 -51
- data/lib/pagy/extras/support.rb +0 -40
- data/lib/stylesheets/pagy.tailwind.scss +0 -24
- /data/{lib/javascripts/pagy-module.d.ts → javascripts/pagy.d.ts} +0 -0
@@ -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
|
-
|
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 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">#{JSTools::A_TAG})
|
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
|
-
|
4
|
+
require_relative '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,59 @@ 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
|
-
|
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; ) <<
|
60
|
+
%(background-color: #485fc7;">#{JSTools::A_TAG})
|
65
61
|
|
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>)
|
62
|
+
%(<nav#{id} class="#{classes}" #{
|
63
|
+
nav_aria_label(pagy, aria_label:)} #{
|
64
|
+
pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
|
65
|
+
}>#{
|
66
|
+
bulma_prev_next_html(pagy, a)
|
67
|
+
}<ul class="pagination-list"><li class="pagination-link"><label>#{
|
68
|
+
pagy_t('pagy.combo_nav_js', page_input:, pages:)
|
69
|
+
}</label></li></ul></nav>)
|
85
70
|
end
|
86
71
|
|
87
72
|
private
|
88
73
|
|
89
|
-
def bulma_prev_next_html(pagy,
|
90
|
-
html =
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
74
|
+
def bulma_prev_next_html(pagy, a)
|
75
|
+
html = if (p_prev = pagy.prev)
|
76
|
+
a.(p_prev, pagy_t('pagy.prev'), classes: 'pagination-previous', aria_label: pagy_t('pagy.aria_label.prev'))
|
77
|
+
else
|
78
|
+
%(<a role="link" class="pagination-previous" disabled aria-disabled="true" aria-label="#{
|
79
|
+
pagy_t('pagy.aria_label.prev')}">#{pagy_t 'pagy.prev'}</a>)
|
80
|
+
end
|
96
81
|
html << if (p_next = pagy.next)
|
97
|
-
|
82
|
+
a.(p_next, pagy_t('pagy.next'), classes: 'pagination-next', aria_label: pagy_t('pagy.aria_label.next'))
|
98
83
|
else
|
99
|
-
%(<a role="link" class="pagination-next" disabled aria-disabled="true" #{
|
100
|
-
|
84
|
+
%(<a role="link" class="pagination-next" disabled aria-disabled="true" aria-label="#{
|
85
|
+
pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</a>)
|
101
86
|
end
|
102
87
|
end
|
103
88
|
end
|
data/lib/pagy/extras/calendar.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/calendar
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
require 'pagy/calendar/helper'
|
4
|
+
require_relative '../calendar'
|
6
5
|
|
7
6
|
class Pagy # :nodoc:
|
8
7
|
# Add pagination filtering by calendar unit (:year, :quarter, :month, :week, :day) to the regular pagination
|
@@ -20,8 +19,13 @@ class Pagy # :nodoc:
|
|
20
19
|
|
21
20
|
conf[:pagy] ||= {}
|
22
21
|
unless conf.key?(:active) && !conf[:active]
|
23
|
-
calendar, from, to = Calendar
|
24
|
-
|
22
|
+
calendar, from, to = Calendar.send(:init, conf, pagy_calendar_period(collection), params)
|
23
|
+
if respond_to?(:pagy_calendar_counts)
|
24
|
+
calendar.each_key do |unit|
|
25
|
+
calendar[unit].vars[:counts] = pagy_calendar_counts(collection, unit, *calendar[unit].vars[:period])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
collection = pagy_calendar_filter(collection, from, to)
|
25
29
|
end
|
26
30
|
pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
|
27
31
|
[calendar, pagy, results]
|
@@ -40,6 +44,32 @@ class Pagy # :nodoc:
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
47
|
+
# Override the pagy_anchor
|
48
|
+
module FrontendOverride
|
49
|
+
# Consider the vars[:count]
|
50
|
+
def pagy_anchor(pagy)
|
51
|
+
return super unless (counts = pagy.vars[:counts])
|
52
|
+
|
53
|
+
a_string = pagy.vars[:anchor_string]
|
54
|
+
a_string = %( #{a_string}) if a_string
|
55
|
+
left, right = %(<a#{a_string} href="#{pagy_url_for(pagy, PAGE_TOKEN)}").split(PAGE_TOKEN, 2)
|
56
|
+
# lambda used by all the helpers
|
57
|
+
lambda do |page, text = pagy.label_for(page), classes: nil, aria_label: nil|
|
58
|
+
count = counts[page - 1]
|
59
|
+
item_name = pagy_t('pagy.item_name', count:)
|
60
|
+
if count.zero?
|
61
|
+
classes = "#{classes && (classes + ' ')}empty-page"
|
62
|
+
title = %( title="#{pagy_t('pagy.info.no_items', item_name:, count:)}")
|
63
|
+
else
|
64
|
+
title = %( title="#{pagy_t('pagy.info.single_page', item_name:, count:)}")
|
65
|
+
end
|
66
|
+
classes = %( class="#{classes}") if classes
|
67
|
+
aria_label = %( aria-label="#{aria_label}") if aria_label
|
68
|
+
%(#{left}#{page}#{right}#{title}#{classes}#{aria_label}>#{text}</a>)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
43
73
|
# Additions for the Frontend module
|
44
74
|
module UrlHelperAddOn
|
45
75
|
# Return the url for the calendar page at time
|
@@ -49,5 +79,5 @@ class Pagy # :nodoc:
|
|
49
79
|
end
|
50
80
|
end
|
51
81
|
Backend.prepend CalendarExtra::BackendAddOn, CalendarExtra::UrlHelperAddOn
|
52
|
-
Frontend.prepend CalendarExtra::UrlHelperAddOn
|
82
|
+
Frontend.prepend CalendarExtra::UrlHelperAddOn, CalendarExtra::FrontendOverride
|
53
83
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/countless
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require_relative '../countless'
|
5
5
|
|
6
6
|
class Pagy # :nodoc:
|
7
7
|
DEFAULT[:countless_minimal] = false
|
@@ -19,7 +19,7 @@ class Pagy # :nodoc:
|
|
19
19
|
# Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
|
20
20
|
def pagy_countless_get_vars(_collection, vars)
|
21
21
|
pagy_set_items_from_params(vars) if defined?(ItemsExtra)
|
22
|
-
vars[:page] ||=
|
22
|
+
vars[:page] ||= pagy_get_page(vars)
|
23
23
|
vars
|
24
24
|
end
|
25
25
|
|
@@ -1,25 +1,26 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/foundation
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
warn '[PAGY WARNING] The foundation extra has been discontinued and it will be removed in v9 ' \
|
4
|
+
'(https://github.com/ddnexus/pagy/discussions/672#discussioncomment-9212328)'
|
5
|
+
|
6
|
+
require_relative 'js_tools'
|
5
7
|
|
6
8
|
class Pagy # :nodoc:
|
7
9
|
# Frontend modules are specially optimized for performance.
|
8
10
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
11
|
module FoundationExtra
|
10
12
|
# 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:)
|
13
|
+
def pagy_foundation_nav(pagy, id: nil, aria_label: nil, **vars)
|
14
|
+
id = %( id="#{id}") if id
|
15
|
+
a = pagy_anchor(pagy)
|
15
16
|
|
16
|
-
html = +%(<nav#{
|
17
|
-
|
18
|
-
|
17
|
+
html = +%(<nav#{id} class="pagy-foundation-nav" #{
|
18
|
+
nav_aria_label(pagy, aria_label:)}><ul class="pagination"> #{
|
19
|
+
foundation_prev_html(pagy, a)})
|
19
20
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
20
21
|
html << case item
|
21
22
|
when Integer
|
22
|
-
%(<li>#{
|
23
|
+
%(<li>#{a.(item)}</li>)
|
23
24
|
when String
|
24
25
|
%(<li class="current" role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</li>)
|
25
26
|
when :gap
|
@@ -28,76 +29,65 @@ class Pagy # :nodoc:
|
|
28
29
|
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
29
30
|
end
|
30
31
|
end
|
31
|
-
html <<
|
32
|
-
html << %(</ul></nav>)
|
32
|
+
html << %(#{foundation_next_html(pagy, a)}</ul></nav>)
|
33
33
|
end
|
34
34
|
|
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)
|
35
|
+
# Javascript pagination for foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
|
36
|
+
def pagy_foundation_nav_js(pagy, id: nil, aria_label: nil, **vars)
|
38
37
|
sequels = pagy.sequels(**vars)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
id = %( id="#{id}") if id
|
39
|
+
a = pagy_anchor(pagy)
|
40
|
+
tokens = { 'before' => %(<ul class="pagination">#{foundation_prev_html pagy, a}),
|
41
|
+
'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN)}</li>),
|
42
|
+
'current' => %(<li class="current" role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</li>),
|
43
|
+
'gap' => %(<li class="ellipsis gap"></li>),
|
44
|
+
'after' => %(#{foundation_next_html pagy, a}</ul>) }
|
46
45
|
|
47
|
-
%(<nav#{
|
48
|
-
|
49
|
-
pagy_data(pagy, :nav,
|
46
|
+
%(<nav#{id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-foundation-nav-js" #{
|
47
|
+
nav_aria_label(pagy, aria_label:)} #{
|
48
|
+
pagy_data(pagy, :nav, tokens, sequels, pagy.label_sequels(sequels))
|
49
|
+
}></nav>)
|
50
50
|
end
|
51
51
|
|
52
|
-
# Javascript combo pagination for Foundation: it returns a nav
|
53
|
-
def pagy_foundation_combo_nav_js(pagy,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
p_pages.to_s.length + 1}rem; padding: 0 0.3rem; margin: 0 0.3rem;" aria-current="page">)
|
52
|
+
# Javascript combo pagination for Foundation: it returns a nav with a data-pagy attribute used by the pagy.js file
|
53
|
+
def pagy_foundation_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; ) <<
|
60
|
+
%(height: 1.5rem; padding: .5rem; margin: 0 .4rem; font-size: .875rem;" class="current">#{JSTools::A_TAG})
|
62
61
|
|
63
|
-
%(<nav#{
|
64
|
-
|
65
|
-
pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}#{
|
74
|
-
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
|
75
|
-
.sub!('<label>', '<label class="input-group-label">')}#{ # add the class to the official dictionary string
|
76
|
-
if (p_next = pagy.next)
|
77
|
-
link.call(p_next, pagy_t('pagy.next'),
|
78
|
-
%(style="margin-bottom: 0" class="next button primary" #{next_aria_label_attr}))
|
79
|
-
else
|
80
|
-
%(<a style="margin-bottom: 0" class="next button primary disabled" role="link" aria-disabled="true" #{
|
81
|
-
next_aria_label_attr}>#{pagy_t 'pagy.next'}</a>)
|
82
|
-
end
|
83
|
-
}</div></nav>)
|
62
|
+
%(<nav#{id} class="pagy-foundation-combo-nav-js" #{
|
63
|
+
nav_aria_label(pagy, aria_label:)} #{
|
64
|
+
pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
|
65
|
+
}><ul class="pagination">#{
|
66
|
+
foundation_prev_html(pagy, a)
|
67
|
+
}<li style="padding: 0 .3rem"><label style="display: flex; align-items: center; white-space: nowrap">#{
|
68
|
+
pagy_t('pagy.combo_nav_js', page_input:, pages:)
|
69
|
+
}</label></li>#{
|
70
|
+
foundation_next_html(pagy, a)
|
71
|
+
}</ul></nav>)
|
84
72
|
end
|
85
73
|
|
86
74
|
private
|
87
75
|
|
88
|
-
def foundation_prev_html(pagy,
|
76
|
+
def foundation_prev_html(pagy, a)
|
89
77
|
if (p_prev = pagy.prev)
|
90
|
-
%(<li class="prev">#{
|
78
|
+
%(<li class="prev">#{a.(p_prev, pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))}</li>)
|
91
79
|
else
|
92
|
-
%(<li class="prev disabled" role="link" aria-disabled="true" #{
|
80
|
+
%(<li class="prev disabled" role="link" aria-disabled="true" aria-label="#{
|
81
|
+
pagy_t('pagy.aria_label.prev')}">#{pagy_t('pagy.prev')}</li>)
|
93
82
|
end
|
94
83
|
end
|
95
84
|
|
96
|
-
def
|
85
|
+
def foundation_next_html(pagy, a)
|
97
86
|
if (p_next = pagy.next)
|
98
|
-
%(<li class="next">#{
|
87
|
+
%(<li class="next">#{a.(p_next, pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.next'))}</li>)
|
99
88
|
else
|
100
|
-
%(<li class="next disabled" role="link" aria-disabled="true" #{
|
89
|
+
%(<li class="next disabled" role="link" aria-disabled="true" aria-label="#{
|
90
|
+
pagy_t('pagy.aria_label.next')}">#{pagy_t('pagy.next')}</li>)
|
101
91
|
end
|
102
92
|
end
|
103
93
|
end
|