pagy 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +26 -21
- data/lib/javascripts/pagy.js +31 -21
- data/lib/pagy.rb +3 -3
- data/lib/pagy/countless.rb +1 -0
- data/lib/pagy/extras/bootstrap.rb +11 -8
- data/lib/pagy/extras/bulma.rb +11 -8
- data/lib/pagy/extras/foundation.rb +11 -8
- data/lib/pagy/extras/items.rb +5 -3
- data/lib/pagy/extras/materialize.rb +11 -8
- data/lib/pagy/extras/navs.rb +2 -44
- data/lib/pagy/extras/plain.rb +51 -0
- data/lib/pagy/extras/semantic.rb +11 -8
- data/lib/pagy/extras/shared.rb +15 -0
- data/lib/pagy/extras/support.rb +54 -0
- data/lib/templates/{nav_bootstrap.html.erb → bootstrap_nav.html.erb} +1 -1
- data/lib/templates/{nav_bootstrap.html.haml → bootstrap_nav.html.haml} +1 -1
- data/lib/templates/{nav_bootstrap.html.slim → bootstrap_nav.html.slim} +1 -1
- data/lib/templates/{nav_bulma.html.erb → bulma_nav.html.erb} +1 -1
- data/lib/templates/{nav_bulma.html.haml → bulma_nav.html.haml} +1 -1
- data/lib/templates/{nav_bulma.html.slim → bulma_nav.html.slim} +1 -1
- data/lib/templates/{nav_foundation.html.erb → foundation_nav.html.erb} +1 -1
- data/lib/templates/{nav_foundation.html.haml → foundation_nav.html.haml} +1 -1
- data/lib/templates/{nav_foundation.html.slim → foundation_nav.html.slim} +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 388922f4fd6c86c42945097ef08078bfe351e8b61a380ef68c58c583509ee4ae
|
4
|
+
data.tar.gz: 775b71455d808039150ac6285a15c8fd9574609df2a43399f465d71fed853cff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a98e301538f52ebd068f137ff5bf7850ab713a28e8636b399753b8a70022d076885e3ac93216c7da255fb3d4269f8bd3c48990243e27db31ccc08f841af750b2
|
7
|
+
data.tar.gz: d22e17a6910d0e1dbc31f184a69a9dae63a25932c7d29d2f9dc1d291d9ed5fe58c641bba96ae9feea2e312cd06e478643705688916d8b26c3395937a7fe0442c
|
data/lib/config/pagy.rb
CHANGED
@@ -8,69 +8,74 @@
|
|
8
8
|
|
9
9
|
# Backend Extras
|
10
10
|
|
11
|
-
# Array: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
|
11
|
+
# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
|
12
12
|
# See https://ddnexus.github.io/pagy/extras/array
|
13
13
|
# require 'pagy/extras/array'
|
14
14
|
|
15
|
-
# Countless: Paginate without any count, saving one query per rendering
|
15
|
+
# Countless extra: Paginate without any count, saving one query per rendering
|
16
16
|
# See https://ddnexus.github.io/pagy/extras/countless
|
17
17
|
# require 'pagy/extras/countless'
|
18
|
+
# Pagy::VARS[:cycle] = false # default
|
18
19
|
|
19
|
-
# Elasticsearch Rails: Paginate `ElasticsearchRails::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
|
20
|
+
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
|
20
21
|
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
21
22
|
# require 'pagy/extras/elasticsearch_rails'
|
22
23
|
|
23
|
-
# Searchkick: Paginate `Searchkick::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
|
24
|
+
# Searchkick extra: Paginate `Searchkick::Results` objects efficiently, avoiding expensive object-wrapping and without overriding.
|
24
25
|
# See https://ddnexus.github.io/pagy/extras/searchkick
|
25
26
|
# require 'pagy/extras/searchkick'
|
26
27
|
|
27
28
|
|
28
29
|
# Frontend Extras
|
29
30
|
|
30
|
-
#
|
31
|
-
# Notice: the other frontend extras add their own framework-styled versions,
|
32
|
-
# so require this extra only if you need the plain unstyled version
|
33
|
-
# See https://ddnexus.github.io/pagy/extras/navs
|
34
|
-
# require 'pagy/extras/navs'
|
35
|
-
|
36
|
-
# Bootstrap: Nav, responsive and compact helpers and templates for Bootstrap pagination
|
31
|
+
# Bootstrap extra: Add nav, responsive and compact helpers and templates for Bootstrap pagination
|
37
32
|
# See https://ddnexus.github.io/pagy/extras/bootstrap
|
38
33
|
# require 'pagy/extras/bootstrap'
|
39
34
|
|
40
|
-
# Bulma:
|
35
|
+
# Bulma extra: Add nav, responsive and compact helpers and templates for Bulma pagination
|
41
36
|
# See https://ddnexus.github.io/pagy/extras/bulma
|
42
37
|
# require 'pagy/extras/bulma'
|
43
38
|
|
44
|
-
# Foundation:
|
39
|
+
# Foundation extra: Add nav, responsive and compact helpers and templates for Foundation pagination
|
45
40
|
# See https://ddnexus.github.io/pagy/extras/foundation
|
46
41
|
# require 'pagy/extras/foundation'
|
47
42
|
|
48
|
-
# Materialize: Nav, responsive and compact helpers for Materialize pagination
|
43
|
+
# Materialize extra: Nav, responsive and compact helpers for Materialize pagination
|
49
44
|
# See https://ddnexus.github.io/pagy/extras/materialize
|
50
45
|
# require 'pagy/extras/materialize'
|
51
46
|
|
52
|
-
#
|
47
|
+
# Plain extra: Add responsive and compact nav plain helpers
|
48
|
+
# Notice: the other frontend extras add their own framework-styled versions,
|
49
|
+
# so require this extra only if you need the plain unstyled version
|
50
|
+
# See https://ddnexus.github.io/pagy/extras/plain
|
51
|
+
# require 'pagy/extras/plain'
|
52
|
+
|
53
|
+
# Semantic extra: Nav, responsive and compact helpers for Semantic UI pagination
|
53
54
|
# See https://ddnexus.github.io/pagy/extras/semantic
|
54
55
|
# require 'pagy/extras/semantic'
|
55
56
|
|
56
57
|
# Breakpoints var used by the responsive nav helpers
|
57
|
-
# See https://ddnexus.github.io/pagy/extras/
|
58
|
+
# See https://ddnexus.github.io/pagy/extras/plain#breakpoints
|
58
59
|
# Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
|
59
60
|
|
60
61
|
|
61
62
|
# Feature Extras
|
62
63
|
|
63
|
-
#
|
64
|
+
# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination
|
65
|
+
# See https://ddnexus.github.io/pagy/extras/support
|
66
|
+
# require 'pagy/extras/support'
|
67
|
+
|
68
|
+
# Items extra: Allow the client to request a custom number of items per page with an optional selector UI
|
64
69
|
# See https://ddnexus.github.io/pagy/extras/items
|
65
70
|
# require 'pagy/extras/items'
|
66
71
|
# Pagy::VARS[:items_param] = :items # default
|
67
72
|
# Pagy::VARS[:max_items] = 100 # default
|
68
73
|
|
69
|
-
# Overflow: Allow for easy handling of overflowing pages
|
74
|
+
# Overflow extra: Allow for easy handling of overflowing pages
|
70
75
|
# See https://ddnexus.github.io/pagy/extras/overflow
|
71
76
|
# Pagy::VARS[:overflow] = :last_page # default (other options: :empty_page and :exception)
|
72
77
|
|
73
|
-
# Trim: Remove the page=1 param from links
|
78
|
+
# Trim extra: Remove the page=1 param from links
|
74
79
|
# See https://ddnexus.github.io/pagy/extras/trim
|
75
80
|
# require 'pagy/extras/trim'
|
76
81
|
|
@@ -106,7 +111,7 @@
|
|
106
111
|
|
107
112
|
# I18n
|
108
113
|
|
109
|
-
# I18n
|
114
|
+
# I18n faster internal pagy implementation (does not use the I18n gem)
|
110
115
|
# Use only for single language apps that don't need dynamic translation between multiple languages
|
111
116
|
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
112
117
|
# Notice: Do not use any of the following lines if you use the i18n extra below
|
@@ -114,7 +119,7 @@
|
|
114
119
|
# Pagy::Frontend::I18N.load(file:'path/to/dictionary.yml', language:'en') # load a custom 'en' file
|
115
120
|
# Pagy::Frontend::I18N[:plural] = -> (count) {(['zero', 'one'][count] || 'other')} # default
|
116
121
|
|
117
|
-
# I18n: Use the `I18n` gem instead of the pagy implementation
|
122
|
+
# I18n extra: Use the `I18n` gem instead of the pagy implementation
|
118
123
|
# (slower but allows dynamic translation between multiple languages)
|
119
124
|
# See https://ddnexus.github.io/pagy/extras/i18n
|
120
125
|
# require 'pagy/extras/i18n'
|
data/lib/javascripts/pagy.js
CHANGED
@@ -14,28 +14,28 @@ Pagy.addInputEventListeners = function(input, handler){
|
|
14
14
|
};
|
15
15
|
|
16
16
|
Pagy.compact = function(id, marker, page, trim){
|
17
|
-
var
|
18
|
-
input
|
19
|
-
link
|
20
|
-
linkP1
|
21
|
-
go
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
var pagyEl = document.getElementById(id),
|
18
|
+
input = pagyEl.getElementsByTagName('input')[0],
|
19
|
+
link = pagyEl.getElementsByTagName('a')[0],
|
20
|
+
linkP1 = pagyEl.getElementsByTagName('a')[1],
|
21
|
+
go = function(){
|
22
|
+
if (page !== input.value) {
|
23
|
+
if (trim === true && input.value === '1') { linkP1.click() }
|
24
|
+
else {
|
25
|
+
var href = link.getAttribute('href').replace(marker, input.value);
|
26
|
+
link.setAttribute('href', href);
|
27
|
+
link.click();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
};
|
31
31
|
Pagy.addInputEventListeners(input, go);
|
32
32
|
};
|
33
33
|
|
34
34
|
Pagy.items = function(id, marker, from){
|
35
|
-
var
|
36
|
-
input =
|
35
|
+
var pagyEl = document.getElementById(id),
|
36
|
+
input = pagyEl.getElementsByTagName('input')[0],
|
37
37
|
current = input.value,
|
38
|
-
link =
|
38
|
+
link = pagyEl.getElementsByTagName('a')[0],
|
39
39
|
go = function(){
|
40
40
|
var items = input.value;
|
41
41
|
if (current !== items) {
|
@@ -49,18 +49,18 @@ Pagy.items = function(id, marker, from){
|
|
49
49
|
};
|
50
50
|
|
51
51
|
Pagy.responsive = function(id, tags, widths, series){
|
52
|
-
var
|
53
|
-
pagyParent =
|
52
|
+
var pagyEl = document.getElementById(id),
|
53
|
+
pagyParent = pagyEl.parentElement,
|
54
54
|
lastWidth = undefined,
|
55
55
|
render = function(){
|
56
56
|
var parentWidth = parseInt(pagyParent.clientWidth),
|
57
57
|
width = widths.find(function(w){return parentWidth > w});
|
58
58
|
if (width !== lastWidth) {
|
59
|
-
while (
|
59
|
+
while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
|
60
60
|
var html = tags['before'];
|
61
61
|
series[width].forEach(function(item){html += tags[item]});
|
62
62
|
html += tags['after'];
|
63
|
-
|
63
|
+
pagyEl.insertAdjacentHTML('beforeend', html);
|
64
64
|
lastWidth = width;
|
65
65
|
}
|
66
66
|
}.bind(this);
|
@@ -73,6 +73,12 @@ Pagy.init = function(){
|
|
73
73
|
// we need to explicitly remove the window listeners because turbolinks persists the window object
|
74
74
|
Pagy.windowListeners.forEach(function(l){window.removeEventListener('resize', l, true)});
|
75
75
|
Pagy.windowListeners = [];
|
76
|
+
var json = document.getElementsByClassName('pagy-json');
|
77
|
+
for (var i = 0, len = json.length; i < len; i++) {
|
78
|
+
var args = JSON.parse(json[i].innerHTML);
|
79
|
+
Pagy[args.shift()].apply(null, args);
|
80
|
+
}
|
81
|
+
// Support for legacy overridden helpers. It will be removed in 2.0
|
76
82
|
['compact', 'items', 'responsive'].forEach(function(name){
|
77
83
|
var json = document.getElementsByClassName("pagy-"+name+"-json");
|
78
84
|
for (var i = 0, len = json.length; i < len; i++) {
|
@@ -80,3 +86,7 @@ Pagy.init = function(){
|
|
80
86
|
}
|
81
87
|
})
|
82
88
|
};
|
89
|
+
|
90
|
+
function PagyInit(){}
|
91
|
+
|
92
|
+
Pagy.applyInit = function(name, payload){ PagyInit[name].apply(null, [payload]) };
|
data/lib/pagy.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
class Pagy ; VERSION = '1.
|
6
|
+
class Pagy ; VERSION = '1.2.0'
|
7
7
|
|
8
8
|
class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
|
9
9
|
|
@@ -11,7 +11,7 @@ class Pagy ; VERSION = '1.1.0'
|
|
11
11
|
def self.root; Pathname.new(__FILE__).dirname end
|
12
12
|
|
13
13
|
# default vars
|
14
|
-
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name' }
|
14
|
+
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name', cycle: false }
|
15
15
|
|
16
16
|
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
|
17
17
|
|
@@ -29,7 +29,7 @@ class Pagy ; VERSION = '1.1.0'
|
|
29
29
|
@from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
|
30
30
|
@to = @count == 0 ? 0 : @offset + @items - @outset # page ends to item
|
31
31
|
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
32
|
-
@next =
|
32
|
+
@next = @page == @last ? (1 if @vars[:cycle]) : @page+1 # nil if no next page, 1 if :cycle
|
33
33
|
end
|
34
34
|
|
35
35
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
data/lib/pagy/countless.rb
CHANGED
@@ -23,6 +23,7 @@ class Pagy
|
|
23
23
|
@to = items == 0 ? 0 : @offset + @items - @outset # page ends to item
|
24
24
|
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
25
25
|
@next = (@page+1 unless @page == @last) # nil if no next page
|
26
|
+
@next = (@page == @last ? (1 if @vars[:cycle]) : @page+1) # nil if no next page
|
26
27
|
self
|
27
28
|
end
|
28
29
|
|
@@ -7,7 +7,7 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
10
|
-
def
|
10
|
+
def pagy_bootstrap_nav(pagy)
|
11
11
|
html, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
|
12
12
|
|
13
13
|
html << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
@@ -20,15 +20,16 @@ class Pagy
|
|
20
20
|
end
|
21
21
|
html << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
22
22
|
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
|
23
|
-
%(<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
|
23
|
+
%(<nav class="pagy-nav-bootstrap pagy-bootstrap-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
|
24
24
|
end
|
25
|
+
Pagy.deprecate self, :pagy_nav_bootstrap, :pagy_bootstrap_nav
|
25
26
|
|
26
27
|
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
|
27
28
|
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
28
|
-
def
|
29
|
+
def pagy_bootstrap_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
29
30
|
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
30
31
|
|
31
|
-
html << %(<nav id="
|
32
|
+
html << %(<nav id="#{id}" class="pagy-nav-compact-bootstrap pagy-bootstrap-compact-nav pagination" role="navigation" aria-label="pager">)
|
32
33
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
33
34
|
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
34
35
|
html << %(<div class="btn-group" role="group">)
|
@@ -38,12 +39,13 @@ class Pagy
|
|
38
39
|
html << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
|
39
40
|
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
40
41
|
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
41
|
-
html << %(</div></nav
|
42
|
+
html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
42
43
|
end
|
44
|
+
Pagy.deprecate self, :pagy_nav_compact_bootstrap, :pagy_bootstrap_compact_nav
|
43
45
|
|
44
46
|
# Responsive pagination for bootstrap: it returns the html with the series of links to the pages
|
45
47
|
# rendered by the Pagy.responsive javascript
|
46
|
-
def
|
48
|
+
def pagy_bootstrap_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
47
49
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
|
48
50
|
|
49
51
|
tags['before'] = +'<ul class="pagination">'
|
@@ -58,9 +60,10 @@ class Pagy
|
|
58
60
|
tags['after'] = +(p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
59
61
|
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
|
60
62
|
tags['after'] << '</ul>'
|
61
|
-
script =
|
62
|
-
%(<nav id="
|
63
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
64
|
+
%(<nav id="#{id}" class="pagy-nav-responsive-bootstrap pagy-bootstrap-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
|
63
65
|
end
|
66
|
+
Pagy.deprecate self, :pagy_nav_responsive_bootstrap, :pagy_bootstrap_responsive_nav
|
64
67
|
|
65
68
|
end
|
66
69
|
end
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -7,7 +7,7 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for Bulma: it returns the html with the series of links to the pages
|
10
|
-
def
|
10
|
+
def pagy_bulma_nav(pagy)
|
11
11
|
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
12
12
|
|
13
13
|
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -22,15 +22,16 @@ class Pagy
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
html << '</ul>'
|
25
|
-
%(<nav class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
|
25
|
+
%(<nav class="pagy-nav-bulma pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
|
26
26
|
end
|
27
|
+
Pagy.deprecate self, :pagy_nav_bulma, :pagy_bulma_nav
|
27
28
|
|
28
29
|
# Compact pagination for Bulma: it returns the html with the series of links to the pages
|
29
30
|
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
30
|
-
def
|
31
|
+
def pagy_bulma_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
31
32
|
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
32
33
|
|
33
|
-
html << %(<nav id="
|
34
|
+
html << %(<nav id="#{id}" class="pagy-nav-compact-bulma pagy-bulma-compact-nav" role="navigation" aria-label="pagination">)
|
34
35
|
html << link.call(MARKER, '', 'style="display: none;"')
|
35
36
|
(html << link.call(1, '', %(style="display: none;"))) if defined?(TRIM)
|
36
37
|
html << %(<div class="field is-grouped is-grouped-centered" role="group">)
|
@@ -40,12 +41,13 @@ class Pagy
|
|
40
41
|
html << %(<div class="pagy-compact-input control level is-mobile">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
|
41
42
|
html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
|
42
43
|
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
|
43
|
-
html << %(</div></nav
|
44
|
+
html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
44
45
|
end
|
46
|
+
Pagy.deprecate self, :pagy_nav_compact_bulma, :pagy_bulma_compact_nav
|
45
47
|
|
46
48
|
# Responsive pagination for Bulma: it returns the html with the series of links to the pages
|
47
49
|
# rendered by the Pagy.responsive javascript
|
48
|
-
def
|
50
|
+
def pagy_bulma_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
49
51
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
50
52
|
|
51
53
|
tags['before'] = +(p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -60,9 +62,10 @@ class Pagy
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
tags['after'] = '</ul>'
|
63
|
-
script =
|
64
|
-
%(<nav id="
|
65
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
66
|
+
%(<nav id="#{id}" class="pagy-nav-responsive-bulma pagy-bulma-responsive-nav pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
|
65
67
|
end
|
68
|
+
Pagy.deprecate self, :pagy_nav_responsive_bulma, :pagy_bulma_responsive_nav
|
66
69
|
|
67
70
|
end
|
68
71
|
end
|
@@ -7,7 +7,7 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for Foundation: it returns the html with the series of links to the pages
|
10
|
-
def
|
10
|
+
def pagy_foundation_nav(pagy)
|
11
11
|
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
12
12
|
|
13
13
|
html << (p_prev ? %(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
@@ -20,15 +20,16 @@ class Pagy
|
|
20
20
|
end
|
21
21
|
html << (p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
22
22
|
: %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
|
23
|
-
%(<nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
|
23
|
+
%(<nav class="pagy-nav-foundation pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
|
24
24
|
end
|
25
|
+
Pagy.deprecate self, :pagy_nav_foundation, :pagy_foundation_nav
|
25
26
|
|
26
27
|
# Compact pagination for Foundation: it returns the html with the series of links to the pages
|
27
28
|
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
28
|
-
def
|
29
|
+
def pagy_foundation_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
29
30
|
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
30
31
|
|
31
|
-
html << %(<nav id="
|
32
|
+
html << %(<nav id="#{id}" class="pagy-nav-compact-foundation pagy-foundation-compact-nav" role="navigation" aria-label="Pagination">)
|
32
33
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
33
34
|
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
34
35
|
html << %(<div class="input-group">)
|
@@ -38,12 +39,13 @@ class Pagy
|
|
38
39
|
html << %(<span class="input-group-label">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</span>)
|
39
40
|
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
|
40
41
|
: %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
41
|
-
html << %(</div></nav
|
42
|
+
html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
42
43
|
end
|
44
|
+
Pagy.deprecate self, :pagy_nav_compact_foundation, :pagy_foundation_compact_nav
|
43
45
|
|
44
46
|
# Responsive pagination for Foundation: it returns the html with the series of links to the pages
|
45
47
|
# rendered by the Pagy.responsive javascript
|
46
|
-
def
|
48
|
+
def pagy_foundation_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
47
49
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
48
50
|
|
49
51
|
tags['before'] = +'<ul class="pagination">'
|
@@ -58,9 +60,10 @@ class Pagy
|
|
58
60
|
tags['after'] = +(p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
59
61
|
: %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
|
60
62
|
tags['after'] << '</ul>'
|
61
|
-
script =
|
62
|
-
%(<nav id="
|
63
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
64
|
+
%(<nav id="#{id}" class="pagy-nav-responsive-foundation pagy-foundation-responsive-nav" aria-label="Pagination"></nav>#{script})
|
63
65
|
end
|
66
|
+
Pagy.deprecate self, :pagy_nav_responsive_foundation, :pagy_foundation_responsive_nav
|
64
67
|
|
65
68
|
end
|
66
69
|
end
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'pagy/extras/shared'
|
5
|
+
|
4
6
|
class Pagy
|
5
7
|
|
6
8
|
# Default variables for this extra
|
@@ -44,14 +46,14 @@ class Pagy
|
|
44
46
|
alias_method :pagy_url_for, :pagy_url_for_with_items
|
45
47
|
|
46
48
|
# Return the items selector HTML. For example "Show [20] items per page"
|
47
|
-
def pagy_items_selector(pagy, id=caller(1,1)[0].hash)
|
49
|
+
def pagy_items_selector(pagy, id=caller(1,1)[0].hash.to_s)
|
48
50
|
pagy = pagy.clone; p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
|
49
51
|
|
50
|
-
html = +%(<span id="
|
52
|
+
html = +%(<span id="#{id}">)
|
51
53
|
html << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
|
52
54
|
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;">)
|
53
55
|
html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)})
|
54
|
-
html << %(</span
|
56
|
+
html << %(</span>#{pagy_json_tag(:items, id, MARKER, pagy.from)})
|
55
57
|
end
|
56
58
|
|
57
59
|
end
|
@@ -7,7 +7,7 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
10
|
-
def
|
10
|
+
def pagy_materialize_nav(pagy)
|
11
11
|
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
12
12
|
html << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
13
13
|
: %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
|
@@ -19,15 +19,16 @@ class Pagy
|
|
19
19
|
end
|
20
20
|
html << (p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
21
21
|
: %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
22
|
-
%(<div class="pagy-nav-materialize pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
|
22
|
+
%(<div class="pagy-nav-materialize pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
|
23
23
|
end
|
24
|
+
Pagy.deprecate self, :pagy_nav_materialize, :pagy_materialize_nav
|
24
25
|
|
25
26
|
# Compact pagination for materialize: it returns the html with the series of links to the pages
|
26
27
|
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
27
|
-
def
|
28
|
+
def pagy_materialize_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
28
29
|
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
29
30
|
|
30
|
-
html << %(<div id="
|
31
|
+
html << %(<div id="#{id}" class="pagy-nav-compact-materialize pagy-materialize-compact-nav pagination" role="navigation" aria-label="pager">)
|
31
32
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
32
33
|
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
33
34
|
html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
|
@@ -39,12 +40,13 @@ class Pagy
|
|
39
40
|
html << %(<div class="pagy-compact-input btn-flat" style="cursor: default; padding: 0px">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
|
40
41
|
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>)
|
41
42
|
: %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
42
|
-
html << %(</ul></div
|
43
|
+
html << %(</ul></div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
43
44
|
end
|
45
|
+
Pagy.deprecate self, :pagy_nav_compact_materialize, :pagy_materialize_compact_nav
|
44
46
|
|
45
47
|
# Responsive pagination for Materialize: it returns the html with the series of links to the pages
|
46
48
|
# rendered by the Pagy.responsive javascript
|
47
|
-
def
|
49
|
+
def pagy_materialize_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
48
50
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
49
51
|
|
50
52
|
tags['before'] = +'<ul class="pagination">'
|
@@ -59,9 +61,10 @@ class Pagy
|
|
59
61
|
tags['after'] = +(p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
60
62
|
: %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
61
63
|
tags['after'] << '</ul>'
|
62
|
-
script =
|
63
|
-
%(<div id="
|
64
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
65
|
+
%(<div id="#{id}" class="pagy-nav-responsive-materialize pagy-materialize-responsive-nav pagination" role="navigation" aria-label="pager"></div>#{script})
|
64
66
|
end
|
67
|
+
Pagy.deprecate self, :pagy_nav_responsive_materialize, :pagy_materialize_responsive_nav
|
65
68
|
|
66
69
|
end
|
67
70
|
end
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -1,46 +1,4 @@
|
|
1
|
-
|
2
|
-
# frozen_string_literal: true
|
1
|
+
Warning.warn %(WARNING: The "navs" extra is deprecated and will be removed in 2.0; please require "pagy/extras/plain" instead.\n)
|
3
2
|
|
4
|
-
require 'pagy/extras/
|
3
|
+
require 'pagy/extras/plain'
|
5
4
|
|
6
|
-
class Pagy
|
7
|
-
module Frontend
|
8
|
-
|
9
|
-
# Generic compact pagination: it returns the html with the series of links to the pages
|
10
|
-
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
11
|
-
def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
|
12
|
-
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
13
|
-
|
14
|
-
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
|
15
|
-
html << link.call(MARKER, '', %(style="display: none;" ))
|
16
|
-
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
17
|
-
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
18
|
-
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
19
|
-
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;">)
|
20
|
-
html << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</span> )
|
21
|
-
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
22
|
-
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
23
|
-
html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Generic responsive pagination: it returns the html with the series of links to the pages
|
27
|
-
# rendered by the Pagy.responsive javascript
|
28
|
-
def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
|
29
|
-
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
30
|
-
|
31
|
-
tags['before'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
32
|
-
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
33
|
-
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
34
|
-
tags[item.to_s] = if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
35
|
-
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
36
|
-
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
37
|
-
end
|
38
|
-
end
|
39
|
-
tags['after'] = (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
40
|
-
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
41
|
-
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
42
|
-
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/plain
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pagy/extras/shared'
|
5
|
+
|
6
|
+
class Pagy
|
7
|
+
module Frontend
|
8
|
+
|
9
|
+
# added alias for symmetry
|
10
|
+
alias :pagy_plain_nav :pagy_nav
|
11
|
+
|
12
|
+
# Plain compact pagination: it returns the html with the series of links to the pages
|
13
|
+
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
14
|
+
def pagy_plain_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
15
|
+
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
16
|
+
|
17
|
+
html << %(<nav id="#{id}" class="pagy-nav-compact pagy-plain-compact-nav pagination" role="navigation" aria-label="pager">)
|
18
|
+
html << link.call(MARKER, '', %(style="display: none;" ))
|
19
|
+
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
20
|
+
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
21
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
22
|
+
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;">)
|
23
|
+
html << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</span> )
|
24
|
+
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
25
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
26
|
+
html << %(</nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
27
|
+
end
|
28
|
+
Pagy.deprecate self, :pagy_nav_compact, :pagy_plain_compact_nav
|
29
|
+
|
30
|
+
# Plain responsive pagination: it returns the html with the series of links to the pages
|
31
|
+
# rendered by the Pagy.responsive javascript
|
32
|
+
def pagy_plain_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
33
|
+
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
34
|
+
|
35
|
+
tags['before'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
36
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
37
|
+
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
38
|
+
tags[item.to_s] = if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
39
|
+
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
40
|
+
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
41
|
+
end
|
42
|
+
end
|
43
|
+
tags['after'] = (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
44
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
45
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
46
|
+
%(<nav id="#{id}" class="pagy-nav-responsive pagy-plain-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
|
47
|
+
end
|
48
|
+
Pagy.deprecate self, :pagy_nav_responsive, :pagy_plain_responsive_nav
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -7,7 +7,7 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for semantic-ui: it returns the html with the series of links to the pages
|
10
|
-
def
|
10
|
+
def pagy_semantic_nav(pagy)
|
11
11
|
html, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
|
12
12
|
|
13
13
|
html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
@@ -20,15 +20,16 @@ class Pagy
|
|
20
20
|
end
|
21
21
|
html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
22
22
|
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
23
|
-
%(<div class="ui pagination menu" aria-label="pager">#{html}</div>)
|
23
|
+
%(<div class="pagy-nav-semantic pagy-semantic-nav ui pagination menu" aria-label="pager">#{html}</div>)
|
24
24
|
end
|
25
|
+
Pagy.deprecate self, :pagy_nav_semantic, :pagy_semantic_nav
|
25
26
|
|
26
27
|
# Compact pagination for semantic: it returns the html with the series of links to the pages
|
27
28
|
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
28
|
-
def
|
29
|
+
def pagy_semantic_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
29
30
|
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
|
30
31
|
|
31
|
-
html << %(<div id="
|
32
|
+
html << %(<div id="#{id}" class="pagy-nav-compact-semantic pagy-semantic-compact-nav ui compact menu" role="navigation" aria-label="pager">)
|
32
33
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
33
34
|
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
34
35
|
html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
@@ -37,12 +38,13 @@ class Pagy
|
|
37
38
|
html << %(<div class="pagy-compact-input item">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div> )
|
38
39
|
html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
39
40
|
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
40
|
-
html << %(</div
|
41
|
+
html << %(</div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
|
41
42
|
end
|
43
|
+
Pagy.deprecate self, :pagy_nav_compact_semantic, :pagy_semantic_compact_nav
|
42
44
|
|
43
45
|
# Responsive pagination for semantic: it returns the html with the series of links to the pages
|
44
46
|
# rendered by the Pagy.responsive javascript
|
45
|
-
def
|
47
|
+
def pagy_semantic_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
|
46
48
|
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.responsive
|
47
49
|
|
48
50
|
tags['before'] = (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
@@ -55,9 +57,10 @@ class Pagy
|
|
55
57
|
end
|
56
58
|
tags['after'] = (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
57
59
|
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
58
|
-
script =
|
59
|
-
%(<div id="
|
60
|
+
script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
|
61
|
+
%(<div id="#{id}" class="pagy-nav-responsive-semantic pagy-semantic-responsive-nav ui pagination menu" role="navigation" aria-label="pager"></div>#{script})
|
60
62
|
end
|
63
|
+
Pagy.deprecate self, :pagy_nav_responsive_semantic, :pagy_semantic_responsive_nav
|
61
64
|
|
62
65
|
end
|
63
66
|
end
|
data/lib/pagy/extras/shared.rb
CHANGED
@@ -27,4 +27,19 @@ class Pagy
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.deprecate(mod, old_meth, new_meth)
|
31
|
+
mod.send(:define_method, old_meth) do |pagy, id=caller(1,1)[0].hash.to_s|
|
32
|
+
Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
|
33
|
+
mod.instance_method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Frontend
|
38
|
+
|
39
|
+
def pagy_json_tag(*args)
|
40
|
+
%(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
30
45
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/support
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pagy/extras/shared'
|
5
|
+
|
6
|
+
class Pagy
|
7
|
+
|
8
|
+
def to_h
|
9
|
+
{ count: @count,
|
10
|
+
page: @page,
|
11
|
+
items: @items,
|
12
|
+
pages: @pages,
|
13
|
+
last: @last,
|
14
|
+
offset: @offset,
|
15
|
+
from: @from,
|
16
|
+
to: @to,
|
17
|
+
prev: @prev,
|
18
|
+
next: @next,
|
19
|
+
vars: @vars,
|
20
|
+
series: series }
|
21
|
+
end
|
22
|
+
|
23
|
+
module Frontend
|
24
|
+
|
25
|
+
def pagy_prev_url(pagy)
|
26
|
+
pagy_url_for(pagy.prev, pagy) if pagy.prev
|
27
|
+
end
|
28
|
+
|
29
|
+
def pagy_next_url(pagy)
|
30
|
+
pagy_url_for(pagy.next, pagy) if pagy.next
|
31
|
+
end
|
32
|
+
|
33
|
+
def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
|
34
|
+
pagy.prev ? %(<span class="page prev"><a href="#{pagy_prev_url(pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
|
35
|
+
: %(<span class="page prev disabled">#{text}</span>)
|
36
|
+
end
|
37
|
+
|
38
|
+
def pagy_next_link(pagy, text = pagy_t('pagy.nav.next'), link_extra = '')
|
39
|
+
pagy.next ? %(<span class="page next"><a href="#{pagy_next_url(pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
|
40
|
+
: %(<span class="page next disabled">#{text}</span>)
|
41
|
+
end
|
42
|
+
|
43
|
+
def pagy_serialized(pagy)
|
44
|
+
pagy.to_h.merge(prev_url: pagy_prev_url(pagy), next_url: pagy_next_url(pagy))
|
45
|
+
end
|
46
|
+
|
47
|
+
# Multi purpose JSON tag for custom javascript initialization
|
48
|
+
def pagy_apply_init_tag(pagy, function, payload=pagy_serialized(pagy))
|
49
|
+
pagy_json_tag(:applyInit, function, payload)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy, 'class="page-link"') -%>
|
9
|
-
<%# -%><nav aria-label="pager" class="pagy-nav-bootstrap pagination" role="navigation">
|
9
|
+
<%# -%><nav aria-label="pager" class="pagy-nav-bootstrap pagy-bootstrap-nav pagination" role="navigation">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
12
|
<% else -%> <li class="page-item prev disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.prev') %></a></li>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy, 'class="page-link"')
|
8
8
|
|
9
|
-
%nav.pagy-nav-bootstrap.pagination{"aria-label" => "pager", :role => "navigation"}
|
9
|
+
%nav.pagy-nav-bootstrap.pagy-bootstrap-nav.pagination{"aria-label" => "pager", :role => "navigation"}
|
10
10
|
|
11
11
|
%ul.pagination
|
12
12
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy) -%>
|
9
|
-
<%# -%><nav class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination">
|
9
|
+
<%# -%><nav class="pagy-nav-bulma pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">
|
10
10
|
<% if pagy.prev -%> <%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') %>
|
11
11
|
<% else -%> <a class="pagination-previous" disabled><%== pagy_t('pagy.nav.prev') %></a>
|
12
12
|
<% end -%>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy)
|
8
8
|
|
9
|
-
%nav.pagy-nav-bulma.pagination.is-centered{:role => "navigation", "aria-label" => "pagination"}
|
9
|
+
%nav.pagy-nav-bulma.pagy-bulma_nav.pagination.is-centered{:role => "navigation", "aria-label" => "pagination"}
|
10
10
|
|
11
11
|
- if pagy.prev
|
12
12
|
!= link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy)
|
8
8
|
|
9
|
-
nav.pagy-nav-bulma.pagination.is-centered role="navigation" aria-label="pagination"
|
9
|
+
nav.pagy-nav-bulma.pagy-bulma-nav.pagination.is-centered role="navigation" aria-label="pagination"
|
10
10
|
|
11
11
|
- if pagy.prev
|
12
12
|
== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy) -%>
|
9
|
-
<%# -%><nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination">
|
9
|
+
<%# -%><nav class="pagy-nav-foundation pagy-foundation-nav" role="navigation" aria-label="Pagination">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
12
|
<% else -%> <li class="prev disabled"><%== pagy_t('pagy.nav.prev') %></li>
|
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: 1.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2018-12-03 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,
|
@@ -48,23 +48,25 @@ files:
|
|
48
48
|
- lib/pagy/extras/materialize.rb
|
49
49
|
- lib/pagy/extras/navs.rb
|
50
50
|
- lib/pagy/extras/overflow.rb
|
51
|
+
- lib/pagy/extras/plain.rb
|
51
52
|
- lib/pagy/extras/searchkick.rb
|
52
53
|
- lib/pagy/extras/semantic.rb
|
53
54
|
- lib/pagy/extras/shared.rb
|
55
|
+
- lib/pagy/extras/support.rb
|
54
56
|
- lib/pagy/extras/trim.rb
|
55
57
|
- lib/pagy/frontend.rb
|
58
|
+
- lib/templates/bootstrap_nav.html.erb
|
59
|
+
- lib/templates/bootstrap_nav.html.haml
|
60
|
+
- lib/templates/bootstrap_nav.html.slim
|
61
|
+
- lib/templates/bulma_nav.html.erb
|
62
|
+
- lib/templates/bulma_nav.html.haml
|
63
|
+
- lib/templates/bulma_nav.html.slim
|
64
|
+
- lib/templates/foundation_nav.html.erb
|
65
|
+
- lib/templates/foundation_nav.html.haml
|
66
|
+
- lib/templates/foundation_nav.html.slim
|
56
67
|
- lib/templates/nav.html.erb
|
57
68
|
- lib/templates/nav.html.haml
|
58
69
|
- lib/templates/nav.html.slim
|
59
|
-
- lib/templates/nav_bootstrap.html.erb
|
60
|
-
- lib/templates/nav_bootstrap.html.haml
|
61
|
-
- lib/templates/nav_bootstrap.html.slim
|
62
|
-
- lib/templates/nav_bulma.html.erb
|
63
|
-
- lib/templates/nav_bulma.html.haml
|
64
|
-
- lib/templates/nav_bulma.html.slim
|
65
|
-
- lib/templates/nav_foundation.html.erb
|
66
|
-
- lib/templates/nav_foundation.html.haml
|
67
|
-
- lib/templates/nav_foundation.html.slim
|
68
70
|
- pagy.gemspec
|
69
71
|
homepage: https://github.com/ddnexus/pagy
|
70
72
|
licenses:
|