pagy 4.3.0 → 4.4.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 +29 -24
- data/lib/javascripts/pagy.js +60 -56
- data/lib/pagy.rb +5 -3
- data/lib/pagy/backend.rb +1 -0
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/extras/arel.rb +1 -0
- data/lib/pagy/extras/array.rb +1 -0
- data/lib/pagy/extras/bootstrap.rb +16 -11
- data/lib/pagy/extras/bulma.rb +16 -11
- data/lib/pagy/extras/countless.rb +2 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +1 -0
- data/lib/pagy/extras/foundation.rb +16 -11
- data/lib/pagy/extras/headers.rb +3 -3
- data/lib/pagy/extras/items.rb +18 -34
- data/lib/pagy/extras/materialize.rb +17 -11
- data/lib/pagy/extras/metadata.rb +3 -2
- data/lib/pagy/extras/navs.rb +12 -8
- data/lib/pagy/extras/searchkick.rb +1 -0
- data/lib/pagy/extras/semantic.rb +17 -12
- data/lib/pagy/extras/shared.rb +4 -9
- data/lib/pagy/extras/standalone.rb +71 -0
- data/lib/pagy/extras/support.rb +12 -8
- data/lib/pagy/extras/trim.rb +5 -4
- data/lib/pagy/extras/uikit.rb +16 -11
- data/lib/pagy/frontend.rb +29 -18
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48e9fa30f5123b3b985a58c0f20e00803b8708662d25e4b8116f786264adf382
|
4
|
+
data.tar.gz: fd51c8bf8bb897c01382459c4ab1a6baf3e28c7c9437213652382cbf5d01b8f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073dd75676b37ba14baaccd30a58ce008e8d32dd8e1dfd8508bc02abf0f1d85bfe8a503a4790b4157cd8a36f3e8b1c89284ae3d83c0ea8cb6565e5e32a74985d
|
7
|
+
data.tar.gz: 449da76a99d14327a89fcc30fad843dc5581c8225fab8c5678aa72f9888b160ebbd09d6c1b6946d8bcd1002267803a72b97a28de7797ac1a0be28ece704475f6
|
data/lib/config/pagy.rb
CHANGED
@@ -1,10 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (4.
|
3
|
+
# Pagy initializer file (4.4.0)
|
4
4
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
5
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
6
|
|
7
7
|
|
8
|
+
# Pagy Variables
|
9
|
+
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
10
|
+
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
|
11
|
+
# per instance by just passing them to Pagy.new or the #pagy controller method
|
12
|
+
|
13
|
+
|
14
|
+
# Instance variables
|
15
|
+
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
16
|
+
# Pagy::VARS[:page] = 1 # default
|
17
|
+
# Pagy::VARS[:items] = 20 # default
|
18
|
+
# Pagy::VARS[:outset] = 0 # default
|
19
|
+
|
20
|
+
|
21
|
+
# Other Variables
|
22
|
+
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
23
|
+
# Pagy::VARS[:size] = [1,4,4,1] # default
|
24
|
+
# Pagy::VARS[:page_param] = :page # default
|
25
|
+
# Pagy::VARS[:params] = {} # default
|
26
|
+
# Pagy::VARS[:fragment] = '#fragment' # example
|
27
|
+
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
|
28
|
+
# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default
|
29
|
+
# Pagy::VARS[:cycle] = true # example
|
30
|
+
|
31
|
+
|
8
32
|
# Extras
|
9
33
|
# See https://ddnexus.github.io/pagy/extras
|
10
34
|
|
@@ -18,7 +42,6 @@
|
|
18
42
|
# Countless extra: Paginate without any count, saving one query per rendering
|
19
43
|
# See https://ddnexus.github.io/pagy/extras/countless
|
20
44
|
# require 'pagy/extras/countless'
|
21
|
-
# Pagy::VARS[:cycle] = false # default
|
22
45
|
|
23
46
|
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
24
47
|
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
@@ -87,6 +110,8 @@
|
|
87
110
|
# require 'pagy/extras/items'
|
88
111
|
# Pagy::VARS[:items_param] = :items # default
|
89
112
|
# Pagy::VARS[:max_items] = 100 # default
|
113
|
+
# set to false if you want to make :enable_items_extra an opt-in variable
|
114
|
+
# Pagy::VARS[:enable_items_extra] = false # default true
|
90
115
|
|
91
116
|
# Overflow extra: Allow for easy handling of overflowing pages
|
92
117
|
# See https://ddnexus.github.io/pagy/extras/overflow
|
@@ -105,28 +130,8 @@
|
|
105
130
|
# See https://ddnexus.github.io/pagy/extras/trim
|
106
131
|
# require 'pagy/extras/trim'
|
107
132
|
# after requiring it will trim by default
|
108
|
-
# set to false if you want to make :
|
109
|
-
# Pagy::VARS[:
|
110
|
-
|
111
|
-
|
112
|
-
# Pagy Variables
|
113
|
-
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
114
|
-
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
|
115
|
-
# per instance by just passing them to Pagy.new or the #pagy controller method
|
116
|
-
|
117
|
-
|
118
|
-
# Instance variables
|
119
|
-
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
120
|
-
# Pagy::VARS[:items] = 20 # default
|
121
|
-
|
122
|
-
|
123
|
-
# Other Variables
|
124
|
-
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
125
|
-
# Pagy::VARS[:size] = [1,4,4,1] # default
|
126
|
-
# Pagy::VARS[:page_param] = :page # default
|
127
|
-
# Pagy::VARS[:params] = {} # default
|
128
|
-
# Pagy::VARS[:anchor] = '#anchor' # example
|
129
|
-
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
|
133
|
+
# set to false if you want to make :enable_trim_extra an opt-in variable
|
134
|
+
# Pagy::VARS[:enable_trim_extra] = false # default true
|
130
135
|
|
131
136
|
|
132
137
|
# Rails
|
data/lib/javascripts/pagy.js
CHANGED
@@ -2,34 +2,35 @@
|
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
-
Pagy.version = '4.
|
5
|
+
Pagy.version = '4.4.0';
|
6
6
|
|
7
|
-
Pagy.
|
7
|
+
Pagy.timeout = 100;
|
8
|
+
|
9
|
+
Pagy.timeoutId = 0;
|
10
|
+
|
11
|
+
Pagy.init = function(arg) {
|
8
12
|
var target = arg instanceof Event || arg === undefined ? document : arg,
|
9
13
|
jsonTags = target.getElementsByClassName('pagy-json');
|
10
|
-
if (target === document) { // reset resize-listeners on page load (#163)
|
11
|
-
for (var id in Pagy.navResizeListeners) { window.removeEventListener('resize', Pagy.navResizeListeners[id], true) }
|
12
|
-
Pagy.navResizeListeners = {};
|
13
|
-
}
|
14
14
|
for (var i = 0, len = jsonTags.length; i < len; i++) {
|
15
|
-
var args
|
16
|
-
|
15
|
+
var args = JSON.parse(jsonTags[i].innerHTML),
|
16
|
+
fname = args.shift();
|
17
|
+
args.unshift(jsonTags[i].previousSibling);
|
18
|
+
Pagy[fname].apply(null, args);
|
17
19
|
}
|
18
|
-
}
|
20
|
+
}
|
19
21
|
|
20
|
-
Pagy.nav = function(
|
21
|
-
var
|
22
|
-
lastWidth = undefined,
|
22
|
+
Pagy.nav = function(pagyEl, tags, sequels, param) {
|
23
|
+
var lastWidth = undefined,
|
23
24
|
timeoutId = 0,
|
24
25
|
pageREg = new RegExp(/__pagy_page__/g),
|
25
26
|
widths = [],
|
26
|
-
|
27
|
+
wait = function() { clearTimeout(timeoutId); timeoutId = setTimeout(pagyEl.render, Pagy.timeout) };
|
27
28
|
|
28
29
|
for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
|
29
|
-
widths.sort(function(a, b){return b-a});
|
30
|
+
widths.sort(function(a, b) { return b - a });
|
30
31
|
|
31
|
-
pagyEl.render = function(){
|
32
|
-
if (this.parentElement.clientWidth === 0) {
|
32
|
+
pagyEl.render = function() {
|
33
|
+
if (this.parentElement.clientWidth === 0) { return wait() } // not ready yet
|
33
34
|
var width, i, len;
|
34
35
|
for (i = 0, len = widths.length; i < len; i++) {
|
35
36
|
if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
|
@@ -50,57 +51,60 @@ Pagy.nav = function(id, tags, sequels, param){
|
|
50
51
|
lastWidth = width;
|
51
52
|
}
|
52
53
|
}.bind(pagyEl);
|
53
|
-
|
54
|
-
if (widths.length > 1) {
|
55
|
-
// refresh the window resize listener (avoiding rendering multiple times)
|
56
|
-
window.removeEventListener('resize', Pagy.navResizeListeners[id], true); // needed for AJAX init
|
57
|
-
window.addEventListener('resize', rendering, true);
|
58
|
-
Pagy.navResizeListeners[id] = rendering;
|
59
|
-
}
|
60
54
|
pagyEl.render();
|
61
|
-
}
|
55
|
+
}
|
62
56
|
|
63
|
-
Pagy.combo_nav = function(
|
64
|
-
var
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
};
|
57
|
+
Pagy.combo_nav = function(pagyEl, page, link, param) {
|
58
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
59
|
+
go = function() {
|
60
|
+
if (page !== input.value) {
|
61
|
+
var html = link.replace(/__pagy_page__/, input.value);
|
62
|
+
if (typeof (param) === 'string' && input.value === '1') { html = Pagy.trim(html, param) }
|
63
|
+
pagyEl.insertAdjacentHTML('afterbegin', html);
|
64
|
+
pagyEl.getElementsByTagName('a')[0].click();
|
65
|
+
}
|
66
|
+
};
|
74
67
|
Pagy.addInputEventListeners(input, go);
|
75
|
-
}
|
68
|
+
}
|
76
69
|
|
77
|
-
Pagy.items_selector = function(
|
78
|
-
var
|
79
|
-
input = pagyEl.getElementsByTagName('input')[0],
|
70
|
+
Pagy.items_selector = function(pagyEl, from, link, param) {
|
71
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
80
72
|
current = input.value,
|
81
|
-
go = function(){
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
73
|
+
go = function() {
|
74
|
+
var items = input.value;
|
75
|
+
if (current !== items) {
|
76
|
+
var page = Math.max(Math.ceil(from / items), 1),
|
77
|
+
html = link.replace(/__pagy_page__/, page).replace(/__pagy_items__/, items);
|
78
|
+
if (typeof (param) === 'string' && page === 1) { html = Pagy.trim(html, param) }
|
79
|
+
pagyEl.insertAdjacentHTML('afterbegin', html);
|
80
|
+
pagyEl.getElementsByTagName('a')[0].click();
|
81
|
+
}
|
82
|
+
};
|
91
83
|
Pagy.addInputEventListeners(input, go);
|
92
|
-
}
|
84
|
+
}
|
93
85
|
|
94
|
-
Pagy.addInputEventListeners = function(input, handler){
|
86
|
+
Pagy.addInputEventListeners = function(input, handler) {
|
95
87
|
// select the content on click: easier for typing a number
|
96
|
-
input.addEventListener('click', function(){ this.select() });
|
88
|
+
input.addEventListener('click', function() { this.select() });
|
97
89
|
// go when the input looses focus
|
98
90
|
input.addEventListener('focusout', handler);
|
99
91
|
// … and when pressing enter inside the input
|
100
|
-
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
|
101
|
-
}
|
92
|
+
input.addEventListener('keyup', function(e) { if (e.which === 13) {handler()} }.bind(this));
|
93
|
+
}
|
102
94
|
|
103
|
-
Pagy.trim = function(html, param){
|
95
|
+
Pagy.trim = function(html, param) {
|
104
96
|
var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&');
|
105
97
|
return html.replace(re, '');
|
106
|
-
}
|
98
|
+
}
|
99
|
+
|
100
|
+
Pagy.renderNjs = function() {
|
101
|
+
var navs = document.getElementsByClassName('pagy-njs');
|
102
|
+
for (var i = 0, len = navs.length; i < len; i++) { navs[i].render() }
|
103
|
+
}
|
104
|
+
|
105
|
+
Pagy.wait = function() {
|
106
|
+
clearTimeout(Pagy.timeoutId);
|
107
|
+
Pagy.timeoutId = setTimeout(Pagy.renderNjs, Pagy.timeout);
|
108
|
+
}
|
109
|
+
|
110
|
+
window.addEventListener('resize', Pagy.wait, true);
|
data/lib/pagy.rb
CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# main class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '4.
|
8
|
+
VERSION = '4.4.0'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
@@ -14,7 +14,7 @@ class Pagy
|
|
14
14
|
|
15
15
|
# default vars
|
16
16
|
VARS = { page: 1, items: 20, outset: 0, size: [1, 4, 4, 1], page_param: :page, # rubocop:disable Style/MutableConstant
|
17
|
-
params: {},
|
17
|
+
params: {}, fragment: '', link_extra: '', i18n_key: 'pagy.item_name', cycle: false }
|
18
18
|
|
19
19
|
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
|
20
20
|
|
@@ -22,7 +22,8 @@ class Pagy
|
|
22
22
|
|
23
23
|
# Merge and validate the options, do some simple arithmetic and set the instance variables
|
24
24
|
def initialize(vars)
|
25
|
-
@vars = VARS.merge( vars.delete_if{|
|
25
|
+
@vars = VARS.merge( vars.delete_if{|k,v| VARS.key?(k) && (v.nil? || v == '') } )
|
26
|
+
@vars[:fragment] = deprecated_var(:anchor, @vars[:anchor], :fragment, @vars[:fragment]) if @vars[:anchor]
|
26
27
|
|
27
28
|
INSTANCE_VARS_MIN.each do |name,min|
|
28
29
|
raise VariableError.new(self), "expected :#{name} >= #{min}; got #{@vars[name].inspect}" \
|
@@ -69,6 +70,7 @@ class Pagy
|
|
69
70
|
|
70
71
|
end
|
71
72
|
|
73
|
+
require 'pagy/deprecation'
|
72
74
|
require 'pagy/backend'
|
73
75
|
require 'pagy/frontend'
|
74
76
|
require 'pagy/exceptions'
|
data/lib/pagy/backend.rb
CHANGED
@@ -19,6 +19,7 @@ class Pagy
|
|
19
19
|
|
20
20
|
# Sub-method called only by #pagy: here for easy customization of variables by overriding
|
21
21
|
def pagy_get_vars(collection, vars)
|
22
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
22
23
|
vars[:count] ||= (c = collection.count(:all)).is_a?(Hash) ? c.size : c
|
23
24
|
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
24
25
|
vars
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class Pagy
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# deprecated variables
|
6
|
+
def deprecated_var(var, val, new_var, new_val)
|
7
|
+
value = new_val || val
|
8
|
+
Warning.warn %([PAGY WARNING] deprecated use of `#{var}` var will not be supported in 5.0! Use `#{new_var}: #{value.inspect}` instead.)
|
9
|
+
value
|
10
|
+
end
|
11
|
+
|
12
|
+
# deprecated pagy_url_for argument order
|
13
|
+
def deprecated_order(pagy, page)
|
14
|
+
Warning.warn '[PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.'
|
15
|
+
[page, pagy]
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# deprecated posiitioal arguments
|
20
|
+
def deprecated_arg(arg, val, new_key, new_val)
|
21
|
+
value = new_val || val # we use the new_val if present
|
22
|
+
Warning.warn %([PAGY WARNING] deprecated use of positional `#{arg}` arg will not be supported in 5.0! Use only the keyword arg `#{new_key}: #{value.inspect}` instead.)
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/pagy/extras/arel.rb
CHANGED
data/lib/pagy/extras/array.rb
CHANGED
@@ -14,6 +14,7 @@ class Pagy
|
|
14
14
|
|
15
15
|
# Sub-method called only by #pagy_array: here for easy customization of variables by overriding
|
16
16
|
def pagy_array_get_vars(array, vars)
|
17
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
17
18
|
vars[:count] ||= array.size
|
18
19
|
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
19
20
|
vars
|
@@ -7,10 +7,11 @@ 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 pagy_bootstrap_nav(pagy)
|
11
|
-
|
10
|
+
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
12
13
|
|
13
|
-
html = +%(<nav class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
|
+
html = +%(<nav#{p_id} class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
15
|
html << pagy_bootstrap_prev_html(pagy, link)
|
15
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
17
|
html << case item
|
@@ -24,26 +25,30 @@ class Pagy
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
|
-
def pagy_bootstrap_nav_js(pagy,
|
28
|
-
|
28
|
+
def pagy_bootstrap_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
29
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
30
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
31
|
+
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
29
32
|
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
|
30
33
|
'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
31
34
|
'active' => %(<li class="page-item active">#{mark}</li>),
|
32
35
|
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
33
36
|
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }
|
34
37
|
|
35
|
-
html = %(<nav
|
36
|
-
html << pagy_json_tag(pagy, :nav,
|
38
|
+
html = %(<nav#{p_id} class="pagy-njs pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav>)
|
39
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
37
40
|
end
|
38
41
|
|
39
42
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
40
|
-
def pagy_bootstrap_combo_nav_js(pagy,
|
41
|
-
|
43
|
+
def pagy_bootstrap_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
44
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
45
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
46
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
42
47
|
p_page = pagy.page
|
43
48
|
p_pages = pagy.pages
|
44
49
|
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;">)
|
45
50
|
|
46
|
-
%(<nav
|
51
|
+
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination" role="navigation" aria-label="pager"><div class="btn-group" role="group">#{
|
47
52
|
if (p_prev = pagy.prev)
|
48
53
|
link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"'
|
49
54
|
else
|
@@ -56,7 +61,7 @@ class Pagy
|
|
56
61
|
%(<a class="next btn btn-primary disabled" href="#">#{pagy_t 'pagy.nav.next' }</a>)
|
57
62
|
end
|
58
63
|
}</div></nav>#{
|
59
|
-
pagy_json_tag pagy, :combo_nav,
|
64
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
60
65
|
})
|
61
66
|
end
|
62
67
|
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -7,10 +7,11 @@ 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 pagy_bulma_nav(pagy)
|
11
|
-
|
10
|
+
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
12
13
|
|
13
|
-
html = +%(<nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">)
|
14
|
+
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">)
|
14
15
|
html << pagy_bulma_prev_next_html(pagy, link)
|
15
16
|
html << %(<ul class="pagination-list">)
|
16
17
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
@@ -23,26 +24,30 @@ class Pagy
|
|
23
24
|
html << %(</ul></nav>)
|
24
25
|
end
|
25
26
|
|
26
|
-
def pagy_bulma_nav_js(pagy,
|
27
|
-
|
27
|
+
def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
28
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
29
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
30
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
28
31
|
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
|
29
32
|
'link' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}")}</li>),
|
30
33
|
'active' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}")}</li>),
|
31
34
|
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap' }</span></li>),
|
32
35
|
'after' => '</ul>' }
|
33
36
|
|
34
|
-
html = %(<nav
|
35
|
-
html << pagy_json_tag(pagy, :nav,
|
37
|
+
html = %(<nav#{p_id} class="pagy-njs pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>)
|
38
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
36
39
|
end
|
37
40
|
|
38
41
|
# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
39
|
-
def pagy_bulma_combo_nav_js(pagy,
|
40
|
-
|
42
|
+
def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
43
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
44
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
45
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
41
46
|
p_page = pagy.page
|
42
47
|
p_pages = pagy.pages
|
43
48
|
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;">)
|
44
49
|
|
45
|
-
%(<nav
|
50
|
+
%(<nav#{p_id} class="pagy-bulma-combo-nav-js" role="navigation" aria-label="pagination"><div class="field is-grouped is-grouped-centered" role="group">#{
|
46
51
|
if (p_prev = pagy.prev)
|
47
52
|
%(<p class="control">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"'}</p>)
|
48
53
|
else
|
@@ -55,7 +60,7 @@ class Pagy
|
|
55
60
|
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.next'}</a></p>)
|
56
61
|
end
|
57
62
|
}</div></nav>#{
|
58
|
-
pagy_json_tag pagy, :combo_nav,
|
63
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
59
64
|
})
|
60
65
|
end
|
61
66
|
|