pagy 5.3.1 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3530b69891d7c069acdb707d6fa54e8b5d31763a80e57dae2e0fe3afafce8b2
4
- data.tar.gz: defdc75e9f60ae351e8b071fffd3bf4767e28d51edd8ec6398a1b5958d688084
3
+ metadata.gz: 4a62cb4c6decfdc1013da6d14b38220aa361246637301a8d92b2d781440397bc
4
+ data.tar.gz: 2555195198def80d6ec002928da8cef07419a76da9a196d8971d50e7fb5095e2
5
5
  SHA512:
6
- metadata.gz: 13dc93a7f0de2f1e4a688292e1901905df218d500fe1543e4d518dab1f1e7f7d2276cc63f197c251b1ed14e8fea4b46d8be4590ccbad89cfed11d70481a769a2
7
- data.tar.gz: f6ddac95479d63445920df9bad22142f59b9b14e2a4c758303c76389eefd1a475ce49dd1e781e70519bed0a081c1b2296bb19be6ca6e50feefa0abb9660749a6
6
+ metadata.gz: f665f63cb281c25d6fcf430c12888def46ea46911e45a566fd52cb4943763efe775b094015d3b658b8322ade23a9a43a5888c60f10471bd567f000d5a67352c7
7
+ data.tar.gz: 8c22ab2ad5efc0bd91b648d89217d1b71d77fbf669e1153b015954b79c2506c8f5ffe29d80e7d5988bea76b4bed35e7a76bb9c3657f60de0db3cde84b38e62e2
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.3.1)
3
+ # Pagy initializer file (5.6.0)
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: Paginate a collection by calendar Time unit (year, month, week or day)
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
- # Pagy::DEFAULT[:local_minmax] = [] # Min and max local Time period must be set by the user (better not not as default)
47
- # Pagy::DEFAULT[:unit] = :month # Time unit allowed %i[year month week day]
48
- # Pagy::DEFAULT[:week_offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
49
- # Pagy::DEFAULT[:order] = :asc # Time direction of pagination
50
- # Pagy::DEFAULT[:year_format] = '%Y' # strftime format for :year unit
51
- # Pagy::DEFAULT[:month_format] = '%Y-%m' # strftime format for :month unit
52
- # Pagy::DEFAULT[:week_format] = '%Y-%W' # strftime format for :week unit
53
- # Pagy::DEFAULT[:day_format] = '%Y-%m-%d' # strftime format for :day unit
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 defaults freeze it,
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
@@ -5,7 +5,7 @@
5
5
  // Container of the whole pagy stuff
6
6
  function Pagy(){}
7
7
 
8
- Pagy.version = '5.3.1'
8
+ Pagy.version = '5.6.0'
9
9
 
10
10
  // Used by the waitForMe function
11
11
  Pagy.delay = 100
@@ -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,16 @@
1
+ # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'month_mixin'
5
+
6
+ class Pagy # :nodoc:
7
+ class Calendar # :nodoc:
8
+ # Calendar month subclass
9
+ class Month < Calendar
10
+ DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
11
+ format: '%Y-%m' }
12
+ MONTHS = 1 # number of months in the unit
13
+ include MonthMixin
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+ class Calendar
5
+ # Mixin for month based unit periods
6
+ # It is used for month and quarter, but you could use it to implement less common unit of 6, 4, 2 months
7
+ # (see the https://ddnexus.github.io/pagy/api/calendar#custom-units sections for details).
8
+ # The class that includes it needs to set the MONTH duration for the unit and the usual DEFAULT.
9
+ module MonthMixin
10
+ protected
11
+
12
+ # Setup the calendar variables
13
+ def setup_unit_vars
14
+ super
15
+ @months = self.class::MONTHS # number of months in the unit
16
+ @initial = new_time(@starting.year, beginning_month(@starting.month))
17
+ @final = add_to(new_time(@ending.year, beginning_month(@ending.month)), @months)
18
+ @pages = @last = (months_in(@final) - months_in(@initial)) / @months
19
+ @from = start_for(@page)
20
+ @to = add_to(@from, @months)
21
+ end
22
+
23
+ # Time for the page
24
+ def start_for(page)
25
+ add_to(@initial, snap(page) * @months)
26
+ end
27
+
28
+ # Return the beginning month for the unit (e.g. quarter) that includes the month argument
29
+ def beginning_month(month)
30
+ (@months * ((month - 1) / @months)) + 1
31
+ end
32
+
33
+ private
34
+
35
+ # Months in time
36
+ def months_in(time)
37
+ (time.year * 12) + time.month
38
+ end
39
+
40
+ # Add months to time
41
+ def add_to(time, months)
42
+ months += months_in(time)
43
+ year = months / 12
44
+ month = months % 12
45
+ month.zero? ? new_time(year - 1, 12) : new_time(year, month)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'month_mixin'
5
+
6
+ class Pagy # :nodoc:
7
+ class Calendar # :nodoc:
8
+ # Calendar quarter subclass
9
+ class Quarter < Calendar
10
+ DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
11
+ format: '%Y-Q%q' }
12
+ MONTHS = 3 # number of months of the unit
13
+ include MonthMixin
14
+ end
15
+ end
16
+ 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 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,24 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy'
5
- require 'date'
6
5
 
7
6
  class Pagy # :nodoc:
8
- DEFAULT[:local_minmax] = [] # Min and max Time period must be set by the user
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, Quarter, Month, Week, Day)
18
8
  class Calendar < Pagy
19
- attr_reader :utc_from, :utc_to, :unit, :week_offset, :order
20
- attr_writer :count, :in
9
+ # List of units in desc order of duration. It can be used for custom units.
10
+ UNITS = %i[year quarter month week day] # rubocop:disable Style/MutableConstant
11
+ DAY = 60 * 60 * 24 # One day in seconds
12
+ WEEK = DAY * 7 # One week in seconds
13
+
14
+ attr_reader :order
21
15
 
22
16
  # Merge and validate the options, do some simple arithmetic and set a few instance variables
23
17
  def initialize(vars) # rubocop:disable Lint/MissingSuper
24
- normalize_vars(vars)
25
- setup_vars(page: 1, week_offset: 0)
18
+ raise InternalError, 'Pagy::Calendar is a base class; use one of its subclasses' if instance_of?(Pagy::Calendar)
19
+
20
+ vars = self.class::DEFAULT.merge(vars) # subclass specific default
21
+ normalize_vars(vars) # general default
22
+ setup_vars(page: 1)
26
23
  setup_unit_vars
27
24
  setup_params_var
28
25
  raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
@@ -31,104 +28,45 @@ class Pagy # :nodoc:
31
28
  @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
32
29
  end
33
30
 
34
- # Generate a label for each page, with the specific `Time` period it refers to
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
- localize(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)
31
+ # The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
51
32
  def label(**opts)
52
33
  label_for(@page, **opts)
53
34
  end
54
35
 
55
- DAY = 60 * 60 * 24
56
- WEEK = DAY * 7
36
+ # The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
37
+ def label_for(page, **opts)
38
+ opts[:format] ||= @vars[:format]
39
+ start = start_for(page.to_i)
40
+ opts[:format] = opts[:format].gsub('%q') { (start.month / 4) + 1 }
41
+ localize(start, **opts)
42
+ end
43
+
44
+ # Period of the active page (used for nested units)
45
+ def active_period
46
+ [[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
47
+ end
57
48
 
58
49
  protected
59
50
 
51
+ # Base class method for the setup of the unit variables
60
52
  def setup_unit_vars
61
- (units = %i[year month week day]).each do |unit|
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])
53
+ raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
67
54
  raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
68
55
  unless %i[asc desc].include?(@order = @vars[:order])
69
56
 
70
- min, max = @vars[:local_minmax]
71
- raise VariableError.new(self, :local_minmax, 'to be a an Array of min and max local Time instances', @vars[:local_minmax]) \
72
- unless min.is_a?(Time) && max.is_a?(Time) && !min.utc? && !max.utc? && min <= max \
73
- && (@utc_offset = min.utc_offset) == max.utc_offset
74
-
75
- send :"setup_#{@unit}_vars", min, max
57
+ @starting, @ending = @vars[:period]
58
+ raise VariableError.new(self, :period, 'to be a an Array of min and max local Time instances', @vars[:period]) \
59
+ unless @starting.is_a?(Time) && @ending.is_a?(Time) && !@starting.utc? && !@ending.utc? && @starting <= @ending \
60
+ && (@utc_offset = @starting.utc_offset) == @ending.utc_offset
76
61
  end
77
62
 
78
- # IMPORTANT: all the Time objects created and passed as arguments MUST be local!
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
- # Apply the strftime format to the time
122
- # (overridden by the i18n extra when localization is required)
123
- def localize(time, **opts)
63
+ # Apply the strftime format to the time (overridden by the i18n extra when localization is required)
64
+ def localize(time, opts)
124
65
  time.strftime(opts[:format])
125
66
  end
126
67
 
127
- private
128
-
129
- # Simple trick to snap the page into its ordered position,
130
- # without actually reordering anything in the internal structure
131
- def snap(page = @page)
68
+ # Simple trick to snap the page to its ordered start, without actually reordering anything in the internal structure
69
+ def snap(page)
132
70
  @order == :asc ? page - 1 : @pages - page
133
71
  end
134
72
 
@@ -137,23 +75,17 @@ class Pagy # :nodoc:
137
75
  Time.new(year, month, day, 0, 0, 0, @utc_offset)
138
76
  end
139
77
 
140
- # Months in local time
141
- def months(time)
142
- (time.year * 12) + time.month
143
- end
144
-
145
- # Add 1 or more months to local time
146
- def bump_month(time, months = 1)
147
- months += months(time)
148
- year = months / 12
149
- month = months % 12
150
- month.zero? ? new_time(year - 1, 12) : new_time(year, month)
151
- end
78
+ class << self
79
+ # Create a subclass instance by unit name (internal use)
80
+ def create(unit, vars)
81
+ raise InternalError, "unit must be in #{UNITS.inspect}; got #{unit}" unless UNITS.include?(unit)
152
82
 
153
- # Return the start of the week for local time
154
- def week_start(time)
155
- start = time - (((time.wday - @week_offset) * DAY) % WEEK)
156
- new_time(start.year, start.month, start.day)
83
+ name = unit.to_s
84
+ name[0] = name[0].capitalize
85
+ Object.const_get("Pagy::Calendar::#{name}").new(vars)
86
+ end
157
87
  end
158
88
  end
89
+
90
+ Calendar::UNITS.each { |unit| require "pagy/calendar/#{unit}" }
159
91
  end
@@ -30,7 +30,7 @@ class Pagy
30
30
 
31
31
  # Override the original series.
32
32
  # Return nil if :countless_minimal is enabled
33
- def series(_size = @vars[:size])
33
+ def series(*)
34
34
  super unless @vars[:countless_minimal]
35
35
  end
36
36
  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 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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></nav>)
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
@@ -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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></nav>)
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
@@ -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 = (Calendar::UNITS + %i[pagy active]).freeze
12
+
11
13
  private
12
14
 
13
- # Return Pagy object and items
14
- def pagy_calendar(collection, vars = {})
15
- pagy = Calendar.new(pagy_calendar_get_vars(collection, vars))
16
- [pagy, pagy_calendar_get_items(collection, pagy)]
15
+ # Take a collection and a conf Hash with keys in [:year, :quarter, :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 & conf.keys # get the units in time length desc order
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.send(: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
- # Sub-method called only by #pagy_calendar: here for easy customization of variables by overriding.
20
- # You may want to override it in order to implement the dynamic set of the :minmax variable.
21
- def pagy_calendar_get_vars(_collection, vars)
22
- # vars[:minmax] ||= your_own_method_to_get_the_period_from(collection)
23
- vars[:page] ||= params[vars[:page_param] || DEFAULT[:page_param]]
24
- vars
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 should be implemented in the application and should return the records
28
- # for the unit by selecting the records with Time from pagy.utc_from to pagy.utc_to
29
- def pagy_calendar_get_items(_collection, _pagy)
30
- # collection.your_own_method_to_get_the_items_with(pagy.utc_from, pagy.utc_to)
31
- raise NoMethodError, 'The pagy_calendar_get_items method must be implemented in the application and must return ' \
32
- 'the items for the unit by selecting the records with Time from pagy.utc_from to pagy.utc_to'
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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></nav>)
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 = nil)
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, size| sequels[width.to_s] = series(size) }
25
+ steps.each { |width, step_size| sequels[width.to_s] = series(size: step_size) }
27
26
  end
28
27
  end
29
28
 
@@ -13,7 +13,7 @@ class Pagy # :nodoc:
13
13
 
14
14
  # Calendar overriding
15
15
  module Calendar
16
- def localize(time, **opts)
16
+ def localize(time, opts)
17
17
  ::I18n.l(time, **opts)
18
18
  end
19
19
  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 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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></div>)
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
@@ -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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></nav>)
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
@@ -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 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)
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(size = @vars[:size])
44
+ def series(*)
45
45
  @page = @last # series for last page
46
- super(size).tap do |s| # call original series
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 # vars relative to the actual page
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
@@ -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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></div>)
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
@@ -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: '', steps: nil)
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(steps)), pagy.label_sequels(sequels))}></ul>)
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> )
@@ -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) # remove in 6.0
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.3.1'
8
+ VERSION = '5.6.0'
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 = @vars[: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.3.1
4
+ version: 5.6.0
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-12 00:00:00.000000000 Z
11
+ date: 2021-11-26 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,12 @@ 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/month_mixin.rb
60
+ - lib/pagy/calendar/quarter.rb
61
+ - lib/pagy/calendar/week.rb
62
+ - lib/pagy/calendar/year.rb
57
63
  - lib/pagy/console.rb
58
64
  - lib/pagy/countless.rb
59
65
  - lib/pagy/exceptions.rb
@@ -102,7 +108,8 @@ files:
102
108
  homepage: https://github.com/ddnexus/pagy
103
109
  licenses:
104
110
  - MIT
105
- metadata: {}
111
+ metadata:
112
+ rubygems_mfa_required: 'true'
106
113
  post_install_message:
107
114
  rdoc_options: []
108
115
  require_paths: