pagy 3.3.0 → 3.3.1
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/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: 5e120aa3e069608ec73236cf7814a9b1e1292afd8b20e00208cfd2412e9422f1
|
4
|
+
data.tar.gz: fe66d484cc2a926ee36d9b50892f92c3c0437c9fecb74dc3020dc902e2cd1618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a519633530e20b2213c8bb8f3b90fd4ed77d64f67057eafdd22620239500de1e2417d9e6a146204b27eab199f0a7c53d58e1e177a72beb5758704b9a12c0076e
|
7
|
+
data.tar.gz: 5c99aed2660d0fcd7a43128d524f53655b6a35be55baaf765ba2bffbaed8f7b840e4a0a16f350ebb7a49ab80434d64362fc90b563078bcb048b39ea8095090e4
|
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.1)
|
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/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.1'
|
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.1
|
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-07-02 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
|