pagy 5.3.0 → 5.5.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 +24 -12
- data/lib/javascripts/pagy.js +1 -1
- data/lib/pagy/calendar/day.rb +29 -0
- data/lib/pagy/calendar/month.rb +44 -0
- data/lib/pagy/calendar/week.rb +39 -0
- data/lib/pagy/calendar/year.rb +29 -0
- data/lib/pagy/calendar.rb +41 -110
- data/lib/pagy/countless.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +4 -4
- data/lib/pagy/extras/bulma.rb +4 -4
- data/lib/pagy/extras/calendar.rb +56 -17
- data/lib/pagy/extras/foundation.rb +4 -4
- data/lib/pagy/extras/frontend_helpers.rb +2 -3
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/materialize.rb +4 -4
- data/lib/pagy/extras/navs.rb +2 -2
- data/lib/pagy/extras/overflow.rb +5 -5
- data/lib/pagy/extras/semantic.rb +4 -4
- data/lib/pagy/extras/uikit.rb +4 -4
- data/lib/pagy/frontend.rb +2 -2
- data/lib/pagy/url_helpers.rb +1 -1
- data/lib/pagy.rb +2 -2
- data/lib/templates/bootstrap_nav.html.erb +1 -1
- data/lib/templates/bootstrap_nav.html.haml +1 -1
- data/lib/templates/bootstrap_nav.html.slim +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e23922e820d30e39dee31d0b1931e79da25f9fd6fa4ee4c5f75a25f383ca99bc
|
4
|
+
data.tar.gz: 863360e18514c2250c2746d7fdfac4b11e65e0b04488150bee078466877a8b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27819f1864544b94b0c916cca3d4d43a7bfd051c41a7a202b30818e9b5730fd754c2034247c912d48bb046d90ce46f95f4a18a636b2b75e8ed6b06203f1ddc81
|
7
|
+
data.tar.gz: '031559fa58448415d4555613c76cb16f3e5f1b1262400d6ea928c0817dd45a6902a28014052860aa1ac74f6da59d2313d142226635fd6d351578f12477e34439'
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (5.
|
3
|
+
# Pagy initializer file (5.5.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
|
|
@@ -40,17 +40,30 @@
|
|
40
40
|
# See https://ddnexus.github.io/pagy/extras/array
|
41
41
|
# require 'pagy/extras/array'
|
42
42
|
|
43
|
-
# Calendar extra:
|
43
|
+
# Calendar extra: Add pagination filtering by calendar time unit (Year, Month, Week Day)
|
44
44
|
# See https://ddnexus.github.io/pagy/extras/calendar
|
45
45
|
# require 'pagy/extras/calendar'
|
46
|
-
#
|
47
|
-
# Pagy::DEFAULT[:
|
48
|
-
# Pagy::DEFAULT[:
|
49
|
-
#
|
50
|
-
# Pagy::DEFAULT[:
|
51
|
-
# Pagy::DEFAULT[:
|
52
|
-
#
|
53
|
-
# Pagy::DEFAULT[:
|
46
|
+
# Default for each unit
|
47
|
+
# Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination
|
48
|
+
# Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format
|
49
|
+
#
|
50
|
+
# Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
|
51
|
+
# Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
|
52
|
+
#
|
53
|
+
# Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination
|
54
|
+
# Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format
|
55
|
+
# Pagy::Calendar::Week::DEFAULT[:offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
|
56
|
+
#
|
57
|
+
# Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
|
58
|
+
# Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
|
59
|
+
#
|
60
|
+
# Uncomment the following block, if you need calendar localization without using the I18n extra
|
61
|
+
# module LocalizePagyCalendar
|
62
|
+
# def localize(time, opts)
|
63
|
+
# ::I18n.l(time, **opts)
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
# Pagy::Calendar.prepend LocalizePagyCalendar
|
54
67
|
|
55
68
|
# Countless extra: Paginate without any count, saving one query per rendering
|
56
69
|
# See https://ddnexus.github.io/pagy/extras/countless
|
@@ -219,6 +232,5 @@
|
|
219
232
|
# Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
|
220
233
|
|
221
234
|
|
222
|
-
# When you are done setting your own
|
223
|
-
# so it will not changed accidentally
|
235
|
+
# When you are done setting your own default freeze it, so it will not get changed accidentally
|
224
236
|
Pagy::DEFAULT.freeze
|
data/lib/javascripts/pagy.js
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy # :nodoc:
|
5
|
+
class Calendar # :nodoc:
|
6
|
+
# Calendar day subclass
|
7
|
+
class Day < Calendar
|
8
|
+
DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
|
9
|
+
format: '%Y-%m-%d' }
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
# Setup the calendar variables
|
14
|
+
def setup_unit_vars
|
15
|
+
super
|
16
|
+
@initial = new_time(@starting.year, @starting.month, @starting.day)
|
17
|
+
@final = new_time(@ending.year, @ending.month, @ending.day) + DAY
|
18
|
+
@pages = @last = (@final - @initial).to_i / DAY
|
19
|
+
@from = start_for(@page)
|
20
|
+
@to = @from + DAY
|
21
|
+
end
|
22
|
+
|
23
|
+
# Time for the page
|
24
|
+
def start_for(page)
|
25
|
+
@initial + (snap(page) * DAY)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy # :nodoc:
|
5
|
+
class Calendar # :nodoc:
|
6
|
+
# Calendar month subclass
|
7
|
+
class Month < Calendar
|
8
|
+
DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
|
9
|
+
format: '%Y-%m' }
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
# Setup the calendar variables
|
14
|
+
def setup_unit_vars
|
15
|
+
super
|
16
|
+
@initial = new_time(@starting.year, @starting.month)
|
17
|
+
@final = bump_month(@ending)
|
18
|
+
@pages = @last = months(@final) - months(@initial)
|
19
|
+
@from = start_for(@page)
|
20
|
+
@to = bump_month(@from)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Time for the page
|
24
|
+
def start_for(page)
|
25
|
+
bump_month(@initial, snap(page))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Months in local time
|
31
|
+
def months(time)
|
32
|
+
(time.year * 12) + time.month
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add 1 or more months to local time
|
36
|
+
def bump_month(time, months = 1)
|
37
|
+
months += months(time)
|
38
|
+
year = months / 12
|
39
|
+
month = months % 12
|
40
|
+
month.zero? ? new_time(year - 1, 12) : new_time(year, month)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy # :nodoc:
|
5
|
+
class Calendar # :nodoc:
|
6
|
+
# Calendar week subclass
|
7
|
+
class Week < Calendar
|
8
|
+
DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
|
9
|
+
format: '%Y-%W',
|
10
|
+
offset: 0 }
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
# Setup the calendar variables
|
15
|
+
def setup_unit_vars
|
16
|
+
setup_vars(offset: 0)
|
17
|
+
super
|
18
|
+
@initial = week_start(@starting)
|
19
|
+
@final = week_start(@ending) + WEEK
|
20
|
+
@pages = @last = (@final - @initial).to_i / WEEK
|
21
|
+
@from = start_for(@page)
|
22
|
+
@to = @from + WEEK
|
23
|
+
end
|
24
|
+
|
25
|
+
# Time for the page
|
26
|
+
def start_for(page)
|
27
|
+
@initial + (snap(page) * WEEK)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Return the start of the week for local time
|
33
|
+
def week_start(time)
|
34
|
+
start = time - (((time.wday - @offset) * DAY) % WEEK)
|
35
|
+
new_time(start.year, start.month, start.day)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy # :nodoc:
|
5
|
+
class Calendar # :nodoc:
|
6
|
+
# Calendar year subclass
|
7
|
+
class Year < Calendar
|
8
|
+
DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
|
9
|
+
format: '%Y' }
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
# Setup the calendar variables
|
14
|
+
def setup_unit_vars
|
15
|
+
super
|
16
|
+
@initial = new_time(@starting.year)
|
17
|
+
@final = new_time(@ending.year + 1)
|
18
|
+
@pages = @last = @final.year - @initial.year
|
19
|
+
@from = start_for(@page)
|
20
|
+
@to = new_time(@from.year + 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Time for the page
|
24
|
+
def start_for(page)
|
25
|
+
new_time(@initial.year + snap(page))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/pagy/calendar.rb
CHANGED
@@ -2,27 +2,22 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy'
|
5
|
-
require 'date'
|
6
5
|
|
7
6
|
class Pagy # :nodoc:
|
8
|
-
|
9
|
-
DEFAULT[:unit] = :month # Time unit allowed %i[year month week day]
|
10
|
-
DEFAULT[:week_offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
|
11
|
-
DEFAULT[:order] = :asc # Time direction of pagination
|
12
|
-
DEFAULT[:year_format] = '%Y' # strftime format for :year unit
|
13
|
-
DEFAULT[:month_format] = '%Y-%m' # strftime format for :month unit
|
14
|
-
DEFAULT[:week_format] = '%Y-%W' # strftime format for :week unit
|
15
|
-
DEFAULT[:day_format] = '%Y-%m-%d' # strftime format for :day unit
|
16
|
-
|
17
|
-
# Paginate a Time period by units (year, month, week or day)
|
7
|
+
# Base class for time units subclasses (Year, Month, Week, Day)
|
18
8
|
class Calendar < Pagy
|
19
|
-
|
20
|
-
|
9
|
+
DAY = 60 * 60 * 24
|
10
|
+
WEEK = DAY * 7
|
11
|
+
|
12
|
+
attr_reader :order
|
21
13
|
|
22
14
|
# Merge and validate the options, do some simple arithmetic and set a few instance variables
|
23
15
|
def initialize(vars) # rubocop:disable Lint/MissingSuper
|
16
|
+
raise InternalError, 'Pagy::Calendar is a base class; use one of its subclasses' if instance_of?(Pagy::Calendar)
|
17
|
+
|
24
18
|
normalize_vars(vars)
|
25
|
-
|
19
|
+
@vars = self.class::DEFAULT.merge(@vars)
|
20
|
+
setup_vars(page: 1)
|
26
21
|
setup_unit_vars
|
27
22
|
setup_params_var
|
28
23
|
raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
|
@@ -31,103 +26,43 @@ class Pagy # :nodoc:
|
|
31
26
|
@next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
|
32
27
|
end
|
33
28
|
|
34
|
-
#
|
35
|
-
# It can pass along the I18n gem opts when it's used with the i18n extra
|
36
|
-
def label_for(page, **opts)
|
37
|
-
snap = snap(page.to_i)
|
38
|
-
time = case @unit
|
39
|
-
when :year then new_time(@initial.year + snap)
|
40
|
-
when :month then bump_month(@initial, snap)
|
41
|
-
when :week then @initial + (snap * WEEK)
|
42
|
-
when :day then @initial + (snap * DAY)
|
43
|
-
else raise InternalError, "expected @unit to be in [:year, :month, :week, :day]; got #{@unit.inspect}"
|
44
|
-
end
|
45
|
-
opts[:format] ||= @vars[:"#{@unit}_format"]
|
46
|
-
strftime(time, **opts)
|
47
|
-
end
|
48
|
-
|
49
|
-
# The label for the current page
|
50
|
-
# It can pass along the I18n gem opts when it's used with the i18n extra
|
29
|
+
# The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
|
51
30
|
def label(**opts)
|
52
31
|
label_for(@page, **opts)
|
53
32
|
end
|
54
33
|
|
55
|
-
|
56
|
-
|
34
|
+
# The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
|
35
|
+
def label_for(page, **opts)
|
36
|
+
opts[:format] ||= @vars[:format]
|
37
|
+
localize(start_for(page.to_i), **opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Period of the active page (used for nested units)
|
41
|
+
def active_period
|
42
|
+
[[@starting, @from].max, [@to - DAY, @ending].min] # include only last unit day
|
43
|
+
end
|
57
44
|
|
58
45
|
protected
|
59
46
|
|
47
|
+
# Base class method for the setup of the unit variables
|
60
48
|
def setup_unit_vars
|
61
|
-
(
|
62
|
-
raise VariableError.new(self, :format, 'to be a strftime format', @vars[:"#{unit}_format"]) \
|
63
|
-
unless @vars[:"#{unit}_format"].is_a?(String)
|
64
|
-
end
|
65
|
-
raise VariableError.new(self, :unit, "to be in #{units.inspect}", @unit) \
|
66
|
-
unless units.include?(@unit = @vars[:unit])
|
49
|
+
raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
|
67
50
|
raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
|
68
51
|
unless %i[asc desc].include?(@order = @vars[:order])
|
69
52
|
|
70
|
-
|
71
|
-
raise VariableError.new(self, :
|
72
|
-
unless
|
73
|
-
&& (@utc_offset =
|
74
|
-
|
75
|
-
send :"setup_#{@unit}_vars", min, max
|
53
|
+
@starting, @ending = @vars[:period]
|
54
|
+
raise VariableError.new(self, :period, 'to be a an Array of min and max local Time instances', @vars[:period]) \
|
55
|
+
unless @starting.is_a?(Time) && @ending.is_a?(Time) && !@starting.utc? && !@ending.utc? && @starting <= @ending \
|
56
|
+
&& (@utc_offset = @starting.utc_offset) == @ending.utc_offset
|
76
57
|
end
|
77
58
|
|
78
|
-
#
|
79
|
-
|
80
|
-
# @initial: beginning of the first day of the period that encloses the min local time
|
81
|
-
# @final: beginning of the first day of the NEXT period AFTER the period that encloses the max local time
|
82
|
-
# @utc_from: beginning of the first day of the period of the current page as UTC time
|
83
|
-
# @utc_to: beginning of the first day of the NEXT period AFTER the current page as UTC time
|
84
|
-
|
85
|
-
# Setup the calendar vars when the unit is :year
|
86
|
-
def setup_year_vars(min, max)
|
87
|
-
@initial = new_time(min.year)
|
88
|
-
@final = new_time(max.year + 1)
|
89
|
-
@pages = @last = @final.year - @initial.year
|
90
|
-
@utc_from = new_time(@initial.year + snap).utc
|
91
|
-
@utc_to = new_time(@initial.year + snap + 1).utc
|
92
|
-
end
|
93
|
-
|
94
|
-
# Setup the calendar vars when the unit is :month
|
95
|
-
def setup_month_vars(min, max)
|
96
|
-
@initial = new_time(min.year, min.month)
|
97
|
-
@final = bump_month(max)
|
98
|
-
@pages = @last = months(@final) - months(@initial)
|
99
|
-
@utc_from = bump_month(@initial, snap).utc
|
100
|
-
@utc_to = bump_month(@initial, snap + 1).utc
|
101
|
-
end
|
102
|
-
|
103
|
-
# Setup the calendar vars when the unit is :week
|
104
|
-
def setup_week_vars(min, max)
|
105
|
-
@initial = week_start(min)
|
106
|
-
@final = week_start(max) + WEEK
|
107
|
-
@pages = @last = (@final - @initial).to_i / WEEK
|
108
|
-
@utc_from = (@initial + (snap * WEEK)).utc
|
109
|
-
@utc_to = @utc_from + WEEK
|
110
|
-
end
|
111
|
-
|
112
|
-
# Setup the calendar vars when the unit is :day
|
113
|
-
def setup_day_vars(min, max)
|
114
|
-
@initial = new_time(min.year, min.month, min.day)
|
115
|
-
@final = new_time(max.year, max.month, max.day) + DAY
|
116
|
-
@pages = @last = (@final - @initial).to_i / DAY
|
117
|
-
@utc_from = (@initial + (snap * DAY)).utc
|
118
|
-
@utc_to = @utc_from + DAY
|
119
|
-
end
|
120
|
-
|
121
|
-
# The last method in the labelling chain: it is overridden by the I18n when localization is required.
|
122
|
-
def strftime(time, **opts)
|
59
|
+
# Apply the strftime format to the time (overridden by the i18n extra when localization is required)
|
60
|
+
def localize(time, opts)
|
123
61
|
time.strftime(opts[:format])
|
124
62
|
end
|
125
63
|
|
126
|
-
|
127
|
-
|
128
|
-
# Simple trick to snap the page into its ordered position,
|
129
|
-
# without actually reordering anything in the internal structure
|
130
|
-
def snap(page = @page)
|
64
|
+
# Simple trick to snap the page to its ordered start, without actually reordering anything in the internal structure.
|
65
|
+
def snap(page)
|
131
66
|
@order == :asc ? page - 1 : @pages - page
|
132
67
|
end
|
133
68
|
|
@@ -135,24 +70,20 @@ class Pagy # :nodoc:
|
|
135
70
|
def new_time(year, month = 1, day = 1)
|
136
71
|
Time.new(year, month, day, 0, 0, 0, @utc_offset)
|
137
72
|
end
|
73
|
+
end
|
74
|
+
require 'pagy/calendar/year'
|
75
|
+
require 'pagy/calendar/month'
|
76
|
+
require 'pagy/calendar/week'
|
77
|
+
require 'pagy/calendar/day'
|
138
78
|
|
139
|
-
|
140
|
-
|
141
|
-
(time.year * 12) + time.month
|
142
|
-
end
|
79
|
+
class Calendar # :nodoc:
|
80
|
+
UNITS = { year: Year, month: Month, week: Week, day: Day }.freeze
|
143
81
|
|
144
|
-
#
|
145
|
-
def
|
146
|
-
|
147
|
-
year = months / 12
|
148
|
-
month = months % 12
|
149
|
-
month.zero? ? new_time(year - 1, 12) : new_time(year, month)
|
150
|
-
end
|
82
|
+
# Create a subclass instance by unit name (internal use)
|
83
|
+
def self.create(unit, vars)
|
84
|
+
raise InternalError, "unit must be in #{UNITS.keys.inspect}; got #{unit}" unless UNITS.key?(unit)
|
151
85
|
|
152
|
-
|
153
|
-
def week_start(time)
|
154
|
-
start = time - (((time.wday - @week_offset) * DAY) % WEEK)
|
155
|
-
new_time(start.year, start.month, start.day)
|
86
|
+
UNITS[unit].new(vars)
|
156
87
|
end
|
157
88
|
end
|
158
89
|
end
|
data/lib/pagy/countless.rb
CHANGED
@@ -8,13 +8,13 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module BootstrapExtra
|
10
10
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
11
|
-
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
14
14
|
|
15
15
|
html = +%(<nav#{p_id} class="pagy-bootstrap-nav" aria-label="pager"><ul class="pagination">)
|
16
16
|
html << pagy_bootstrap_prev_html(pagy, link)
|
17
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
19
19
|
when Integer
|
20
20
|
%(<li class="page-item">#{link.call item}</li>)
|
@@ -30,7 +30,7 @@ class Pagy # :nodoc:
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
33
|
-
def pagy_bootstrap_nav_js(pagy, pagy_id: nil, link_extra: '',
|
33
|
+
def pagy_bootstrap_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
34
34
|
p_id = %( id="#{pagy_id}") if pagy_id
|
35
35
|
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
36
36
|
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
|
@@ -40,7 +40,7 @@ class Pagy # :nodoc:
|
|
40
40
|
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }
|
41
41
|
|
42
42
|
%(<nav#{p_id} class="pagy-njs pagy-bootstrap-nav-js" aria-label="pager" #{
|
43
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
43
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></nav>)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -8,14 +8,14 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module BulmaExtra
|
10
10
|
# Pagination for Bulma: it returns the html with the series of links to the pages
|
11
|
-
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
|
15
15
|
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination is-centered" aria-label="pagination">)
|
16
16
|
html << pagy_bulma_prev_next_html(pagy, link)
|
17
17
|
html << %(<ul class="pagination-list">)
|
18
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
19
19
|
html << case item
|
20
20
|
when Integer
|
21
21
|
%(<li>#{link.call item, pagy.label_for(item), %(class="pagination-link" aria-label="goto page #{item}")}</li>)
|
@@ -30,7 +30,7 @@ class Pagy # :nodoc:
|
|
30
30
|
html << %(</ul></nav>)
|
31
31
|
end
|
32
32
|
|
33
|
-
def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '',
|
33
|
+
def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
34
34
|
p_id = %( id="#{pagy_id}") if pagy_id
|
35
35
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
36
36
|
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
|
@@ -43,7 +43,7 @@ class Pagy # :nodoc:
|
|
43
43
|
'after' => '</ul>' }
|
44
44
|
|
45
45
|
%(<nav#{p_id} class="pagy-njs pagy-bulma-nav-js pagination is-centered" aria-label="pagination" #{
|
46
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
46
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></nav>)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/extras/calendar.rb
CHANGED
@@ -4,32 +4,71 @@
|
|
4
4
|
require 'pagy/calendar'
|
5
5
|
|
6
6
|
class Pagy # :nodoc:
|
7
|
-
# Paginate based on calendar periods (year month week day)
|
7
|
+
# Paginate based on calendar periods (year month week day) plus the regular pagination
|
8
8
|
module CalendarExtra
|
9
9
|
# Additions for the Backend module
|
10
10
|
module Backend
|
11
|
+
CONF_KEYS = %i[year month week day pagy active].freeze
|
12
|
+
|
11
13
|
private
|
12
14
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
# Take a collection and a conf Hash with keys in [:year, :month: week, :day, :pagy: :active];
|
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
|
21
|
+
def pagy_calendar(collection, conf)
|
22
|
+
unless conf.is_a?(Hash) && (conf.keys - CONF_KEYS).empty? && conf.all? { |k, v| v.is_a?(Hash) || k == :active }
|
23
|
+
raise ArgumentError, "keys must be in #{CONF_KEYS.inspect} and object values must be Hashes; got #{conf.inspect}"
|
24
|
+
end
|
25
|
+
|
26
|
+
conf[:pagy] = {} unless conf[:pagy] # use default Pagy object when omitted
|
27
|
+
calendar, collection = pagy_setup_calendar(collection, conf) unless conf.key?(:active) && !conf[:active]
|
28
|
+
pagy, result = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
|
29
|
+
[calendar, pagy, result]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Setup and return the calendar objects and the filtered collection
|
33
|
+
def pagy_setup_calendar(collection, conf)
|
34
|
+
units = Calendar::UNITS.keys & conf.keys
|
35
|
+
page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
|
36
|
+
units.each do |unit| # set all the :page_param vars for later deletion
|
37
|
+
unit_page_param = :"#{unit}_#{page_param}"
|
38
|
+
conf[unit][:page_param] = unit_page_param
|
39
|
+
conf[unit][:page] = params[unit_page_param]
|
40
|
+
end
|
41
|
+
calendar = {}
|
42
|
+
period = pagy_calendar_period(collection)
|
43
|
+
units.each_with_index do |unit, index|
|
44
|
+
params_to_delete = units[(index + 1), units.size].map { |sub| conf[sub][:page_param] } + [page_param]
|
45
|
+
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
|
47
|
+
params
|
48
|
+
end
|
49
|
+
conf[unit][:period] = period
|
50
|
+
calendar[unit] = Calendar.create(unit, conf[unit])
|
51
|
+
period = calendar[unit].active_period # set the period for the next unit
|
52
|
+
end
|
53
|
+
[calendar, pagy_calendar_filter(collection, calendar[units.last].from, calendar[units.last].to)]
|
17
54
|
end
|
18
55
|
|
19
|
-
#
|
20
|
-
#
|
21
|
-
def
|
22
|
-
#
|
23
|
-
|
24
|
-
|
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
|
58
|
+
def pagy_calendar_period(*)
|
59
|
+
# return_period_array_using(collection)
|
60
|
+
raise NoMethodError, 'the pagy_calendar_period method must be implemented by the application and must return ' \
|
61
|
+
'the starting and ending local Time objects array defining the calendar :period'
|
25
62
|
end
|
26
63
|
|
27
|
-
# This method
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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}
|
67
|
+
def pagy_calendar_filter(*)
|
68
|
+
# return_filtered_collection_using(collection, from, to)
|
69
|
+
raise NoMethodError, 'the pagy_calendar_filter method must be implemented by the application and must return the ' \
|
70
|
+
'collection filtered by a logic equivalent to '\
|
71
|
+
'{storage_time >= from && storage_time < to}'
|
33
72
|
end
|
34
73
|
end
|
35
74
|
end
|
@@ -8,13 +8,13 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module FoundationExtra
|
10
10
|
# Pagination for Foundation: it returns the html with the series of links to the pages
|
11
|
-
def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
|
15
15
|
html = +%(<nav#{p_id} class="pagy-foundation-nav" aria-label="Pagination"><ul class="pagination">)
|
16
16
|
html << pagy_foundation_prev_html(pagy, link)
|
17
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
19
19
|
when Integer then %(<li>#{link.call item}</li>) # page link
|
20
20
|
when String then %(<li class="current">#{pagy.label_for(item)}</li>) # active page
|
@@ -27,7 +27,7 @@ class Pagy # :nodoc:
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
30
|
-
def pagy_foundation_nav_js(pagy, pagy_id: nil, link_extra: '',
|
30
|
+
def pagy_foundation_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
31
31
|
p_id = %( id="#{pagy_id}") if pagy_id
|
32
32
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
33
33
|
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
|
@@ -37,7 +37,7 @@ class Pagy # :nodoc:
|
|
37
37
|
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
|
38
38
|
|
39
39
|
%(<nav#{p_id} class="pagy-njs pagy-foundation-nav-js" aria-label="Pagination" #{
|
40
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
40
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></nav>)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
@@ -18,12 +18,11 @@ class Pagy # :nodoc:
|
|
18
18
|
# "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
|
19
19
|
# "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
|
20
20
|
# Notice: if :steps is false it will use the single {0 => @vars[:size]} size
|
21
|
-
def sequels(steps
|
22
|
-
steps ||= @vars[:steps] || { 0 => @vars[:size] }
|
21
|
+
def sequels(steps: @vars[:steps] || { 0 => @vars[:size] })
|
23
22
|
raise VariableError.new(self, :steps, 'to define the 0 width', steps) unless steps.key?(0)
|
24
23
|
|
25
24
|
{}.tap do |sequels|
|
26
|
-
steps.each { |width,
|
25
|
+
steps.each { |width, step_size| sequels[width.to_s] = series(size: step_size) }
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
data/lib/pagy/extras/i18n.rb
CHANGED
@@ -8,13 +8,13 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module MaterializeExtra
|
10
10
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
11
|
-
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
|
15
15
|
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
|
16
16
|
html << pagy_materialize_prev_html(pagy, link)
|
17
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
19
19
|
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
20
20
|
when String then %(<li class="active">#{link.call item}</li>) # active page
|
@@ -27,7 +27,7 @@ class Pagy # :nodoc:
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
30
|
-
def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '',
|
30
|
+
def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
31
31
|
p_id = %( id="#{pagy_id}") if pagy_id
|
32
32
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
33
33
|
|
@@ -38,7 +38,7 @@ class Pagy # :nodoc:
|
|
38
38
|
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }
|
39
39
|
|
40
40
|
%(<div#{p_id} class="pagy-njs pagy-materialize-nav-js" role="navigation" aria-label="pager" #{
|
41
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
41
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></div>)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -8,7 +8,7 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module NavsExtra
|
10
10
|
# Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
11
|
-
def pagy_nav_js(pagy, pagy_id: nil, link_extra: '',
|
11
|
+
def pagy_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
tags = { 'before' => pagy_nav_prev_html(pagy, link),
|
@@ -18,7 +18,7 @@ class Pagy # :nodoc:
|
|
18
18
|
'after' => pagy_nav_next_html(pagy, link) }
|
19
19
|
|
20
20
|
%(<nav#{p_id} class="pagy-njs pagy-nav-js pagination" aria-label="pager" #{
|
21
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
21
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></nav>)
|
22
22
|
end
|
23
23
|
|
24
24
|
# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -29,8 +29,8 @@ class Pagy # :nodoc:
|
|
29
29
|
when :empty_page
|
30
30
|
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
31
31
|
if defined?(Calendar) && is_a?(Calendar) # only for Calendar instances
|
32
|
-
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but
|
33
|
-
@
|
32
|
+
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but any time would do)
|
33
|
+
@from = @to = edge # set both to the edge utc time (a >=&&< query will get no records)
|
34
34
|
end
|
35
35
|
@prev = @last # prev relative to the actual page
|
36
36
|
extend Series # special series for :empty_page
|
@@ -41,9 +41,9 @@ class Pagy # :nodoc:
|
|
41
41
|
|
42
42
|
# Special series for empty page
|
43
43
|
module Series
|
44
|
-
def series(
|
44
|
+
def series(*)
|
45
45
|
@page = @last # series for last page
|
46
|
-
super
|
46
|
+
super.tap do |s| # call original series
|
47
47
|
s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
|
48
48
|
@page = @vars[:page] # restore the actual page
|
49
49
|
end
|
@@ -63,7 +63,7 @@ class Pagy # :nodoc:
|
|
63
63
|
when :exception
|
64
64
|
raise # same as without the extra
|
65
65
|
when :empty_page
|
66
|
-
@offset = @items = @from = @to = 0
|
66
|
+
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
67
67
|
@vars[:size] = [] # no page in the series
|
68
68
|
self
|
69
69
|
else
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -8,13 +8,13 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module SemanticExtra
|
10
10
|
# Pagination for semantic: it returns the html with the series of links to the pages
|
11
|
-
def pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_semantic_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))
|
14
14
|
|
15
15
|
html = +%(<div#{p_id} class="pagy-semantic-nav ui pagination menu">)
|
16
16
|
html << pagy_semantic_prev_html(pagy, link)
|
17
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
19
19
|
when Integer then link.call item
|
20
20
|
when String then %(<a class="item active">#{pagy.label_for(item)}</a>)
|
@@ -27,7 +27,7 @@ class Pagy # :nodoc:
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
30
|
-
def pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '',
|
30
|
+
def pagy_semantic_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
31
31
|
p_id = %( id="#{pagy_id}") if pagy_id
|
32
32
|
link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))
|
33
33
|
tags = { 'before' => pagy_semantic_prev_html(pagy, link),
|
@@ -37,7 +37,7 @@ class Pagy # :nodoc:
|
|
37
37
|
'after' => pagy_semantic_next_html(pagy, link) }
|
38
38
|
|
39
39
|
%(<div#{p_id} class="pagy-njs pagy-semantic-nav-js ui pagination menu" role="navigation" #{
|
40
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
40
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></div>)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -8,12 +8,12 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module UikitExtra
|
10
10
|
# Pagination for uikit: it returns the html with the series of links to the pages
|
11
|
-
def pagy_uikit_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
def pagy_uikit_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
|
15
15
|
html = +%(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
|
16
|
-
pagy.series.each do |item|
|
16
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
17
|
html << case item
|
18
18
|
when Integer then %(<li>#{link.call item}</li>)
|
19
19
|
when String then %(<li class="uk-active"><span>#{pagy.label_for(item)}</span></li>)
|
@@ -26,7 +26,7 @@ class Pagy # :nodoc:
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Javascript pagination for uikit: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
29
|
-
def pagy_uikit_nav_js(pagy, pagy_id: nil, link_extra: '',
|
29
|
+
def pagy_uikit_nav_js(pagy, pagy_id: nil, link_extra: '', **vars)
|
30
30
|
p_id = %( id="#{pagy_id}") if pagy_id
|
31
31
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
32
32
|
tags = { 'before' => pagy_uikit_prev_html(pagy, link),
|
@@ -36,7 +36,7 @@ class Pagy # :nodoc:
|
|
36
36
|
'after' => pagy_uikit_next_html(pagy, link) }
|
37
37
|
|
38
38
|
%(<ul#{p_id} class="pagy-njs pagy-uikit-nav-js uk-pagination uk-flex-center" #{
|
39
|
-
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(
|
39
|
+
pagy_json_attr(pagy, :nav, tags, (sequels = pagy.sequels(**vars)), pagy.label_sequels(sequels))}></ul>)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Javascript combo pagination for uikit: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
data/lib/pagy/frontend.rb
CHANGED
@@ -15,7 +15,7 @@ class Pagy
|
|
15
15
|
include UrlHelpers
|
16
16
|
|
17
17
|
# Generic pagination: it returns the html with the series of links to the pages
|
18
|
-
def pagy_nav(pagy, pagy_id: nil, link_extra: '')
|
18
|
+
def pagy_nav(pagy, pagy_id: nil, link_extra: '', **vars)
|
19
19
|
p_id = %( id="#{pagy_id}") if pagy_id
|
20
20
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
21
21
|
p_prev = pagy.prev
|
@@ -27,7 +27,7 @@ class Pagy
|
|
27
27
|
else
|
28
28
|
%(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> )
|
29
29
|
end
|
30
|
-
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
30
|
+
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
31
31
|
html << case item
|
32
32
|
when Integer then %(<span class="page">#{link.call item}</span> )
|
33
33
|
when String then %(<span class="page active">#{pagy.label_for(item)}</span> )
|
data/lib/pagy/url_helpers.rb
CHANGED
@@ -23,7 +23,7 @@ class Pagy
|
|
23
23
|
private
|
24
24
|
|
25
25
|
# Transitional code to handle params deprecations. It will be removed in version 6.0
|
26
|
-
def pagy_deprecated_params(pagy, params)
|
26
|
+
def pagy_deprecated_params(pagy, params) # remove in 6.0
|
27
27
|
if pagy.params.is_a?(Proc) # new code
|
28
28
|
pagy.params.call(params)
|
29
29
|
elsif respond_to?(:pagy_massage_params) # deprecated code
|
data/lib/pagy.rb
CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# Core class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '5.
|
8
|
+
VERSION = '5.5.1'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
@@ -44,7 +44,7 @@ class Pagy
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
47
|
-
def series(size
|
47
|
+
def series(size: @vars[:size])
|
48
48
|
return [] if size.empty?
|
49
49
|
raise VariableError.new(self, :size, 'to contain 4 items >= 0', size) \
|
50
50
|
unless size.is_a?(Array) && size.size == 4 && size.all? { |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
|
@@ -5,7 +5,7 @@
|
|
5
5
|
The link variable is set to a proc that returns the link tag.
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
|
-
<% link = pagy_link_proc(pagy, 'class="page-link"') -%>
|
8
|
+
<% link = pagy_link_proc(pagy, link_extra: 'class="page-link"') -%>
|
9
9
|
<%# -%><nav aria-label="pager" class="pagy-bootstrap-nav" role="navigation">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
-# The link variable is set to a proc that returns the link tag.
|
5
5
|
-# Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
6
6
|
|
7
|
-
- link = pagy_link_proc(pagy, 'class="page-link"')
|
7
|
+
- link = pagy_link_proc(pagy, link_extra: 'class="page-link"')
|
8
8
|
|
9
9
|
%nav.pagy-bootstrap-nav{"aria-label" => "pager", :role => "navigation"}
|
10
10
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
/ The link variable is set to a proc that returns the link tag.
|
5
5
|
/ Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
6
6
|
|
7
|
-
- link = pagy_link_proc(pagy, 'class="page-link"')
|
7
|
+
- link = pagy_link_proc(pagy, link_extra: 'class="page-link"')
|
8
8
|
|
9
9
|
nav.pagy-bootstrap-nav role="navigation" aria-label="pager"
|
10
10
|
|
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.
|
4
|
+
version: 5.5.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-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|
@@ -54,6 +54,10 @@ files:
|
|
54
54
|
- lib/pagy.rb
|
55
55
|
- lib/pagy/backend.rb
|
56
56
|
- lib/pagy/calendar.rb
|
57
|
+
- lib/pagy/calendar/day.rb
|
58
|
+
- lib/pagy/calendar/month.rb
|
59
|
+
- lib/pagy/calendar/week.rb
|
60
|
+
- lib/pagy/calendar/year.rb
|
57
61
|
- lib/pagy/console.rb
|
58
62
|
- lib/pagy/countless.rb
|
59
63
|
- lib/pagy/exceptions.rb
|
@@ -102,7 +106,8 @@ files:
|
|
102
106
|
homepage: https://github.com/ddnexus/pagy
|
103
107
|
licenses:
|
104
108
|
- MIT
|
105
|
-
metadata:
|
109
|
+
metadata:
|
110
|
+
rubygems_mfa_required: 'true'
|
106
111
|
post_install_message:
|
107
112
|
rdoc_options: []
|
108
113
|
require_paths:
|