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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75bb34a884999d7ec40e067e8218a43c4d12193680014731a3c469c435370709
4
- data.tar.gz: fcd39cc96ec420b6f2365b57ab3256559ec34cfbf72e0980cf555d60c5086122
3
+ metadata.gz: 7e5a33b40f2a12b18d7a3a4d86d367836a2e5bce8e675fea912292558f41d7bf
4
+ data.tar.gz: d79570153a77422382c17eed7bf00c446c5cc13aadb237c7df3207fb57db3766
5
5
  SHA512:
6
- metadata.gz: 2aab474d8a2780320e4c13f2a79e9c6dbbe82657bbc9bc75135902c7c9ee27e1a742cf415b9588a712e4629914decc7abdfbc4e2dca0fdbf0eaf3436ca6b4376
7
- data.tar.gz: ae28683579224c8cfe7442fafef13e7f767e926d34f4e56d420efd234622f93758ec270a036d7b7e900a2e0a3637a3cdcf2f6e1cee6dbf945f1b593fc4291e9e
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.0)
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
 
@@ -3,7 +3,7 @@
3
3
  // Container of the whole pagy stuff
4
4
  function Pagy(){}
5
5
 
6
- Pagy.version = '5.2.0'
6
+ Pagy.version = '5.2.1'
7
7
 
8
8
  // Used by the waitForMe function
9
9
  Pagy.delay = 100
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(@vars[:"#{@unit}_format"])
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
@@ -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 # don't override if :last_page re-run the method after an overflow
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 # add the overflow flag
21
+ @overflow = true # add the overflow flag
22
22
  case @vars[:overflow]
23
23
  when :exception
24
- raise # same as without the extra
24
+ raise # same as without the extra
25
25
  when :last_page
26
- initial_page = @vars[:page] # save the very initial page (even after re-run)
27
- initialize vars.merge!(page: @last) # re-run with the last page
28
- @vars[:page] = initial_page # restore the initial 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 # vars relative to the actual page
31
- @utc_from = @utc_to = @final # calendar variables out of local_minmax
32
- @prev = @last # prev relative to the actual page
33
- extend Series # special series for :empty_page
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 # series for last page
43
- super(size).tap do |s| # call original series
44
- s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
45
- @page = @vars[:page] # restore the actual 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 # add the overflow flag
61
+ @overflow = true # add the overflow flag
59
62
  case @vars[:overflow]
60
63
  when :exception
61
- raise # same as without the extra
64
+ raise # same as without the extra
62
65
  when :empty_page
63
- @offset = @in = @from = @to = 0 # vars relative to the actual page
64
- @vars[:size] = [] # no page in the series
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
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # Core class
7
7
  class Pagy
8
- VERSION = '5.2.0'
8
+ VERSION = '5.2.1'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
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.0
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-06 00:00:00.000000000 Z
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: