pagy 3.3.0 → 3.3.2
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 +1 -1
- data/lib/javascripts/pagy.js +16 -15
- data/lib/locales/utils/loader.rb +1 -1
- data/lib/pagy.rb +4 -5
- data/lib/pagy/countless.rb +1 -1
- data/lib/pagy/exceptions.rb +22 -0
- data/lib/pagy/extras/overflow.rb +2 -2
- data/lib/pagy/extras/shared.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10ba8b6d06ab5a7b5a8200742565f8193484e664eaecd342102ff001a03c9dd5
|
4
|
+
data.tar.gz: 273c70974fafb3b8c01392254ba45a86af6654a2442229afb403ec29407b76ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f98ade89e75ce830bd933a2a21c8075c9b00e1f08de5e0797a1178d058707931956b16d5cd2cc818427bbb24464a398c4ebc114b92fde6d671667aedf79d6b
|
7
|
+
data.tar.gz: f70784721380571f8286379cf70e34badd30cea3d57ac89f70b5c99704d1b4719192f2cca0e59b7aa34f0cc0f32b22175752d224f187dbba7aadd1eb7b404320
|
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.3.
|
4
|
+
# Pagy initializer file (3.3.2)
|
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
@@ -5,6 +5,10 @@ function Pagy(){}
|
|
5
5
|
Pagy.init = function(arg){
|
6
6
|
var target = arg instanceof Event || arg === undefined ? document : arg,
|
7
7
|
jsonTags = target.getElementsByClassName('pagy-json');
|
8
|
+
if (target === document) { // reset resize-listeners on page load (#163)
|
9
|
+
for (var id in Pagy.navResizeListeners) { window.removeEventListener('resize', Pagy.navResizeListeners[id], true) }
|
10
|
+
Pagy.navResizeListeners = {};
|
11
|
+
}
|
8
12
|
for (var i = 0, len = jsonTags.length; i < len; i++) {
|
9
13
|
var args = JSON.parse(jsonTags[i].innerHTML);
|
10
14
|
Pagy[args.shift()].apply(null, args);
|
@@ -13,19 +17,20 @@ Pagy.init = function(arg){
|
|
13
17
|
|
14
18
|
Pagy.nav = function(id, tags, sequels, param){
|
15
19
|
var pagyEl = document.getElementById(id),
|
16
|
-
container = pagyEl.parentElement,
|
17
20
|
lastWidth = undefined,
|
18
21
|
timeoutId = 0,
|
19
22
|
pageREg = new RegExp(/__pagy_page__/g),
|
20
|
-
widths = []
|
23
|
+
widths = [],
|
24
|
+
rendering = function(){ clearTimeout(timeoutId); timeoutId = setTimeout(pagyEl.render, 150) }; // suppress rapid firing rendering
|
25
|
+
|
21
26
|
for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
|
22
27
|
widths.sort(function(a, b){return b-a});
|
23
28
|
|
24
|
-
|
25
|
-
if (
|
29
|
+
pagyEl.render = function(){
|
30
|
+
if (this.parentElement.clientWidth === 0) { rendering() }
|
26
31
|
var width, i, len;
|
27
32
|
for (i = 0, len = widths.length; i < len; i++) {
|
28
|
-
if (
|
33
|
+
if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
|
29
34
|
}
|
30
35
|
if (width !== lastWidth) {
|
31
36
|
var html = tags.before,
|
@@ -38,21 +43,19 @@ Pagy.nav = function(id, tags, sequels, param){
|
|
38
43
|
else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
|
39
44
|
}
|
40
45
|
html += tags.after;
|
41
|
-
|
42
|
-
|
46
|
+
this.innerHTML = '';
|
47
|
+
this.insertAdjacentHTML('afterbegin', html);
|
43
48
|
lastWidth = width;
|
44
49
|
}
|
45
|
-
}
|
46
|
-
// suppress rapid firing rendering
|
47
|
-
rendering = function(){ clearTimeout(timeoutId); timeoutId = setTimeout(render, 150) };
|
50
|
+
}.bind(pagyEl);
|
48
51
|
|
49
52
|
if (widths.length > 1) {
|
50
53
|
// refresh the window resize listener (avoiding rendering multiple times)
|
51
|
-
window.removeEventListener('resize', Pagy.
|
54
|
+
window.removeEventListener('resize', Pagy.navResizeListeners[id], true); // needed for AJAX init
|
52
55
|
window.addEventListener('resize', rendering, true);
|
53
|
-
Pagy.
|
56
|
+
Pagy.navResizeListeners[id] = rendering;
|
54
57
|
}
|
55
|
-
render();
|
58
|
+
pagyEl.render();
|
56
59
|
};
|
57
60
|
|
58
61
|
Pagy.combo_nav = function(id, page, link, param){
|
@@ -86,8 +89,6 @@ Pagy.items_selector = function(id, from, link, param){
|
|
86
89
|
Pagy.addInputEventListeners(input, go);
|
87
90
|
};
|
88
91
|
|
89
|
-
Pagy.windowListeners = {};
|
90
|
-
|
91
92
|
Pagy.addInputEventListeners = function(input, handler){
|
92
93
|
// select the content on click: easier for typing a number
|
93
94
|
input.addEventListener('click', function(){ this.select() });
|
data/lib/locales/utils/loader.rb
CHANGED
@@ -23,7 +23,7 @@ lambda do |i18n, *args|
|
|
23
23
|
arg[:filepath] ||= Pagy.root.join('locales', "#{arg[:locale]}.yml")
|
24
24
|
arg[:pluralize] ||= plurals[arg[:locale]]
|
25
25
|
hash = YAML.load(File.read(arg[:filepath], encoding: 'UTF-8')) #rubocop:disable Security/YAMLLoad
|
26
|
-
hash.key?(arg[:locale]) or raise
|
26
|
+
hash.key?(arg[:locale]) or raise VariableError, %(expected :locale "#{arg[:locale]}" not found in :filepath "#{arg[:filepath].inspect}")
|
27
27
|
i18n[arg[:locale]] = [flatten.call(hash[arg[:locale]]), arg[:pluralize]]
|
28
28
|
end
|
29
29
|
end
|
data/lib/pagy.rb
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'pathname'
|
6
6
|
|
7
|
-
class Pagy ; VERSION = '3.3.
|
8
|
-
|
9
|
-
class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
|
7
|
+
class Pagy ; VERSION = '3.3.2'
|
10
8
|
|
11
9
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
12
10
|
def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end
|
@@ -21,7 +19,7 @@ class Pagy ; VERSION = '3.3.0'
|
|
21
19
|
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars
|
22
20
|
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
|
23
21
|
(@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
|
24
|
-
or raise(
|
22
|
+
or raise(VariableError.new(self), "expected :#{k} >= #{min}; got #{@vars[k].inspect}")
|
25
23
|
end
|
26
24
|
@pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings
|
27
25
|
@page <= @last or raise(OverflowError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}")
|
@@ -36,7 +34,7 @@ class Pagy ; VERSION = '3.3.0'
|
|
36
34
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
37
35
|
def series(size=@vars[:size])
|
38
36
|
(series = []) and size.empty? and return series
|
39
|
-
4.times{|i| (size[i]>=0 rescue nil) or raise(
|
37
|
+
4.times{|i| (size[i]>=0 rescue nil) or raise(VariableError.new(self), "expected 4 items >= 0 in :size; got #{size.inspect}")}
|
40
38
|
[*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
|
41
39
|
if a<0 || a==b || a>@last # skip out of range and duplicates
|
42
40
|
elsif a+1 == b; series.push(a) # no gap -> no additions
|
@@ -51,3 +49,4 @@ end
|
|
51
49
|
|
52
50
|
require 'pagy/backend'
|
53
51
|
require 'pagy/frontend'
|
52
|
+
require 'pagy/exceptions'
|
data/lib/pagy/countless.rb
CHANGED
@@ -12,7 +12,7 @@ class Pagy
|
|
12
12
|
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden)
|
13
13
|
{ items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
|
14
14
|
(@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
|
15
|
-
or raise(
|
15
|
+
or raise(VariableError.new(self), "expected :#{k} >= #{min}; got #{@vars[k].inspect}")
|
16
16
|
end
|
17
17
|
@offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
|
18
18
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pagy
|
2
|
+
|
3
|
+
class VariableError < ArgumentError
|
4
|
+
attr_reader :pagy
|
5
|
+
|
6
|
+
def initialize(pagy)
|
7
|
+
@pagy = pagy
|
8
|
+
end
|
9
|
+
|
10
|
+
def variable
|
11
|
+
message =~ /expected :([\w]+)/
|
12
|
+
$1.to_sym if $1
|
13
|
+
end
|
14
|
+
|
15
|
+
def value
|
16
|
+
pagy.vars[variable]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class OverflowError < VariableError; end
|
21
|
+
|
22
|
+
end
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -28,7 +28,7 @@ class Pagy
|
|
28
28
|
@prev = @last # prev relative to the actual page
|
29
29
|
extend(Series) # special series for :empty_page
|
30
30
|
else
|
31
|
-
raise
|
31
|
+
raise VariableError.new(self), "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
alias_method :initialize, :initialize_with_overflow
|
@@ -62,7 +62,7 @@ class Pagy
|
|
62
62
|
@vars[:size] = [] # no page in the series
|
63
63
|
self
|
64
64
|
else
|
65
|
-
raise
|
65
|
+
raise VariableError.new(self), "expected :overflow variable in [:empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
alias_method :finalize, :finalize_with_overflow
|
data/lib/pagy/extras/shared.rb
CHANGED
@@ -19,7 +19,7 @@ class Pagy
|
|
19
19
|
# Notice: if :steps is false it will use the single {0 => @vars[:size]} size
|
20
20
|
def sequels
|
21
21
|
steps = @vars[:steps] || {0 => @vars[:size]}
|
22
|
-
steps.key?(0) or raise(
|
22
|
+
steps.key?(0) or raise(VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}")
|
23
23
|
sequels = {}; steps.each {|width, size| sequels[width.to_s] = series(size)}; sequels
|
24
24
|
end
|
25
25
|
|
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.3.
|
4
|
+
version: 3.3.2
|
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-06
|
11
|
+
date: 2019-07-06 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,
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/pagy.rb
|
47
47
|
- lib/pagy/backend.rb
|
48
48
|
- lib/pagy/countless.rb
|
49
|
+
- lib/pagy/exceptions.rb
|
49
50
|
- lib/pagy/extras/array.rb
|
50
51
|
- lib/pagy/extras/bootstrap.rb
|
51
52
|
- lib/pagy/extras/bulma.rb
|