pagy 3.0.0 → 3.1.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/config/pagy.rb +1 -1
- data/lib/javascripts/pagy.js +17 -18
- data/lib/pagy/extras/bootstrap.rb +11 -14
- data/lib/pagy/extras/bulma.rb +11 -13
- data/lib/pagy/extras/foundation.rb +10 -13
- data/lib/pagy/extras/headers.rb +2 -2
- data/lib/pagy/extras/items.rb +8 -5
- data/lib/pagy/extras/materialize.rb +7 -9
- data/lib/pagy/extras/navs.rb +10 -12
- data/lib/pagy/extras/semantic.rb +10 -12
- data/lib/pagy/extras/shared.rb +10 -3
- data/lib/pagy/extras/trim.rb +4 -4
- data/lib/pagy/frontend.rb +4 -6
- data/lib/pagy.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c829d223b7c780665135815222ed37bfe250d61e4e9c8f8083b829940d7bedd7
|
4
|
+
data.tar.gz: c3764805ed4bdbdd692ed71727703e4b007cdeefb9477dccb465c7d8cb327f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9af20f32dae70bc7baa773124283af036a516e419b8e35631798a1bcc29fe99468724032cbddbe84495a92b486016e99e8478d8e8936b31732897ce9d34397cf
|
7
|
+
data.tar.gz: 9f3c149eeb720c9afd7d4dbe923197c4764a9e05f70c227aef72282c61146389d75709f74c075ae79aa0c6c59bf7fa88a152aaf8a48f41bf4f004fee1c2a16f8
|
data/lib/config/pagy.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Pagy initializer file (3.
|
4
|
+
# Pagy initializer file (3.1.0)
|
5
5
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
6
6
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
7
7
|
|
data/lib/javascripts/pagy.js
CHANGED
@@ -11,12 +11,12 @@ Pagy.init = function(arg){
|
|
11
11
|
}
|
12
12
|
};
|
13
13
|
|
14
|
-
Pagy.nav = function(id,
|
14
|
+
Pagy.nav = function(id, tags, sequels){
|
15
15
|
var pagyEl = document.getElementById(id),
|
16
16
|
container = pagyEl.parentElement,
|
17
17
|
lastWidth = undefined,
|
18
18
|
timeoutId = 0,
|
19
|
-
|
19
|
+
markRE = new RegExp('--pagy.page--', 'g'),
|
20
20
|
widths = [];
|
21
21
|
for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
|
22
22
|
widths.sort(function(a, b){return b-a});
|
@@ -33,9 +33,9 @@ Pagy.nav = function(id, marker, tags, sequels){
|
|
33
33
|
series = sequels[width];
|
34
34
|
for (i = 0, len = series.length; i < len; i++) {
|
35
35
|
var item = series[i];
|
36
|
-
if (typeof(item) === 'number') { html += tags.link.replace(
|
36
|
+
if (typeof(item) === 'number') { html += tags.link.replace(markRE, item) }
|
37
37
|
else if (item === 'gap') { html += tags.gap }
|
38
|
-
else if (typeof(item) === 'string') { html += tags.active.replace(
|
38
|
+
else if (typeof(item) === 'string') { html += tags.active.replace(markRE, item) }
|
39
39
|
}
|
40
40
|
html += tags.after;
|
41
41
|
pagyEl.insertAdjacentHTML('beforeend', html);
|
@@ -54,36 +54,36 @@ Pagy.nav = function(id, marker, tags, sequels){
|
|
54
54
|
render();
|
55
55
|
};
|
56
56
|
|
57
|
-
Pagy.combo_nav = function(id,
|
57
|
+
Pagy.combo_nav = function(id, page, links){
|
58
58
|
var pagyEl = document.getElementById(id),
|
59
59
|
input = pagyEl.getElementsByTagName('input')[0],
|
60
|
-
link = pagyEl.getElementsByTagName('a')[0],
|
61
|
-
linkP1 = pagyEl.getElementsByTagName('a')[1],
|
62
60
|
go = function(){
|
63
61
|
if (page !== input.value) {
|
64
|
-
if (
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
link.click();
|
62
|
+
if (links.hasOwnProperty('trimmed') && input.value === '1') {
|
63
|
+
pagyEl.insertAdjacentHTML('afterbegin', links.trimmed);
|
64
|
+
} else {
|
65
|
+
pagyEl.insertAdjacentHTML('afterbegin', links.standard.replace('--pagy.page--', input.value));
|
69
66
|
}
|
67
|
+
pagyEl.getElementsByTagName('a')[0].click();
|
70
68
|
}
|
71
69
|
};
|
72
70
|
Pagy.addInputEventListeners(input, go);
|
73
71
|
};
|
74
72
|
|
75
|
-
Pagy.items_selector = function(id,
|
73
|
+
Pagy.items_selector = function(id, from, links){
|
76
74
|
var pagyEl = document.getElementById(id),
|
77
75
|
input = pagyEl.getElementsByTagName('input')[0],
|
78
76
|
current = input.value,
|
79
|
-
link = pagyEl.getElementsByTagName('a')[0],
|
80
77
|
go = function(){
|
81
78
|
var items = input.value;
|
82
79
|
if (current !== items) {
|
83
80
|
var page = Math.max(Math.ceil(from / items),1);
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
if (links.hasOwnProperty('trimmed') && page === 1) {
|
82
|
+
pagyEl.insertAdjacentHTML('afterbegin', links.trimmed.replace('--pagy.items--', items));
|
83
|
+
} else {
|
84
|
+
pagyEl.insertAdjacentHTML('afterbegin', links.standard.replace('--pagy.page--', page).replace('--pagy.items--', items));
|
85
|
+
}
|
86
|
+
pagyEl.getElementsByTagName('a')[0].click();
|
87
87
|
}
|
88
88
|
};
|
89
89
|
Pagy.addInputEventListeners(input, go);
|
@@ -99,4 +99,3 @@ Pagy.addInputEventListeners = function(input, handler){
|
|
99
99
|
// … and when pressing enter inside the input
|
100
100
|
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
|
101
101
|
};
|
102
|
-
|
@@ -29,29 +29,26 @@ class Pagy
|
|
29
29
|
link, p_prev, p_next = pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
|
30
30
|
tags = { 'before' => p_prev ? %(<ul class="pagination"><li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
31
31
|
: %(<ul class="pagination"><li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>),
|
32
|
-
'link' => %(<li class="page-item">#{
|
33
|
-
'active' => %(<li class="page-item active">#{
|
32
|
+
'link' => %(<li class="page-item">#{mark = link.call(MARK)}</li>),
|
33
|
+
'active' => %(<li class="page-item active">#{mark}</li>),
|
34
34
|
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>),
|
35
35
|
'after' => p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li></ul>)
|
36
36
|
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li></ul>) }
|
37
|
-
%(<nav id="#{id}" class="pagy-bootstrap-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id,
|
37
|
+
%(<nav id="#{id}" class="pagy-bootstrap-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
38
38
|
end
|
39
39
|
|
40
40
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
41
41
|
def pagy_bootstrap_combo_nav_js(pagy, id=pagy_id)
|
42
42
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
43
43
|
|
44
|
-
html = %(<nav id="#{id}" class="pagy-bootstrap-combo-nav-js pagination" role="navigation" aria-label="pager">)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
53
|
-
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
54
|
-
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
|
44
|
+
html = %(<nav id="#{id}" class="pagy-bootstrap-combo-nav-js pagination" role="navigation" aria-label="pager">) + %(<div class="btn-group" role="group">)
|
45
|
+
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
|
46
|
+
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
|
47
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" class="text-primary" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
48
|
+
html << %(<div class="pagy-combo-input btn btn-primary disabled" style="white-space: nowrap;">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
|
49
|
+
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
50
|
+
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
51
|
+
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
55
52
|
end
|
56
53
|
|
57
54
|
end
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -34,11 +34,11 @@ class Pagy
|
|
34
34
|
+ (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
|
35
35
|
: %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>)) \
|
36
36
|
+ '<ul class="pagination-list">' ),
|
37
|
-
'link' => %(<li>#{link.call(
|
38
|
-
'active' => %(<li>#{link.call(
|
37
|
+
'link' => %(<li>#{link.call(MARK, MARK, %(class="pagination-link" aria-label="goto page #{MARK}"))}</li>),
|
38
|
+
'active' => %(<li>#{link.call(MARK, MARK, %(class="pagination-link is-current" aria-current="page" aria-label="page #{MARK}"))}</li>),
|
39
39
|
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>),
|
40
40
|
'after' => '</ul>' }
|
41
|
-
%(<nav id="#{id}" class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>#{pagy_json_tag(:nav, id,
|
41
|
+
%(<nav id="#{id}" class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
42
42
|
end
|
43
43
|
|
44
44
|
# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
@@ -46,16 +46,14 @@ class Pagy
|
|
46
46
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
47
47
|
|
48
48
|
html = %(<nav id="#{id}" class="pagy-bulma-combo-nav-js" role="navigation" aria-label="pagination">) \
|
49
|
-
+
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
|
58
|
-
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
|
49
|
+
+ %(<div class="field is-grouped is-grouped-centered" role="group">)
|
50
|
+
html << (p_prev ? %(<p class="control">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}</p>)
|
51
|
+
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.prev')}</a></p>))
|
52
|
+
input = %(<input class="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; margin:0 0.3rem;">)
|
53
|
+
html << %(<div class="pagy-combo-input control level is-mobile">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
|
54
|
+
html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
|
55
|
+
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
|
56
|
+
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
59
57
|
end
|
60
58
|
|
61
59
|
end
|
@@ -30,30 +30,27 @@ class Pagy
|
|
30
30
|
tags = { 'before' => ( '<ul class="pagination">' \
|
31
31
|
+ (p_prev ? %(<li class="prev">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"')}</li>)
|
32
32
|
: %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>)) ),
|
33
|
-
'link' => %(<li>#{link.call(
|
33
|
+
'link' => %(<li>#{link.call(MARK)}</li>),
|
34
34
|
'active' => %(<li class="current">#{pagy.page}</li>),
|
35
35
|
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
|
36
36
|
'after' => ( (p_next ? %(<li class="next">#{link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next"')}</li>)
|
37
37
|
: %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>)) \
|
38
38
|
+ '</ul>' ) }
|
39
|
-
%(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>#{pagy_json_tag(:nav, id,
|
39
|
+
%(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
40
40
|
end
|
41
41
|
|
42
42
|
# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
43
43
|
def pagy_foundation_combo_nav_js(pagy, id=pagy_id)
|
44
44
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
45
45
|
|
46
|
-
html = %(<nav id="#{id}" class="pagy-foundation-combo-nav-js" role="navigation" aria-label="Pagination">)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
|
55
|
-
: %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
56
|
-
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
|
46
|
+
html = %(<nav id="#{id}" class="pagy-foundation-combo-nav-js" role="navigation" aria-label="Pagination">) + %(<div class="input-group">)
|
47
|
+
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"')
|
48
|
+
: %(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
|
49
|
+
input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1}rem; padding: 0 0.3rem; margin: 0 0.3rem;">)
|
50
|
+
html << %(<span class="input-group-label">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</span>)
|
51
|
+
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
|
52
|
+
: %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
53
|
+
html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
57
54
|
end
|
58
55
|
|
59
56
|
end
|
data/lib/pagy/extras/headers.rb
CHANGED
@@ -23,8 +23,8 @@ class Pagy
|
|
23
23
|
def pagy_headers_hash(pagy)
|
24
24
|
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
|
25
25
|
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }; rels['last'] = pagy.last unless countless
|
26
|
-
url_str = pagy_url_for(Frontend::
|
27
|
-
hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(Frontend::
|
26
|
+
url_str = pagy_url_for(Frontend::MARK, pagy, :url)
|
27
|
+
hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(Frontend::MARK, n.to_s)] if n}.compact] }
|
28
28
|
headers = pagy.vars[:headers]
|
29
29
|
hash[headers[:page]] = pagy.page if headers[:page]
|
30
30
|
hash[headers[:items]] = pagy.vars[:items] if headers[:items]
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -47,13 +47,16 @@ class Pagy
|
|
47
47
|
|
48
48
|
# Return the items selector HTML. For example "Show [20] items per page"
|
49
49
|
def pagy_items_selector_js(pagy, id=pagy_id)
|
50
|
-
p_vars
|
51
|
-
|
52
|
-
|
50
|
+
p_vars = pagy.vars
|
51
|
+
p_items = p_vars[:items]
|
52
|
+
p_vars[:items] = '--pagy.items--'
|
53
|
+
links = pagy_links(pagy_link_proc(pagy))
|
53
54
|
p_vars[:items] = p_items # restore the items
|
55
|
+
|
56
|
+
html = EMPTY + %(<span id="#{id}">)
|
54
57
|
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;">)
|
55
|
-
html << %(#{pagy_t('pagy.items_selector_js', item_name: pagy_t(
|
56
|
-
html << %(</span>#{pagy_json_tag(:items_selector, id,
|
58
|
+
html << %(#{pagy_t('pagy.items_selector_js', item_name: pagy_t(p_vars[:i18n_key], count: p_items), items_input: input, count: p_items)})
|
59
|
+
html << %(</span>#{pagy_json_tag(:items_selector, id, pagy.from, links)})
|
57
60
|
end
|
58
61
|
|
59
62
|
end
|
@@ -29,13 +29,13 @@ class Pagy
|
|
29
29
|
tags = { 'before' => ( '<ul class="pagination">' \
|
30
30
|
+ (p_prev ? %(<li class="waves-effect prev">#{link.call(p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"')}</li>)
|
31
31
|
: %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>)) ),
|
32
|
-
'link' => %(<li class="waves-effect">#{
|
33
|
-
'active' => %(<li class="active">#{
|
32
|
+
'link' => %(<li class="waves-effect">#{mark = link.call(MARK)}</li>),
|
33
|
+
'active' => %(<li class="active">#{mark}</li>),
|
34
34
|
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>),
|
35
35
|
'after' => ( (p_next ? %(<li class="waves-effect next">#{link.call(p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"')}</li>)
|
36
36
|
: %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>)) \
|
37
37
|
+ '</ul>' ) }
|
38
|
-
%(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>#{pagy_json_tag(:nav, id,
|
38
|
+
%(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
39
39
|
end
|
40
40
|
|
41
41
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
@@ -43,18 +43,16 @@ class Pagy
|
|
43
43
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
44
44
|
|
45
45
|
html = %(<div id="#{id}" class="pagy-materialize-combo-nav-js pagination" role="navigation" aria-label="pager">) \
|
46
|
-
+
|
47
|
-
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
48
|
-
html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
|
46
|
+
+ %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
|
49
47
|
html << '<ul class="pagination" style="margin: 0px;">'
|
50
48
|
li_style = 'style="vertical-align: middle;"'
|
51
49
|
html << (p_prev ? %(<li class="waves-effect prev" #{li_style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
52
|
-
|
50
|
+
: %(<li class="prev disabled" #{li_style}><a href="#"><i class="material-icons">chevron_left</i></a></li>))
|
53
51
|
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
54
52
|
html << %(<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
|
55
53
|
html << (p_next ? %(<li class="waves-effect next" #{li_style}>#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
56
|
-
|
57
|
-
html << %(</ul></div>#{pagy_json_tag(:combo_nav, id,
|
54
|
+
: %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
55
|
+
html << %(</ul></div>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
58
56
|
end
|
59
57
|
|
60
58
|
end
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -12,28 +12,26 @@ class Pagy
|
|
12
12
|
link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
|
13
13
|
tags = { 'before' => p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
14
14
|
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ),
|
15
|
-
'link' => %(<span class="page">#{link.call(
|
15
|
+
'link' => %(<span class="page">#{link.call(MARK)}</span> ),
|
16
16
|
'active' => %(<span class="page active">#{pagy.page}</span> ),
|
17
17
|
'gap' => %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ),
|
18
18
|
'after' => p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
19
19
|
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>) }
|
20
|
-
%(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id,
|
20
|
+
%(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
21
21
|
end
|
22
22
|
|
23
23
|
# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
24
24
|
def pagy_combo_nav_js(pagy, id=pagy_id)
|
25
25
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
26
26
|
|
27
|
-
html = %(<nav id="#{id}" class="pagy-combo-nav-js-js pagination" role="navigation" aria-label="pager">)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
36
|
-
html << %(</nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
|
27
|
+
html = EMPTY + %(<nav id="#{id}" class="pagy-combo-nav-js-js pagination" role="navigation" aria-label="pager">)
|
28
|
+
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
29
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
30
|
+
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;">)
|
31
|
+
html << %(<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</span> )
|
32
|
+
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
33
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
34
|
+
html << %(</nav>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
37
35
|
end
|
38
36
|
|
39
37
|
end
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -29,28 +29,26 @@ class Pagy
|
|
29
29
|
link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
|
30
30
|
tags = { 'before' => (p_prev ? %(#{link.call(p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"')})
|
31
31
|
: %(<div class="item disabled"><i class="left small chevron icon"></i></div>)),
|
32
|
-
'link' => %(#{link.call(
|
32
|
+
'link' => %(#{link.call(MARK)}),
|
33
33
|
'active' => %(<a class="item active">#{pagy.page}</a>),
|
34
34
|
'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
|
35
35
|
'after' => (p_next ? %(#{link.call(p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"')})
|
36
36
|
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>)) }
|
37
|
-
%(<div id="#{id}" class="pagy-semantic-nav-js ui pagination menu" role="navigation" aria-label="pager"></div>#{pagy_json_tag(:nav, id,
|
37
|
+
%(<div id="#{id}" class="pagy-semantic-nav-js ui pagination menu" role="navigation" aria-label="pager"></div>#{pagy_json_tag(:nav, id, tags, pagy.sequels)})
|
38
38
|
end
|
39
39
|
|
40
40
|
# Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
41
41
|
def pagy_semantic_combo_nav_js(pagy, id=pagy_id)
|
42
42
|
link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
|
43
43
|
|
44
|
-
html = %(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
53
|
-
html << %(</div>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
|
44
|
+
html = EMPTY + %(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">)
|
45
|
+
html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
46
|
+
: %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
|
47
|
+
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; margin: 0 0.3rem">)
|
48
|
+
html << %(<div class="pagy-combo-input item">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div> )
|
49
|
+
html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
50
|
+
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
51
|
+
html << %(</div>#{pagy_json_tag(:combo_nav, id, p_page, pagy_links(link))})
|
54
52
|
end
|
55
53
|
|
56
54
|
end
|
data/lib/pagy/extras/shared.rb
CHANGED
@@ -26,23 +26,30 @@ class Pagy
|
|
26
26
|
module Frontend
|
27
27
|
|
28
28
|
if defined?(Oj)
|
29
|
-
# returns a script tag with the JSON-serialized args generated with the faster oj gem
|
29
|
+
# it returns a script tag with the JSON-serialized args generated with the faster oj gem
|
30
30
|
def pagy_json_tag(*args)
|
31
31
|
%(<script type="application/json" class="pagy-json">#{Oj.dump(args, mode: :strict)}</script>)
|
32
32
|
end
|
33
33
|
else
|
34
34
|
require 'json'
|
35
|
-
# returns a script tag with the JSON-serialized args generated with the slower to_json
|
35
|
+
# it returns a script tag with the JSON-serialized args generated with the slower to_json
|
36
36
|
def pagy_json_tag(*args)
|
37
37
|
%(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
# returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags
|
41
|
+
# it returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags
|
42
42
|
def pagy_id
|
43
43
|
"pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
|
44
44
|
end
|
45
45
|
|
46
|
+
# it return the links hash to used by pagy.js
|
47
|
+
def pagy_links(link)
|
48
|
+
links = { 'standard' => link.call(MARK, '', 'style="display: none;"') }
|
49
|
+
links['trimmed'] = link.call(1, '', 'style="display: none;"') if defined?(TRIM)
|
50
|
+
links
|
51
|
+
end
|
52
|
+
|
46
53
|
end
|
47
54
|
|
48
55
|
end
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -12,14 +12,14 @@ class Pagy
|
|
12
12
|
alias_method :pagy_link_proc_without_trim, :pagy_link_proc
|
13
13
|
def pagy_link_proc_with_trim(pagy, link_extra='')
|
14
14
|
p_prev, p_next, p_vars = pagy.prev, pagy.next, pagy.vars
|
15
|
-
|
16
|
-
page1_url = pagy_trim_url(
|
15
|
+
marked_url = pagy_url_for(MARK, pagy)
|
16
|
+
page1_url = pagy_trim_url(marked_url, "#{p_vars[:page_param]}=#{MARK}")
|
17
17
|
page1_link = %(<a href="#{page1_url}" #{p_vars[:link_extra]} #{link_extra})
|
18
|
-
a, b = %(<a href="#{
|
18
|
+
a, b = %(<a href="#{marked_url}" #{p_vars[:link_extra]} #{link_extra}).split(MARK, 2)
|
19
19
|
lambda{|n, text=n, extra=''| start = n.to_i == 1 ? page1_link : "#{a}#{n}#{b}"
|
20
20
|
"#{start}#{ if n == p_prev ; ' rel="prev"'
|
21
21
|
elsif n == p_next ; ' rel="next"'
|
22
|
-
else '' end } #{extra}>#{text}</a>"
|
22
|
+
else '' end } #{extra}>#{text}</a>"}
|
23
23
|
end
|
24
24
|
alias_method :pagy_link_proc, :pagy_link_proc_with_trim
|
25
25
|
|
data/lib/pagy/frontend.rb
CHANGED
@@ -27,8 +27,8 @@ class Pagy
|
|
27
27
|
|
28
28
|
include Helpers
|
29
29
|
|
30
|
-
# EMPTY + 'string' is almost as fast as +'string' but is also 1.9 compatible
|
31
|
-
|
30
|
+
EMPTY = '' # EMPTY + 'string' is almost as fast as +'string' but is also 1.9 compatible
|
31
|
+
MARK = '--pagy.page--' # string used for search and replace, hardcoded also in the pagy.js file
|
32
32
|
|
33
33
|
# Generic pagination: it returns the html with the series of links to the pages
|
34
34
|
def pagy_nav(pagy)
|
@@ -55,16 +55,14 @@ class Pagy
|
|
55
55
|
pagy_t(path, item_name: pagy_t(pagy.vars[:i18n_key], count: count), count: count, from: pagy.from, to: pagy.to)
|
56
56
|
end
|
57
57
|
|
58
|
-
MARKER = "-pagy-#{'pagy'.hash}-"
|
59
|
-
|
60
58
|
# Returns a performance optimized proc to generate the HTML links
|
61
59
|
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
|
62
60
|
def pagy_link_proc(pagy, link_extra='')
|
63
61
|
p_prev, p_next = pagy.prev, pagy.next
|
64
|
-
a, b = %(<a href="#{pagy_url_for(
|
62
|
+
a, b = %(<a href="#{pagy_url_for(MARK, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(MARK, 2)
|
65
63
|
lambda {|n, text=n, extra=''| "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'
|
66
64
|
elsif n == p_next ; ' rel="next"'
|
67
|
-
else '' end } #{extra}>#{text}</a>"
|
65
|
+
else '' end } #{extra}>#{text}</a>"}
|
68
66
|
end
|
69
67
|
|
70
68
|
# Similar to I18n.t: just ~18x faster using ~10x less memory
|
data/lib/pagy.rb
CHANGED
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: 3.
|
4
|
+
version: 3.1.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: 2019-
|
11
|
+
date: 2019-05-08 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,
|