pagy 6.5.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/config/pagy.rb +18 -16
- data/lib/javascripts/pagy-dev.js +3 -3
- data/lib/javascripts/pagy-module.js +2 -2
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/ar.yml +14 -10
- data/lib/locales/be.yml +11 -10
- data/lib/locales/bg.yml +9 -10
- data/lib/locales/bs.yml +11 -10
- data/lib/locales/ca.yml +11 -10
- data/lib/locales/cs.yml +12 -9
- data/lib/locales/da.yml +11 -10
- data/lib/locales/de.yml +9 -10
- data/lib/locales/en.yml +9 -10
- data/lib/locales/es.yml +9 -10
- data/lib/locales/fr.yml +9 -10
- data/lib/locales/hr.yml +11 -10
- data/lib/locales/id.yml +9 -10
- data/lib/locales/it.yml +9 -10
- data/lib/locales/ja.yml +9 -10
- data/lib/locales/km.yml +9 -9
- data/lib/locales/ko.yml +9 -10
- data/lib/locales/nb.yml +9 -10
- data/lib/locales/nl.yml +9 -10
- data/lib/locales/nn.yml +9 -10
- data/lib/locales/pl.yml +11 -10
- data/lib/locales/pt-BR.yml +9 -10
- data/lib/locales/pt.yml +9 -10
- data/lib/locales/ru.yml +13 -10
- data/lib/locales/sr.yml +11 -9
- data/lib/locales/sv-SE.yml +10 -12
- data/lib/locales/sv.yml +10 -12
- data/lib/locales/sw.yml +11 -10
- data/lib/locales/ta.yml +11 -10
- data/lib/locales/tr.yml +9 -10
- data/lib/locales/uk.yml +11 -10
- data/lib/locales/vi.yml +7 -10
- data/lib/locales/zh-CN.yml +9 -10
- data/lib/locales/zh-HK.yml +9 -10
- data/lib/locales/zh-TW.yml +9 -10
- data/lib/pagy/backend.rb +2 -2
- data/lib/pagy/calendar/day.rb +3 -2
- data/lib/pagy/calendar/helper.rb +3 -7
- data/lib/pagy/calendar/month.rb +3 -2
- data/lib/pagy/calendar/quarter.rb +3 -2
- data/lib/pagy/calendar/year.rb +2 -1
- data/lib/pagy/extras/bootstrap.rb +42 -29
- data/lib/pagy/extras/bulma.rb +40 -31
- data/lib/pagy/extras/calendar.rb +7 -8
- data/lib/pagy/extras/elasticsearch_rails.rb +6 -6
- data/lib/pagy/extras/foundation.rb +44 -31
- data/lib/pagy/extras/frontend_helpers.rb +7 -7
- data/lib/pagy/extras/headers.rb +7 -7
- data/lib/pagy/extras/i18n.rb +4 -4
- data/lib/pagy/extras/items.rb +10 -9
- data/lib/pagy/extras/jsonapi.rb +2 -7
- data/lib/pagy/extras/materialize.rb +41 -29
- data/lib/pagy/extras/meilisearch.rb +7 -7
- data/lib/pagy/extras/metadata.rb +1 -1
- data/lib/pagy/extras/navs.rb +21 -33
- data/lib/pagy/extras/overflow.rb +7 -5
- data/lib/pagy/extras/searchkick.rb +6 -6
- data/lib/pagy/extras/semantic.rb +40 -27
- data/lib/pagy/extras/standalone.rb +4 -7
- data/lib/pagy/extras/support.rb +18 -32
- data/lib/pagy/extras/trim.rb +2 -2
- data/lib/pagy/extras/uikit.rb +43 -30
- data/lib/pagy/frontend.rb +56 -25
- data/lib/pagy/i18n.rb +0 -3
- data/lib/pagy/url_helpers.rb +1 -2
- data/lib/pagy.rb +16 -14
- metadata +6 -22
- data/lib/locales/ckb.yml +0 -20
- data/lib/templates/bootstrap_nav.html.erb +0 -24
- data/lib/templates/bootstrap_nav.html.haml +0 -34
- data/lib/templates/bootstrap_nav.html.slim +0 -34
- data/lib/templates/bulma_nav.html.erb +0 -24
- data/lib/templates/bulma_nav.html.haml +0 -32
- data/lib/templates/bulma_nav.html.slim +0 -32
- data/lib/templates/foundation_nav.html.erb +0 -24
- data/lib/templates/foundation_nav.html.haml +0 -34
- data/lib/templates/foundation_nav.html.slim +0 -34
- data/lib/templates/nav.html.erb +0 -22
- data/lib/templates/nav.html.haml +0 -30
- data/lib/templates/nav.html.slim +0 -29
- data/lib/templates/uikit_nav.html.erb +0 -15
- data/lib/templates/uikit_nav.html.haml +0 -28
- data/lib/templates/uikit_nav.html.slim +0 -28
data/lib/locales/zh-CN.yml
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
|
2
|
-
|
3
2
|
zh-CN:
|
4
3
|
pagy:
|
5
|
-
|
4
|
+
aria_label:
|
5
|
+
# please add a comment in the https://github.com/ddnexus/pagy/issues/608
|
6
|
+
# posting the translation of the following "Page"/"Pages" with the plurals for this locale
|
7
|
+
nav: "Pages"
|
8
|
+
prev: "上一页"
|
9
|
+
next: "下一页"
|
10
|
+
prev: "<"
|
11
|
+
next: ">"
|
12
|
+
gap: "…"
|
6
13
|
item_name: ""
|
7
|
-
|
8
|
-
nav:
|
9
|
-
prev: "‹ 上一页"
|
10
|
-
next: "下一页 ›"
|
11
|
-
gap: "…"
|
12
|
-
|
13
14
|
info:
|
14
15
|
no_items: "项目未找到"
|
15
16
|
single_page: "显示<b>%{count}</b> 项%{item_name}"
|
16
17
|
multiple_pages: "共 <b>%{count}</b> 项%{item_name},显示 <b>%{from}-%{to}</b>"
|
17
|
-
|
18
18
|
combo_nav_js: "<label>第 %{page_input} / %{pages} 页</label>"
|
19
|
-
|
20
19
|
items_selector_js: "<label>每页显示 %{items_input} 条%</label>"
|
data/lib/locales/zh-HK.yml
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
|
2
|
-
|
3
2
|
zh-HK:
|
4
3
|
pagy:
|
5
|
-
|
4
|
+
aria_label:
|
5
|
+
# please add a comment in the https://github.com/ddnexus/pagy/issues/609
|
6
|
+
# posting the translation of the following "Page"/"Pages" with the plurals for this locale
|
7
|
+
nav: "Pages"
|
8
|
+
prev: "上一頁"
|
9
|
+
next: "下一頁"
|
10
|
+
prev: "<"
|
11
|
+
next: ">"
|
12
|
+
gap: "…"
|
6
13
|
item_name: ""
|
7
|
-
|
8
|
-
nav:
|
9
|
-
prev: "‹ 上一頁"
|
10
|
-
next: "下一頁 ›"
|
11
|
-
gap: "…"
|
12
|
-
|
13
14
|
info:
|
14
15
|
no_items: "記錄未搵到"
|
15
16
|
single_page: "顯示 <b>%{count}</b> %{item_name}"
|
16
17
|
multiple_pages: "共 <b>%{count}</b> %{item_name},顯示 <b>%{from}-%{to}</b>"
|
17
|
-
|
18
18
|
combo_nav_js: "<label>第 %{page_input} / %{pages} 頁</label>"
|
19
|
-
|
20
19
|
items_selector_js: "<label>每頁顯示 %{items_input} 記錄</label>"
|
data/lib/locales/zh-TW.yml
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
|
2
|
-
|
3
2
|
zh-TW:
|
4
3
|
pagy:
|
5
|
-
|
4
|
+
aria_label:
|
5
|
+
# please add a comment in the https://github.com/ddnexus/pagy/issues/610
|
6
|
+
# posting the translation of the following "Page"/"Pages" with the plurals for this locale
|
7
|
+
nav: "Pages"
|
8
|
+
prev: "上一頁"
|
9
|
+
next: "下一頁"
|
10
|
+
prev: "<"
|
11
|
+
next: ">"
|
12
|
+
gap: "…"
|
6
13
|
item_name: ""
|
7
|
-
|
8
|
-
nav:
|
9
|
-
prev: "‹ 上一頁"
|
10
|
-
next: "下一頁 ›"
|
11
|
-
gap: "…"
|
12
|
-
|
13
14
|
info:
|
14
15
|
no_items: "沒找到項"
|
15
16
|
single_page: "顯示 <b>%{count}</b> 項%{item_name}"
|
16
17
|
multiple_pages: "共 <b>%{count}</b> 項%{item_name},顯示 <b>%{from}-%{to}</b>"
|
17
|
-
|
18
18
|
combo_nav_js: "<label>第 %{page_input} / %{pages} 頁</label>"
|
19
|
-
|
20
19
|
items_selector_js: "<label>每頁顯示 %{items_input} 項%{item_name}</label>"
|
data/lib/pagy/backend.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
class Pagy
|
5
|
-
# Define a few generic methods to paginate
|
5
|
+
# Define a few generic methods to paginate a collection out of the box,
|
6
6
|
# or any collection by overriding pagy_get_items and/or pagy_get_vars in your controller
|
7
7
|
# See also the extras if you need specialized methods to paginate Arrays or other collections
|
8
8
|
module Backend
|
@@ -18,7 +18,7 @@ class Pagy
|
|
18
18
|
# You may need to override the count call for non AR collections
|
19
19
|
def pagy_get_vars(collection, vars)
|
20
20
|
pagy_set_items_from_params(vars) if defined?(ItemsExtra)
|
21
|
-
vars[:count] ||= (count = collection.count(:
|
21
|
+
vars[:count] ||= (count = collection.count(*vars[:count_args])).is_a?(Hash) ? count.size : count
|
22
22
|
vars[:page] ||= pagy_get_page(vars)
|
23
23
|
vars
|
24
24
|
end
|
data/lib/pagy/calendar/day.rb
CHANGED
@@ -5,8 +5,9 @@ class Pagy # :nodoc:
|
|
5
5
|
class Calendar # :nodoc:
|
6
6
|
# Calendar day subclass
|
7
7
|
class Day < Calendar
|
8
|
-
DEFAULT = {
|
9
|
-
|
8
|
+
DEFAULT = { size: 31, # rubocop:disable Style/MutableConstant
|
9
|
+
order: :asc,
|
10
|
+
format: '%d' }
|
10
11
|
|
11
12
|
protected
|
12
13
|
|
data/lib/pagy/calendar/helper.rb
CHANGED
@@ -17,13 +17,13 @@ class Pagy # :nodoc:
|
|
17
17
|
|
18
18
|
# Create the calendar
|
19
19
|
def init(conf, period, params)
|
20
|
-
@
|
20
|
+
@conf = Marshal.load(Marshal.dump(conf)) # store a copy
|
21
|
+
@units = Calendar::UNITS & @conf.keys # get the units in time length desc order
|
21
22
|
raise ArgumentError, 'no calendar unit found in pagy_calendar @configuration' if @units.empty?
|
22
23
|
|
23
24
|
@period = period
|
24
25
|
@params = params
|
25
26
|
@page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
|
26
|
-
@conf = Marshal.load(Marshal.dump(conf)) # store a copy
|
27
27
|
@units.each do |unit| # set all the :page_param vars for later deletion
|
28
28
|
unit_page_param = :"#{unit}_#{@page_param}"
|
29
29
|
conf[unit][:page_param] = unit_page_param
|
@@ -33,11 +33,7 @@ class Pagy # :nodoc:
|
|
33
33
|
object = nil
|
34
34
|
@units.each_with_index do |unit, index|
|
35
35
|
params_to_delete = @units[(index + 1), @units.size].map { |sub| conf[sub][:page_param] } + [@page_param]
|
36
|
-
conf[unit][:params] = lambda
|
37
|
-
# Hash#except missing from ruby 2.5 baseline
|
38
|
-
params_to_delete.each { |p| unit_params.delete(p.to_s) }
|
39
|
-
unit_params
|
40
|
-
end
|
36
|
+
conf[unit][:params] = lambda { |up| up.except(*params_to_delete.map(&:to_s)) } # rubocop:disable Style/Lambda
|
41
37
|
conf[unit][:period] = object&.send(:active_period) || @period
|
42
38
|
calendar[unit] = object = Calendar.send(:create, unit, conf[unit])
|
43
39
|
end
|
data/lib/pagy/calendar/month.rb
CHANGED
@@ -5,8 +5,9 @@ class Pagy # :nodoc:
|
|
5
5
|
class Calendar # :nodoc:
|
6
6
|
# Calendar month subclass
|
7
7
|
class Month < Calendar
|
8
|
-
DEFAULT = {
|
9
|
-
|
8
|
+
DEFAULT = { size: 12, # rubocop:disable Style/MutableConstant
|
9
|
+
order: :asc,
|
10
|
+
format: '%b' }
|
10
11
|
|
11
12
|
protected
|
12
13
|
|
@@ -5,8 +5,9 @@ class Pagy # :nodoc:
|
|
5
5
|
class Calendar # :nodoc:
|
6
6
|
# Calendar quarter subclass
|
7
7
|
class Quarter < Calendar
|
8
|
-
DEFAULT = {
|
9
|
-
|
8
|
+
DEFAULT = { size: 4, # rubocop:disable Style/MutableConstant
|
9
|
+
order: :asc,
|
10
|
+
format: 'Q%q' } # '%q' token
|
10
11
|
|
11
12
|
# The label for any page, with the substitution of the '%q' token
|
12
13
|
def label_for(page, opts = {})
|
data/lib/pagy/calendar/year.rb
CHANGED
@@ -5,7 +5,8 @@ class Pagy # :nodoc:
|
|
5
5
|
class Calendar # :nodoc:
|
6
6
|
# Calendar year subclass
|
7
7
|
class Year < Calendar
|
8
|
-
DEFAULT = {
|
8
|
+
DEFAULT = { size: 10, # rubocop:disable Style/MutableConstant
|
9
|
+
order: :asc,
|
9
10
|
format: '%Y' }
|
10
11
|
|
11
12
|
protected
|
@@ -8,84 +8,97 @@ class Pagy # :nodoc:
|
|
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, pagy_id: nil, link_extra: '',
|
11
|
+
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '',
|
12
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
12
13
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
14
|
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
14
15
|
|
15
|
-
html = +%(<nav#{p_id} class="pagy-bootstrap-nav"
|
16
|
-
|
16
|
+
html = +%(<nav#{p_id} class="pagy-bootstrap-nav" #{
|
17
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><ul class="pagination">)
|
18
|
+
html << bootstrap_prev_html(pagy, link)
|
17
19
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
20
|
html << case item
|
19
21
|
when Integer
|
20
|
-
%(<li class="page-item">#{link.call
|
22
|
+
%(<li class="page-item">#{link.call(item)}</li>)
|
21
23
|
when String
|
22
|
-
%(<li class="page-item active">#{link.call
|
24
|
+
%(<li class="page-item active">#{link.call(item)}</li>)
|
23
25
|
when :gap
|
24
|
-
%(<li class="page-item gap disabled"><a href="#" class="page-link">#{
|
26
|
+
%(<li class="page-item gap disabled"><a href="#" class="page-link" aria-disabled="true">#{
|
27
|
+
pagy_t 'pagy.gap'}</a></li>)
|
25
28
|
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
26
29
|
end
|
27
30
|
end
|
28
|
-
html <<
|
31
|
+
html << bootstrap_next_html(pagy, link)
|
29
32
|
html << %(</ul></nav>)
|
30
33
|
end
|
31
34
|
|
32
35
|
# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the pagy.js file
|
33
|
-
def pagy_bootstrap_nav_js(pagy, pagy_id: nil, link_extra: '',
|
36
|
+
def pagy_bootstrap_nav_js(pagy, pagy_id: nil, link_extra: '',
|
37
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
34
38
|
sequels = pagy.sequels(**vars)
|
35
39
|
p_id = %( id="#{pagy_id}") if pagy_id
|
36
40
|
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
37
|
-
tags = { 'before' => %(<ul class="pagination">#{
|
38
|
-
'link' => %(<li class="page-item">#{
|
39
|
-
'active' => %(<li class="page-item active">#{
|
40
|
-
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{
|
41
|
-
|
41
|
+
tags = { 'before' => %(<ul class="pagination">#{bootstrap_prev_html pagy, link}),
|
42
|
+
'link' => %(<li class="page-item">#{html = link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</li>),
|
43
|
+
'active' => %(<li class="page-item active">#{html}</li>),
|
44
|
+
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link" aria-disabled="true">#{
|
45
|
+
pagy_t 'pagy.gap'}</a></li>),
|
46
|
+
'after' => %(#{bootstrap_next_html pagy, link}</ul>) }
|
42
47
|
|
43
48
|
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bootstrap-nav-js" #{
|
44
|
-
|
49
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
|
50
|
+
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))
|
51
|
+
}></nav>)
|
45
52
|
end
|
46
53
|
|
47
54
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the pagy.js file
|
48
|
-
def pagy_bootstrap_combo_nav_js(pagy, pagy_id: nil, link_extra: ''
|
55
|
+
def pagy_bootstrap_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
|
56
|
+
nav_aria_label: nil, nav_i18n_key: nil)
|
49
57
|
p_id = %( id="#{pagy_id}") if pagy_id
|
50
|
-
link = pagy_link_proc(pagy, link_extra:
|
58
|
+
link = pagy_link_proc(pagy, link_extra:)
|
51
59
|
p_page = pagy.page
|
52
60
|
p_pages = pagy.pages
|
53
61
|
input = %(<input type="number" min="1" max="#{p_pages}" value="#{
|
54
62
|
p_page}" style="padding: 0; border: none; text-align: center; width: #{
|
55
|
-
p_pages.to_s.length + 1}rem;">)
|
63
|
+
p_pages.to_s.length + 1}rem;" aria-current="page">)
|
56
64
|
|
57
|
-
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination"
|
65
|
+
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination" #{
|
66
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><div class="btn-group" role="group" #{
|
58
67
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
59
68
|
if (p_prev = pagy.prev)
|
60
|
-
link.call
|
69
|
+
link.call(p_prev, pagy_t('pagy.prev'), %(class="prev btn btn-primary" #{prev_aria_label_attr}))
|
61
70
|
else
|
62
|
-
%(<a class="prev btn btn-primary disabled" href="#"
|
71
|
+
%(<a class="prev btn btn-primary disabled" href="#" aria-disabled="true" #{
|
72
|
+
prev_aria_label_attr}>#{pagy_t('pagy.prev')}</a>)
|
63
73
|
end
|
64
74
|
}<div class="pagy-combo-input btn btn-secondary" style="white-space: nowrap;">#{
|
65
75
|
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
|
66
|
-
if (p_next
|
67
|
-
link.call
|
76
|
+
if (p_next = pagy.next)
|
77
|
+
link.call(p_next, pagy_t('pagy.next'), %(class="next btn btn-primary" #{next_aria_label_attr}))
|
68
78
|
else
|
69
|
-
%(<a class="next btn btn-primary disabled" href="#"
|
79
|
+
%(<a class="next btn btn-primary disabled" href="#" aria-disabled="true" #{
|
80
|
+
next_aria_label_attr}>#{pagy_t 'pagy.next'}</a>)
|
70
81
|
end
|
71
82
|
}</div></nav>)
|
72
83
|
end
|
73
84
|
|
74
85
|
private
|
75
86
|
|
76
|
-
def
|
87
|
+
def bootstrap_prev_html(pagy, link)
|
77
88
|
if (p_prev = pagy.prev)
|
78
|
-
%(<li class="page-item prev">#{link.call
|
89
|
+
%(<li class="page-item prev">#{link.call(p_prev, pagy_t('pagy.prev'), prev_aria_label_attr)}</li>)
|
79
90
|
else
|
80
|
-
%(<li class="page-item prev disabled"><a href="#" class="page-link"
|
91
|
+
%(<li class="page-item prev disabled"><a href="#" class="page-link" aria-disabled="true" #{
|
92
|
+
prev_aria_label_attr}>#{pagy_t('pagy.prev')}</a></li>)
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
84
|
-
def
|
96
|
+
def bootstrap_next_html(pagy, link)
|
85
97
|
if (p_next = pagy.next)
|
86
|
-
%(<li class="page-item next">#{link.call p_next, pagy_t('pagy.
|
98
|
+
%(<li class="page-item next">#{link.call p_next, pagy_t('pagy.next'), next_aria_label_attr}</li>)
|
87
99
|
else
|
88
|
-
%(<li class="page-item next disabled"><a href="#" class="page-link"
|
100
|
+
%(<li class="page-item next disabled"><a href="#" class="page-link" aria-disabled="true" #{
|
101
|
+
next_aria_label_attr}>#{pagy_t('pagy.next')}</a></li>)
|
89
102
|
end
|
90
103
|
end
|
91
104
|
end
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -4,26 +4,29 @@
|
|
4
4
|
require 'pagy/extras/frontend_helpers'
|
5
5
|
|
6
6
|
class Pagy # :nodoc:
|
7
|
+
DEFAULT[:bulma_nav_classes] = 'is-centered'
|
8
|
+
|
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 BulmaExtra
|
10
12
|
# Pagination for bulma: it returns the html with the series of links to the pages
|
11
|
-
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '',
|
13
|
+
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '',
|
14
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
12
15
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
|
-
link = pagy_link_proc(pagy, link_extra:
|
16
|
+
link = pagy_link_proc(pagy, link_extra:)
|
14
17
|
|
15
|
-
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination
|
16
|
-
|
18
|
+
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination #{DEFAULT[:bulma_nav_classes]}" #{
|
19
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>)
|
20
|
+
html << bulma_prev_next_html(pagy, link)
|
17
21
|
html << %(<ul class="pagination-list">)
|
18
22
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
19
23
|
html << case item
|
20
24
|
when Integer
|
21
|
-
%(<li>#{link.call
|
25
|
+
%(<li>#{link.call(item, pagy.label_for(item), %(class="pagination-link"))}</li>)
|
22
26
|
when String
|
23
|
-
%(<li>#{link.call
|
24
|
-
%(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>)
|
27
|
+
%(<li>#{link.call(item, pagy.label_for(item), %(class="pagination-link is-current"))}</li>)
|
25
28
|
when :gap
|
26
|
-
%(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.
|
29
|
+
%(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.gap'}</span></li>)
|
27
30
|
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
28
31
|
end
|
29
32
|
end
|
@@ -31,62 +34,68 @@ class Pagy # :nodoc:
|
|
31
34
|
end
|
32
35
|
|
33
36
|
# Javascript pagination for bulma: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
34
|
-
def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '',
|
37
|
+
def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '',
|
38
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
35
39
|
sequels = pagy.sequels(**vars)
|
36
40
|
p_id = %( id="#{pagy_id}") if pagy_id
|
37
|
-
link = pagy_link_proc(pagy, link_extra:
|
38
|
-
tags = { 'before' => %(#{
|
39
|
-
'link' => %(<li>#{link.call
|
40
|
-
|
41
|
-
'
|
42
|
-
%(class="pagination-link is-current" aria-current="page" aria-label="page #{
|
43
|
-
PAGE_PLACEHOLDER}")}</li>),
|
44
|
-
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>),
|
41
|
+
link = pagy_link_proc(pagy, link_extra:)
|
42
|
+
tags = { 'before' => %(#{bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
|
43
|
+
'link' => %(<li>#{link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER, %(class="pagination-link"))}</li>),
|
44
|
+
'active' => %(<li>#{link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER, %(class="pagination-link is-current"))}</li>),
|
45
|
+
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.gap'}</span></li>),
|
45
46
|
'after' => '</ul>' }
|
46
47
|
|
47
|
-
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bulma-nav-js pagination
|
48
|
+
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bulma-nav-js pagination #{DEFAULT[:bulma_nav_classes]}" #{
|
49
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}#{
|
48
50
|
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
|
49
51
|
end
|
50
52
|
|
51
53
|
# Javascript combo pagination for bulma: it returns a nav and a JSON tag used by the pagy.js file
|
52
|
-
def pagy_bulma_combo_nav_js(pagy, pagy_id: nil, link_extra: ''
|
54
|
+
def pagy_bulma_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
|
55
|
+
nav_aria_label: nil, nav_i18n_key: nil)
|
53
56
|
p_id = %( id="#{pagy_id}") if pagy_id
|
54
|
-
link = pagy_link_proc(pagy, link_extra:
|
57
|
+
link = pagy_link_proc(pagy, link_extra:)
|
55
58
|
p_page = pagy.page
|
56
59
|
p_pages = pagy.pages
|
57
60
|
input = %(<input class="input" type="number" min="1" max="#{p_pages}" value="#{
|
58
|
-
p_page}" style="padding: 0; text-align: center; width: #{
|
61
|
+
p_page}" style="padding: 0; text-align: center; width: #{
|
62
|
+
p_pages.to_s.length + 1}rem; margin:0 0.3rem;" aria-current="page">)
|
59
63
|
|
60
|
-
html = %(<nav#{p_id} class="pagy-bulma-combo-nav-js"
|
64
|
+
html = %(<nav#{p_id} class="pagy-bulma-combo-nav-js #{DEFAULT[:bulma_nav_classes]}" #{
|
65
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>)
|
61
66
|
%(#{html}<div class="field is-grouped is-grouped-centered" role="group" #{
|
62
67
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
63
68
|
if (p_prev = pagy.prev)
|
64
|
-
%(<p class="control">#{link.call
|
69
|
+
%(<p class="control">#{link.call(p_prev, pagy_t('pagy.prev'), %(class="button" #{prev_aria_label_attr}))}</p>)
|
65
70
|
else
|
66
|
-
%(<p class="control"><a class="button" disabled
|
71
|
+
%(<p class="control"><a class="button" disabled aria-disabled="true" #{
|
72
|
+
prev_aria_label_attr}>#{pagy_t 'pagy.prev'}</a></p>)
|
67
73
|
end
|
68
74
|
}<div class="pagy-combo-input control level is-mobile">#{
|
69
75
|
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
|
70
76
|
if (p_next = pagy.next)
|
71
|
-
%(<p class="control">#{link.call
|
77
|
+
%(<p class="control">#{link.call(p_next, pagy_t('pagy.next'), %(class="button" #{next_aria_label_attr}))}</p>)
|
72
78
|
else
|
73
|
-
%(<p class="control"><a class="button" disabled
|
79
|
+
%(<p class="control"><a class="button" disabled aria-disabled="true"#{
|
80
|
+
next_aria_label_attr}>#{pagy_t 'pagy.next'}</a></p>)
|
74
81
|
end
|
75
82
|
}</div></nav>)
|
76
83
|
end
|
77
84
|
|
78
85
|
private
|
79
86
|
|
80
|
-
def
|
87
|
+
def bulma_prev_next_html(pagy, link)
|
81
88
|
html = +if (p_prev = pagy.prev)
|
82
|
-
link.call
|
89
|
+
link.call(p_prev, pagy_t('pagy.prev'), %(#{prev_aria_label_attr} class="pagination-previous"))
|
83
90
|
else
|
84
|
-
%(<a class="pagination-previous" disabled
|
91
|
+
%(<a class="pagination-previous" disabled aria-disabled="true" #{
|
92
|
+
prev_aria_label_attr}>#{pagy_t 'pagy.prev'}</a>)
|
85
93
|
end
|
86
94
|
html << if (p_next = pagy.next)
|
87
|
-
link.call
|
95
|
+
link.call(p_next, pagy_t('pagy.next'), %(#{next_aria_label_attr} class="pagination-next"))
|
88
96
|
else
|
89
|
-
%(<a class="pagination-next" disabled
|
97
|
+
%(<a class="pagination-next" disabled aria-disabled="true" #{
|
98
|
+
next_aria_label_attr}>#{pagy_t('pagy.next')}</a>)
|
90
99
|
end
|
91
100
|
end
|
92
101
|
end
|
data/lib/pagy/extras/calendar.rb
CHANGED
@@ -8,18 +8,17 @@ class Pagy # :nodoc:
|
|
8
8
|
# Add pagination filtering by calendar unit (:year, :quarter, :month, :week, :day) to the regular pagination
|
9
9
|
module CalendarExtra
|
10
10
|
# Additions for the Backend module
|
11
|
-
module
|
11
|
+
module BackendAddOn
|
12
12
|
CONF_KEYS = (Calendar::UNITS + %i[pagy active]).freeze
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
16
|
# Take a collection and a conf Hash with keys in CONF_KEYS and return an array with 3 items: [calendar, pagy, results]
|
17
17
|
def pagy_calendar(collection, conf)
|
18
|
-
|
19
|
-
|
20
|
-
end
|
18
|
+
raise ArgumentError, "keys must be in #{CONF_KEYS.inspect}" \
|
19
|
+
unless conf.is_a?(Hash) && (conf.keys - CONF_KEYS).empty?
|
21
20
|
|
22
|
-
conf[:pagy]
|
21
|
+
conf[:pagy] ||= {}
|
23
22
|
unless conf.key?(:active) && !conf[:active]
|
24
23
|
calendar, from, to = Calendar::Helper.send(:init, conf, pagy_calendar_period(collection), params)
|
25
24
|
collection = pagy_calendar_filter(collection, from, to)
|
@@ -42,13 +41,13 @@ class Pagy # :nodoc:
|
|
42
41
|
end
|
43
42
|
|
44
43
|
# Additions for the Frontend module
|
45
|
-
module
|
44
|
+
module UrlHelperAddOn
|
46
45
|
# Return the url for the calendar page at time
|
47
46
|
def pagy_calendar_url_at(calendar, time, **opts)
|
48
47
|
pagy_url_for(calendar.send(:calendar_at, time, **opts), 1, **opts)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
|
-
Backend.prepend CalendarExtra::
|
53
|
-
Frontend.prepend CalendarExtra::
|
51
|
+
Backend.prepend CalendarExtra::BackendAddOn, CalendarExtra::UrlHelperAddOn
|
52
|
+
Frontend.prepend CalendarExtra::UrlHelperAddOn
|
54
53
|
end
|
@@ -19,7 +19,7 @@ class Pagy # :nodoc:
|
|
19
19
|
total.is_a?(Hash) ? total['value'] : total
|
20
20
|
end
|
21
21
|
|
22
|
-
module
|
22
|
+
module ModelExtension # :nodoc:
|
23
23
|
# Return an array used to delay the call of #search
|
24
24
|
# after the pagination variables are merged to the options.
|
25
25
|
# It also pushes to the same array an optional method call.
|
@@ -30,9 +30,10 @@ class Pagy # :nodoc:
|
|
30
30
|
end
|
31
31
|
alias_method Pagy::DEFAULT[:elasticsearch_rails_pagy_search], :pagy_elasticsearch_rails
|
32
32
|
end
|
33
|
+
Pagy::ElasticsearchRails = ModelExtension
|
33
34
|
|
34
35
|
# Additions for the Pagy class
|
35
|
-
module
|
36
|
+
module PagyAddOn
|
36
37
|
# Create a Pagy object from an Elasticsearch::Model::Response::Response object
|
37
38
|
def new_from_elasticsearch_rails(response, vars = {})
|
38
39
|
vars[:items] = response.search.options[:size] || 10
|
@@ -41,9 +42,10 @@ class Pagy # :nodoc:
|
|
41
42
|
new(vars)
|
42
43
|
end
|
43
44
|
end
|
45
|
+
Pagy.extend PagyAddOn
|
44
46
|
|
45
47
|
# Add specialized backend methods to paginate ElasticsearchRails searches
|
46
|
-
module
|
48
|
+
module BackendAddOn
|
47
49
|
private
|
48
50
|
|
49
51
|
# Return Pagy object and items
|
@@ -73,8 +75,6 @@ class Pagy # :nodoc:
|
|
73
75
|
vars
|
74
76
|
end
|
75
77
|
end
|
78
|
+
Backend.prepend BackendAddOn
|
76
79
|
end
|
77
|
-
ElasticsearchRails = ElasticsearchRailsExtra::ElasticsearchRails
|
78
|
-
extend ElasticsearchRailsExtra::Pagy
|
79
|
-
Backend.prepend ElasticsearchRailsExtra::Backend
|
80
80
|
end
|