pagy 5.2.0 → 5.2.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/javascripts/pagy.js +1 -1
- data/lib/pagy/calendar.rb +7 -2
- data/lib/pagy/extras/overflow.rb +22 -19
- 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: 7e5a33b40f2a12b18d7a3a4d86d367836a2e5bce8e675fea912292558f41d7bf
|
4
|
+
data.tar.gz: d79570153a77422382c17eed7bf00c446c5cc13aadb237c7df3207fb57db3766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e7881aac396c5049ecbdf6430d87a748e95f184bbe71b38d2c0b0cbc705cc0309c7148788534ea337a0236fae8591226d2158c78e34f06c4e557e29577f357c
|
7
|
+
data.tar.gz: 166af959cf2fb5b05746a5d0a1431f29775c13059f86402003a1f1a0fd8cbd0b13af58ab7a110fd5604266507a860c24df1b538378a5a28ff4932b68b482dc2d
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (5.2.
|
3
|
+
# Pagy initializer file (5.2.1)
|
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
|
|
data/lib/javascripts/pagy.js
CHANGED
data/lib/pagy/calendar.rb
CHANGED
@@ -31,15 +31,20 @@ class Pagy # :nodoc:
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Generate a label for each page, with the specific `Time` period it refers to
|
34
|
-
def page_label(num = @page)
|
34
|
+
def page_label(num = @page, format = nil)
|
35
35
|
snap = snap(num.to_i)
|
36
|
+
format ||= @vars[:"#{@unit}_format"]
|
36
37
|
case @unit
|
37
38
|
when :year then new_time(@initial.year + snap)
|
38
39
|
when :month then bump_month(@initial, snap)
|
39
40
|
when :week then @initial + (snap * WEEK)
|
40
41
|
when :day then @initial + (snap * DAY)
|
41
42
|
else raise InternalError, "expected @unit to be in [:year, :month, :week, :day]; got #{@unit.inspect}"
|
42
|
-
end.strftime(
|
43
|
+
end.strftime(format)
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_page_label(format = nil)
|
47
|
+
page_label(@page, format)
|
43
48
|
end
|
44
49
|
|
45
50
|
DAY = 60 * 60 * 24
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
DEFAULT[:overflow] = :empty_page
|
6
6
|
|
7
|
-
# Handles OverflowError exceptions with different options
|
7
|
+
# Handles OverflowError exceptions for different classes with different options
|
8
8
|
module OverflowExtra
|
9
9
|
# Support for Pagy class
|
10
10
|
module Pagy
|
@@ -15,22 +15,25 @@ class Pagy # :nodoc:
|
|
15
15
|
|
16
16
|
# Add rescue clause for different behaviors
|
17
17
|
def initialize(vars)
|
18
|
-
@overflow ||= false
|
18
|
+
@overflow ||= false # still true if :last_page re-run the method after an overflow
|
19
19
|
super
|
20
20
|
rescue OverflowError
|
21
|
-
@overflow = true
|
21
|
+
@overflow = true # add the overflow flag
|
22
22
|
case @vars[:overflow]
|
23
23
|
when :exception
|
24
|
-
raise
|
24
|
+
raise # same as without the extra
|
25
25
|
when :last_page
|
26
|
-
|
27
|
-
initialize vars.merge!(page: @last)
|
28
|
-
@vars[:page] =
|
26
|
+
requested_page = @vars[:page] # save the requested page (even after re-run)
|
27
|
+
initialize vars.merge!(page: @last) # re-run with the last page
|
28
|
+
@vars[:page] = requested_page # restore the requested page
|
29
29
|
when :empty_page
|
30
|
-
@offset = @in = @from = @to = 0
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
@offset = @in = @from = @to = 0 # vars relative to the actual page
|
31
|
+
if is_a?(Calendar) # only for Calendar instances
|
32
|
+
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but it would work with any time)
|
33
|
+
@utc_from = @utc_to = edge.getutc # set both to the edge utc time (a query with >= && < will get no record)
|
34
|
+
end
|
35
|
+
@prev = @last # prev relative to the actual page
|
36
|
+
extend Series # special series for :empty_page
|
34
37
|
else
|
35
38
|
raise VariableError.new(self, :overflow, 'to be in [:last_page, :empty_page, :exception]', @vars[:overflow])
|
36
39
|
end
|
@@ -39,10 +42,10 @@ class Pagy # :nodoc:
|
|
39
42
|
# Special series for empty page
|
40
43
|
module Series
|
41
44
|
def series(size = @vars[:size])
|
42
|
-
@page = @last
|
43
|
-
super(size).tap do |s|
|
44
|
-
s[s.index(@page.to_s)] = @page
|
45
|
-
@page = @vars[:page]
|
45
|
+
@page = @last # series for last page
|
46
|
+
super(size).tap do |s| # call original series
|
47
|
+
s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
|
48
|
+
@page = @vars[:page] # restore the actual page
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -55,13 +58,13 @@ class Pagy # :nodoc:
|
|
55
58
|
@overflow = false
|
56
59
|
super
|
57
60
|
rescue OverflowError
|
58
|
-
@overflow = true
|
61
|
+
@overflow = true # add the overflow flag
|
59
62
|
case @vars[:overflow]
|
60
63
|
when :exception
|
61
|
-
raise
|
64
|
+
raise # same as without the extra
|
62
65
|
when :empty_page
|
63
|
-
@offset = @in = @from = @to = 0
|
64
|
-
@vars[:size] = []
|
66
|
+
@offset = @in = @from = @to = 0 # vars relative to the actual page
|
67
|
+
@vars[:size] = [] # no page in the series
|
65
68
|
self
|
66
69
|
else
|
67
70
|
raise VariableError.new(self, :overflow, 'to be in [:empty_page, :exception]', @vars[:overflow])
|
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: 5.2.
|
4
|
+
version: 5.2.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: 2021-11-
|
11
|
+
date: 2021-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|