pagy 0.10.1 → 0.11.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/lib/locales/pagy.yml +2 -0
- data/lib/locales/plurals.rb +25 -0
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +5 -6
- data/lib/pagy/extras/compact.rb +18 -19
- data/lib/pagy/extras/i18n.rb +1 -2
- data/lib/pagy/extras/items.rb +6 -6
- data/lib/pagy/extras/javascripts/pagy.js +46 -58
- data/lib/pagy/extras/responsive.rb +13 -13
- data/lib/pagy/frontend.rb +16 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844ca7b25affe1bb80fd78bc75aa6d91c55000134aecfea338288d57b9587231
|
4
|
+
data.tar.gz: dc9e704d31c3fb376d23d560725c921484ef4ea037524a8bf86c67246069f62f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fe1bc2404142977f00b1285081a6fc39c9b1be5be6813efa8271cebb2b7e1e58349264458cfd5874afca86bb4d0c3e693b3dc1721d0ceccbdfb0d569a5f4dc2
|
7
|
+
data.tar.gz: 2d066a55b2103ff8c96baadab07730413692f8233d4e28eeecbef1fe1fc04770b47b48aa92b3fa4212f6e82652ab72bed47822f3babbb77a8726868cbb6ab064
|
data/lib/locales/pagy.yml
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file adds support for multiple built-in plualiztion types.
|
2
|
+
# It defines the pluralization procs and gets eval(ed) at I18N.load time
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
# utility variables
|
6
|
+
zero_one = ['zero', 'one']
|
7
|
+
|
8
|
+
# Rules
|
9
|
+
# A rule is a proc returning a plural type string based on the passed count
|
10
|
+
# Each plural rule may apply to many language/rule pairs below
|
11
|
+
rules = {
|
12
|
+
zero_one_other: -> (count) {zero_one[count] || 'other'}
|
13
|
+
}
|
14
|
+
|
15
|
+
# Plurals (language/rule pairs)
|
16
|
+
# The default rule for missing languages is the :zero_one_other rule (used for English)
|
17
|
+
plurals = Hash.new(rules[:zero_one_other])
|
18
|
+
|
19
|
+
# Entries for all the languages defined in the pagy.yml dictionary
|
20
|
+
plurals['en'] = rules[:zero_one_other]
|
21
|
+
|
22
|
+
# PR for other languages are very welcome. Thanks!
|
23
|
+
|
24
|
+
# Return plurals
|
25
|
+
plurals
|
data/lib/pagy.rb
CHANGED
@@ -7,21 +7,20 @@ class Pagy
|
|
7
7
|
|
8
8
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
9
9
|
def pagy_nav_bootstrap(pagy)
|
10
|
-
|
10
|
+
html, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
|
11
11
|
|
12
|
-
|
12
|
+
html << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
13
13
|
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
|
14
14
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
15
|
-
|
15
|
+
html << if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
|
16
16
|
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
|
17
17
|
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
html << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
21
21
|
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
|
22
|
-
%(<nav class="pagy-nav-
|
22
|
+
%(<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
data/lib/pagy/extras/compact.rb
CHANGED
@@ -6,38 +6,37 @@ class Pagy
|
|
6
6
|
module Frontend
|
7
7
|
|
8
8
|
# Generic compact pagination: it returns the html with the series of links to the pages
|
9
|
-
# we use a numeric input tag to set the page and the
|
9
|
+
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
10
10
|
def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
|
11
|
-
|
11
|
+
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
|
14
|
+
html << link.call(MARKER, '', %(style="display: none;" ))
|
15
|
+
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
16
16
|
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
17
17
|
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
18
|
-
|
19
|
-
|
18
|
+
html << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</span> )
|
19
|
+
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
20
20
|
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
21
|
-
|
21
|
+
html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
22
22
|
end
|
23
23
|
|
24
24
|
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
|
25
|
-
# we use a numeric input tag to set the page and the
|
26
|
-
def
|
27
|
-
|
25
|
+
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
26
|
+
def pagy_nav_compact_bootstrap(pagy, id=caller(1,1)[0].hash)
|
27
|
+
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">)
|
30
|
+
html << link.call(MARKER, '', %(style="display: none;" ))
|
31
|
+
html << %(<div class="btn-group" role="group">)
|
32
|
+
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
|
33
33
|
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
|
34
34
|
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
35
|
-
|
36
|
-
|
35
|
+
html << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
|
36
|
+
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
37
37
|
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
38
|
-
|
38
|
+
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
data/lib/pagy/extras/i18n.rb
CHANGED
data/lib/pagy/extras/items.rb
CHANGED
@@ -22,21 +22,21 @@ class Pagy
|
|
22
22
|
|
23
23
|
module Frontend
|
24
24
|
|
25
|
-
#
|
25
|
+
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
26
26
|
def pagy_url_for(page, pagy)
|
27
27
|
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, p_vars[:items_param] => p_vars[:items], **p_vars[:params])
|
28
28
|
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
29
29
|
end
|
30
30
|
|
31
|
-
#
|
31
|
+
# Return the items selector HTML. For example "Show [20] items per page"
|
32
32
|
def pagy_items_selector(pagy, id=caller(1,1)[0].hash)
|
33
33
|
pagy = pagy.clone; p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
html = +%(<span id="pagy-items-#{id}">)
|
36
|
+
html << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
|
37
37
|
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
|
38
|
-
|
39
|
-
|
38
|
+
html << %(#{pagy_t('pagy.items.show')} #{input} #{pagy_t('pagy.items.items')})
|
39
|
+
html << %(</span><script type="application/json" class="pagy-items-json">["#{id}", "#{MARKER}", #{pagy.from}]</script>)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -1,84 +1,72 @@
|
|
1
|
-
// See the Pagy documentation: https://ddnexus.github.io/pagy/extras
|
1
|
+
// See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
+
Pagy.addInputEventListeners = function(input, handler){
|
6
|
+
// select the content on click: easier for typing a number
|
7
|
+
input.addEventListener('click', function(){ this.select() });
|
8
|
+
// go when the input looses focus
|
9
|
+
input.addEventListener('focusout', handler);
|
10
|
+
// … and when pressing enter inside the input
|
11
|
+
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
|
12
|
+
};
|
13
|
+
|
5
14
|
Pagy.compact = function(id, marker, page){
|
6
15
|
var pagyNav = document.getElementById('pagy-nav-'+id),
|
7
16
|
input = pagyNav.getElementsByTagName('input')[0],
|
8
|
-
link = pagyNav.getElementsByTagName('a')[0]
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
// select the content on click: easier for typing a number
|
19
|
-
input.addEventListener('click', function(){ this.select() });
|
20
|
-
// go when the input looses focus
|
21
|
-
input.addEventListener('focusout', go);
|
22
|
-
// … and when pressing enter inside the input
|
23
|
-
input.addEventListener('keyup', function(e){ if (e.which === 13) go() }.bind(this));
|
24
|
-
|
25
|
-
};
|
26
|
-
|
17
|
+
link = pagyNav.getElementsByTagName('a')[0],
|
18
|
+
go = function(){
|
19
|
+
if (page !== input.value) {
|
20
|
+
var href = link.getAttribute('href').replace(marker, input.value);
|
21
|
+
link.setAttribute('href', href);
|
22
|
+
link.click();
|
23
|
+
}
|
24
|
+
};
|
25
|
+
Pagy.addInputEventListeners(input, go);
|
26
|
+
};
|
27
27
|
|
28
28
|
Pagy.items = function(id, marker, from){
|
29
29
|
var pagyNav = document.getElementById('pagy-items-'+id),
|
30
30
|
input = pagyNav.getElementsByTagName('input')[0],
|
31
31
|
current = input.value,
|
32
|
-
link = pagyNav.getElementsByTagName('a')[0]
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
// select the content on click: easier for typing a number
|
45
|
-
input.addEventListener('click', function(){ this.select() });
|
46
|
-
// go when the input looses focus
|
47
|
-
input.addEventListener('focusout', go);
|
48
|
-
// … and when pressing enter inside the input
|
49
|
-
input.addEventListener('keyup', function(e){ if (e.which === 13) go() }.bind(this));
|
50
|
-
|
32
|
+
link = pagyNav.getElementsByTagName('a')[0],
|
33
|
+
go = function(){
|
34
|
+
var items = input.value;
|
35
|
+
if (current !== items) {
|
36
|
+
var page = Math.max(Math.ceil(from / items),1);
|
37
|
+
var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
|
38
|
+
link.setAttribute('href', href);
|
39
|
+
link.click();
|
40
|
+
}
|
41
|
+
};
|
42
|
+
Pagy.addInputEventListeners(input, go);
|
51
43
|
};
|
52
44
|
|
53
|
-
Pagy.responsive = function(id,
|
45
|
+
Pagy.responsive = function(id, tags, widths, series){
|
54
46
|
var pagyNav = document.getElementById('pagy-nav-'+id),
|
55
47
|
pagyBox = pagyNav.firstChild || pagyNav,
|
56
48
|
pagyParent = pagyNav.parentElement,
|
57
|
-
lastWidth = undefined
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
};
|
71
|
-
|
49
|
+
lastWidth = undefined,
|
50
|
+
render = function(){
|
51
|
+
var parentWidth = parseInt(pagyParent.clientWidth),
|
52
|
+
width = widths.find(function(w){return parentWidth > w});
|
53
|
+
if (width !== lastWidth) {
|
54
|
+
while (pagyBox.firstChild) { pagyBox.removeChild(pagyBox.firstChild) }
|
55
|
+
var html = tags['prev'];
|
56
|
+
series[width].forEach(function(item){html += tags[item]});
|
57
|
+
html += tags['next'];
|
58
|
+
pagyBox.insertAdjacentHTML('beforeend', html);
|
59
|
+
lastWidth = width;
|
60
|
+
}
|
61
|
+
};
|
72
62
|
if (window.attachEvent) { window.attachEvent('onresize', render) }
|
73
63
|
else if (window.addEventListener) { window.addEventListener('resize', render, true) }
|
74
|
-
|
75
64
|
render();
|
76
65
|
};
|
77
66
|
|
78
|
-
|
79
67
|
Pagy.init = function(){
|
80
68
|
['compact', 'items', 'responsive'].forEach(function(name){
|
81
|
-
Array.from(document.getElementsByClassName("pagy-"+name)).forEach(function(json) {
|
69
|
+
Array.from(document.getElementsByClassName("pagy-"+name+"-json")).forEach(function(json) {
|
82
70
|
Pagy[name].apply(null, JSON.parse(json.innerHTML))
|
83
71
|
})
|
84
72
|
})
|
@@ -22,7 +22,7 @@ class Pagy
|
|
22
22
|
# :widths is the desc-ordered array of widths (passed to the PagyResponsive javascript function)
|
23
23
|
def responsive
|
24
24
|
@responsive ||= {items: [], series: {}, widths:[]}.tap do |r|
|
25
|
-
@vars[:breakpoints].key?(0) || raise(ArgumentError, "expected :breakpoints to contain the 0 size; got #{@vars[:
|
25
|
+
@vars[:breakpoints].key?(0) || raise(ArgumentError, "expected :breakpoints to contain the 0 size; got #{@vars[:breakpoints].inspect}")
|
26
26
|
@vars[:breakpoints].each {|width, size| r[:items] |= r[:series][width] = series(size)}
|
27
27
|
r[:widths] = r[:series].keys.sort!{|a,b| b <=> a}
|
28
28
|
end
|
@@ -32,41 +32,41 @@ class Pagy
|
|
32
32
|
module Frontend
|
33
33
|
|
34
34
|
# Generic responsive pagination: it returns the html with the series of links to the pages
|
35
|
-
#
|
35
|
+
# rendered by the Pagy.responsive javascript
|
36
36
|
def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
|
37
37
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
38
38
|
|
39
|
-
tags[
|
40
|
-
|
39
|
+
tags['prev'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
40
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
41
41
|
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
42
42
|
tags[item.to_s] = if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
43
43
|
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
44
44
|
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
45
45
|
end
|
46
46
|
end
|
47
|
-
tags[
|
48
|
-
|
49
|
-
script = %(<script type="application/json" class="pagy-responsive">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
47
|
+
tags['next'] = (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
48
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
49
|
+
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
50
50
|
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
|
51
51
|
end
|
52
52
|
|
53
53
|
# Responsive pagination for bootstrap: it returns the html with the series of links to the pages
|
54
|
-
#
|
55
|
-
def
|
54
|
+
# rendered by the Pagy.responsive javascript
|
55
|
+
def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
|
56
56
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
|
57
57
|
|
58
58
|
tags['prev'] = (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
59
59
|
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
|
60
60
|
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
61
|
-
tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>)
|
62
|
-
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>)
|
61
|
+
tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
|
62
|
+
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
|
63
63
|
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
|
64
64
|
end
|
65
65
|
end
|
66
66
|
tags['next'] = (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
67
67
|
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
|
68
|
-
script = %(<script type="application/json" class="pagy-responsive">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
69
|
-
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap
|
68
|
+
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
69
|
+
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination"></ul></nav>#{script})
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
data/lib/pagy/frontend.rb
CHANGED
@@ -11,19 +11,19 @@ class Pagy
|
|
11
11
|
|
12
12
|
# Generic pagination: it returns the html with the series of links to the pages
|
13
13
|
def pagy_nav(pagy)
|
14
|
-
|
14
|
+
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
15
15
|
|
16
|
-
|
16
|
+
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
17
17
|
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
18
18
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
19
|
-
|
19
|
+
html << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
20
20
|
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
21
21
|
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
25
25
|
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
26
|
-
%(<nav class="pagy-nav pagination" role="navigation" aria-label="pager">#{
|
26
|
+
%(<nav class="pagy-nav pagination" role="navigation" aria-label="pager">#{html}</nav>)
|
27
27
|
end
|
28
28
|
|
29
29
|
# Return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
|
@@ -33,7 +33,7 @@ class Pagy
|
|
33
33
|
pagy_t(path, item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
|
34
34
|
end
|
35
35
|
|
36
|
-
#
|
36
|
+
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
37
37
|
def pagy_url_for(page, pagy)
|
38
38
|
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, **p_vars[:params])
|
39
39
|
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
@@ -54,19 +54,20 @@ class Pagy
|
|
54
54
|
else '' end } #{extra}>#{text}</a>" }
|
55
55
|
end
|
56
56
|
|
57
|
-
# Pagy::Frontend::I18N
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
# Pagy::Frontend::I18N
|
58
|
+
def (I18N = {data:{}}).load(file:Pagy.root.join('locales', 'pagy.yml'), language: 'en')
|
59
|
+
self[:data] = YAML.load_file(file)[language]
|
60
|
+
self[:plural] = eval(Pagy.root.join('locales', 'plurals.rb').read)[language] #rubocop:disable Security/Eval
|
61
|
+
end; I18N.load
|
61
62
|
|
62
|
-
# Similar to I18n.t for interpolation and pluralization but without translation
|
63
|
-
#
|
64
|
-
# See also https://ddnexus.github.io/pagy/extras/i18n to use the standard I18n gem instead
|
63
|
+
# Similar to I18n.t for streamlined interpolation and pluralization but without dynamic translation.
|
64
|
+
# It is specialized for Pagy and 5x faster than I18n.t (see https://ddnexus.github.io/pagy/api/frontend#i18n)
|
65
|
+
# See also https://ddnexus.github.io/pagy/extras/i18n if you need to use the standard I18n gem instead
|
65
66
|
def pagy_t(path, vars={})
|
66
|
-
value =
|
67
|
+
value = I18N[:data].dig(*path.split('.')) or return %(translation missing: "#{path}")
|
67
68
|
if value.is_a?(Hash)
|
68
69
|
vars.key?(:count) or return value
|
69
|
-
plural = I18N[:
|
70
|
+
plural = I18N[:plural].call(vars[:count])
|
70
71
|
value.key?(plural) or return %(invalid pluralization data: "#{path}" cannot be used with count: #{vars[:count]}; key "#{plural}" is missing.)
|
71
72
|
value = value[plural] or return %(translation missing: "#{path}")
|
72
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
|
14
14
|
and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
|
@@ -22,6 +22,7 @@ extra_rdoc_files: []
|
|
22
22
|
files:
|
23
23
|
- LICENSE.txt
|
24
24
|
- lib/locales/pagy.yml
|
25
|
+
- lib/locales/plurals.rb
|
25
26
|
- lib/pagy.rb
|
26
27
|
- lib/pagy/backend.rb
|
27
28
|
- lib/pagy/extras/array.rb
|