pagy 5.6.2 → 5.6.3
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/day.rb +1 -1
- data/lib/pagy/calendar/month_mixin.rb +10 -8
- data/lib/pagy/calendar/week.rb +7 -7
- data/lib/pagy/calendar/year.rb +1 -1
- data/lib/pagy/calendar.rb +8 -7
- data/lib/pagy/extras/calendar.rb +15 -27
- data/lib/pagy/extras/gearbox.rb +5 -5
- 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: f567ea14d1f7bf5697ca416cf0cf1bc200986b804099f31aba5fd1ae6a946fa4
|
4
|
+
data.tar.gz: 8b09e574678ab6673c4e9d8fdc48eaf611657354d457da4856a70173d7194732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cf7845ce5b8d668cfa0de512bb6fb7ed676e3586167a9b95fdfd6eebb8b9f7bfd5cb688ab523ef1e7e512ce5f5bb379e305beb4531dd00c609e755620bd0004
|
7
|
+
data.tar.gz: f79e860f496368e67bf328b3359f5860162801600452482cf4b1c0b06439b20f9fb296d5593159410c1817fff4576c4e03ef526f265dbb5f9aa4d8877e9c558b
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (5.6.
|
3
|
+
# Pagy initializer file (5.6.3)
|
4
4
|
# Customize only what you really need and notice that the core 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/day.rb
CHANGED
@@ -13,8 +13,8 @@ class Pagy
|
|
13
13
|
def setup_unit_vars
|
14
14
|
super
|
15
15
|
@months = self.class::MONTHS # number of months in the unit
|
16
|
-
@initial =
|
17
|
-
@final = add_months_to(
|
16
|
+
@initial = unit_starting_time_for(@starting)
|
17
|
+
@final = add_months_to(unit_starting_time_for(@ending), @months)
|
18
18
|
@pages = @last = (months_in(@final) - months_in(@initial)) / @months
|
19
19
|
@from = starting_time_for(@page)
|
20
20
|
@to = add_months_to(@from, @months)
|
@@ -22,16 +22,18 @@ class Pagy
|
|
22
22
|
|
23
23
|
# Starting time for the page
|
24
24
|
def starting_time_for(page)
|
25
|
-
add_months_to(@initial,
|
26
|
-
end
|
27
|
-
|
28
|
-
# Starting month of the unit including the passed month
|
29
|
-
def starting_month_including(month)
|
30
|
-
(@months * ((month - 1) / @months)) + 1 # remove 1 month for 0-11 calculations and add it back for 1-12 conversion
|
25
|
+
add_months_to(@initial, offset_units_for(page) * @months)
|
31
26
|
end
|
32
27
|
|
33
28
|
private
|
34
29
|
|
30
|
+
# Unit starting time for time
|
31
|
+
def unit_starting_time_for(time)
|
32
|
+
# remove 1 month for 0-11 calculations and add it back for 1-12 conversion
|
33
|
+
starting_month = (@months * ((time.month - 1) / @months)) + 1
|
34
|
+
new_time(time.year, starting_month)
|
35
|
+
end
|
36
|
+
|
35
37
|
# Number of months in time
|
36
38
|
def months_in(time)
|
37
39
|
(time.year * 12) + time.month
|
data/lib/pagy/calendar/week.rb
CHANGED
@@ -15,8 +15,8 @@ class Pagy # :nodoc:
|
|
15
15
|
def setup_unit_vars
|
16
16
|
setup_vars(offset: 0)
|
17
17
|
super
|
18
|
-
@initial =
|
19
|
-
@final =
|
18
|
+
@initial = unit_starting_time_for(@starting)
|
19
|
+
@final = unit_starting_time_for(@ending) + WEEK
|
20
20
|
@pages = @last = (@final - @initial).to_i / WEEK
|
21
21
|
@from = starting_time_for(@page)
|
22
22
|
@to = @from + WEEK
|
@@ -24,15 +24,15 @@ class Pagy # :nodoc:
|
|
24
24
|
|
25
25
|
# Starting time for the page
|
26
26
|
def starting_time_for(page)
|
27
|
-
@initial + (
|
27
|
+
@initial + (offset_units_for(page) * WEEK)
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
#
|
33
|
-
def
|
34
|
-
|
35
|
-
new_time(
|
32
|
+
# Unit starting time for time
|
33
|
+
def unit_starting_time_for(time)
|
34
|
+
starting_time = time - (((time.wday - @offset) * DAY) % WEEK)
|
35
|
+
new_time(starting_time.year, starting_time.month, starting_time.day)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/pagy/calendar/year.rb
CHANGED
data/lib/pagy/calendar.rb
CHANGED
@@ -39,11 +39,6 @@ class Pagy # :nodoc:
|
|
39
39
|
localize(starting_time_for(page.to_i), opts) # page could be a string
|
40
40
|
end
|
41
41
|
|
42
|
-
# Period of the active page (used for nested units)
|
43
|
-
def active_period
|
44
|
-
[[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
|
45
|
-
end
|
46
|
-
|
47
42
|
protected
|
48
43
|
|
49
44
|
# Base class method for the setup of the unit variables
|
@@ -63,8 +58,9 @@ class Pagy # :nodoc:
|
|
63
58
|
time.strftime(opts[:format])
|
64
59
|
end
|
65
60
|
|
66
|
-
#
|
67
|
-
|
61
|
+
# Number of units to offset from the @initial time, in order to get the ordered starting time for the page.
|
62
|
+
# Used in starting_time_for(page) with a logic equivalent to: @initial + (offset_units_for(page) * unit_time_length)
|
63
|
+
def offset_units_for(page)
|
68
64
|
@order == :asc ? page - 1 : @pages - page
|
69
65
|
end
|
70
66
|
|
@@ -73,6 +69,11 @@ class Pagy # :nodoc:
|
|
73
69
|
Time.new(year, month, day, 0, 0, 0, @utc_offset)
|
74
70
|
end
|
75
71
|
|
72
|
+
# Period of the active page (used internally for nested units)
|
73
|
+
def active_period
|
74
|
+
[[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
|
75
|
+
end
|
76
|
+
|
76
77
|
class << self
|
77
78
|
# Create a subclass instance by unit name (internal use)
|
78
79
|
def create(unit, vars)
|
data/lib/pagy/extras/calendar.rb
CHANGED
@@ -12,12 +12,7 @@ class Pagy # :nodoc:
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
# Take a collection and a conf Hash with keys in
|
16
|
-
# The calendar is active by default, but it can be explicitly inactivated with `active: false`
|
17
|
-
# Return a hash with 3 items:
|
18
|
-
# 0. Array of pagy calendar unit objects
|
19
|
-
# 1. Pagy object
|
20
|
-
# 2. Array of results
|
15
|
+
# Take a collection and a conf Hash with keys in CONF_KEYS and return an array with 3 items: [calendar, pagy, results]
|
21
16
|
def pagy_calendar(collection, conf)
|
22
17
|
unless conf.is_a?(Hash) && (conf.keys - CONF_KEYS).empty? && conf.all? { |k, v| v.is_a?(Hash) || k == :active }
|
23
18
|
raise ArgumentError, "keys must be in #{CONF_KEYS.inspect} and object values must be Hashes; got #{conf.inspect}"
|
@@ -25,8 +20,8 @@ class Pagy # :nodoc:
|
|
25
20
|
|
26
21
|
conf[:pagy] = {} unless conf[:pagy] # use default Pagy object when omitted
|
27
22
|
calendar, collection = pagy_setup_calendar(collection, conf) unless conf.key?(:active) && !conf[:active]
|
28
|
-
pagy,
|
29
|
-
[calendar, pagy,
|
23
|
+
pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
|
24
|
+
[calendar, pagy, results]
|
30
25
|
end
|
31
26
|
|
32
27
|
# Setup and return the calendar objects and the filtered collection
|
@@ -34,41 +29,34 @@ class Pagy # :nodoc:
|
|
34
29
|
units = Calendar::UNITS & conf.keys # get the units in time length desc order
|
35
30
|
page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
|
36
31
|
units.each do |unit| # set all the :page_param vars for later deletion
|
37
|
-
unit_page_param
|
32
|
+
unit_page_param = :"#{unit}_#{page_param}"
|
38
33
|
conf[unit][:page_param] = unit_page_param
|
39
34
|
conf[unit][:page] = params[unit_page_param]
|
40
35
|
end
|
41
36
|
calendar = {}
|
42
|
-
|
37
|
+
last_obj = nil
|
43
38
|
units.each_with_index do |unit, index|
|
44
39
|
params_to_delete = units[(index + 1), units.size].map { |sub| conf[sub][:page_param] } + [page_param]
|
45
40
|
conf[unit][:params] = lambda do |params| # delete page_param from the sub-units
|
46
|
-
params_to_delete.each { |p| params.delete(p.to_s) } # Hash#except missing from 2.5 baseline
|
41
|
+
params_to_delete.each { |p| params.delete(p.to_s) } # Hash#except missing from ruby 2.5 baseline
|
47
42
|
params
|
48
43
|
end
|
49
|
-
conf[unit][:period] =
|
50
|
-
calendar[unit] = Calendar.send(:create, unit, conf[unit])
|
51
|
-
period = calendar[unit].active_period # set the period for the next unit
|
44
|
+
conf[unit][:period] = last_obj&.send(:active_period) || pagy_calendar_period(collection)
|
45
|
+
calendar[unit] = last_obj = Calendar.send(:create, unit, conf[unit])
|
52
46
|
end
|
53
|
-
[calendar, pagy_calendar_filter(collection,
|
47
|
+
[calendar, pagy_calendar_filter(collection, last_obj.from, last_obj.to)]
|
54
48
|
end
|
55
49
|
|
56
|
-
# This method must be implemented by the application
|
57
|
-
# It must return the the starting and ending local Time objects defining the calendar :period
|
50
|
+
# This method must be implemented by the application
|
58
51
|
def pagy_calendar_period(*)
|
59
|
-
|
60
|
-
|
61
|
-
'the starting and ending local Time objects array defining the calendar :period'
|
52
|
+
raise NoMethodError, 'the pagy_calendar_period method must be implemented by the application ' \
|
53
|
+
'(see https://ddnexus.github.io/pagy/extras/calendar#pagy_calendar_periodcollection)'
|
62
54
|
end
|
63
55
|
|
64
|
-
# This method must be implemented by the application
|
65
|
-
# It receives the main collection and must return a filtered version of it.
|
66
|
-
# The filter logic must be equivalent to {storage_time >= from && storage_time < to}
|
56
|
+
# This method must be implemented by the application
|
67
57
|
def pagy_calendar_filter(*)
|
68
|
-
|
69
|
-
|
70
|
-
'collection filtered by a logic equivalent to '\
|
71
|
-
'{storage_time >= from && storage_time < to}'
|
58
|
+
raise NoMethodError, 'the pagy_calendar_filter method must be implemented by the application ' \
|
59
|
+
'(see https://ddnexus.github.io/pagy/extras/calendar#pagy_calendar_filtercollection-from-to)'
|
72
60
|
end
|
73
61
|
end
|
74
62
|
end
|
data/lib/pagy/extras/gearbox.rb
CHANGED
@@ -28,11 +28,11 @@ class Pagy # :nodoc:
|
|
28
28
|
@pages = @last = (if @count > (sum = gearbox_items.sum)
|
29
29
|
[((@count - sum).to_f / gearbox_items.last).ceil, 1].max + gearbox_items.count
|
30
30
|
else
|
31
|
-
pages
|
32
|
-
|
33
|
-
while
|
34
|
-
pages
|
35
|
-
|
31
|
+
pages = 0
|
32
|
+
remainder = @count
|
33
|
+
while remainder.positive?
|
34
|
+
pages += 1
|
35
|
+
remainder -= gearbox_items[pages - 1]
|
36
36
|
end
|
37
37
|
[pages, 1].max
|
38
38
|
end)
|
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.6.
|
4
|
+
version: 5.6.3
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|