pagy 5.2.3 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 500b8bfdb84150bd2ec01036eb55b53eeadcb1b0ab1fdc0721cee5fdf7fed46e
4
- data.tar.gz: 9a75dbbf42e34e1ef12106e4a567acb408d22600fdb34fd42137a4b0dd61c8f3
3
+ metadata.gz: 78c55595ac8caaa34c73688103333dc62e9ebb395696725e7c305e5ace3d7f42
4
+ data.tar.gz: 3e259f8f72025fc7955fb6107920be08025539d5178e5c4c714173d26aa05da1
5
5
  SHA512:
6
- metadata.gz: 7ee826ffb154387f67275568fef53b557e6b16879017a0658701999bfcb34934322a1c645aa26afc599fa7fc2fbc69743878582d8d5f0d21054609610d49e578
7
- data.tar.gz: c0334539b13212ac107aaabab36d2a00460682693e75bab9519b320b2446942a8340f191542cab531ef0de6f9af2df3baf9d74a77b2f2c7154178954428b9616
6
+ metadata.gz: fede5003b2a686ee972d7dd93a80b5221704518212adb8faa7b133c309b2ece0094f3fbe72575fb4e29b706a819f5dc447fc6f3a89b4c3fe202e23542dfee310
7
+ data.tar.gz: 15840445b0afa7e343c9f0f4ad196b847cb564d8d2a5da56b94a9a59ac348731fc6bb104c282343f77654a0d07090dd501957e751c843c88de208779581dbbae
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.2.3)
3
+ # Pagy initializer file (5.5.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
 
@@ -22,6 +22,7 @@
22
22
  # See https://ddnexus.github.io/pagy/api/pagy#other-variables
23
23
  # Pagy::DEFAULT[:size] = [1,4,4,1] # default
24
24
  # Pagy::DEFAULT[:page_param] = :page # default
25
+ # The :params can be also set as a lambda e.g ->(params){ params.exclude('useless').merge!('custom' => 'useful') }
25
26
  # Pagy::DEFAULT[:params] = {} # default
26
27
  # Pagy::DEFAULT[:fragment] = '#fragment' # example
27
28
  # Pagy::DEFAULT[:link_extra] = 'data-remote="true"' # example
@@ -39,17 +40,30 @@
39
40
  # See https://ddnexus.github.io/pagy/extras/array
40
41
  # require 'pagy/extras/array'
41
42
 
42
- # 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)
43
44
  # See https://ddnexus.github.io/pagy/extras/calendar
44
45
  # require 'pagy/extras/calendar'
45
- # Pagy::DEFAULT[:local_minmax] = [] # Min and max local Time period must be set by the user (better not not as default)
46
- # Pagy::DEFAULT[:unit] = :month # Time unit allowed %i[year month week day]
47
- # Pagy::DEFAULT[:week_offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
48
- # Pagy::DEFAULT[:order] = :asc # Time direction of pagination
49
- # Pagy::DEFAULT[:year_format] = '%Y' # strftime format for :year unit
50
- # Pagy::DEFAULT[:month_format] = '%Y-%m' # strftime format for :month unit
51
- # Pagy::DEFAULT[:week_format] = '%Y-%W' # strftime format for :week unit
52
- # 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
53
67
 
54
68
  # Countless extra: Paginate without any count, saving one query per rendering
55
69
  # See https://ddnexus.github.io/pagy/extras/countless
@@ -218,6 +232,5 @@
218
232
  # Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
219
233
 
220
234
 
221
- # When you are done setting your own defaults freeze it,
222
- # so it will not changed accidentally
235
+ # When you are done setting your own default freeze it, so it will not get changed accidentally
223
236
  Pagy::DEFAULT.freeze
@@ -1,9 +1,11 @@
1
1
  // See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
2
2
 
3
+ // This code should be OK also with very old browsers
4
+
3
5
  // Container of the whole pagy stuff
4
6
  function Pagy(){}
5
7
 
6
- Pagy.version = '5.2.3'
8
+ Pagy.version = '5.5.0'
7
9
 
8
10
  // Used by the waitForMe function
9
11
  Pagy.delay = 100
@@ -23,10 +25,11 @@ Pagy.init =
23
25
 
24
26
  // Power the pagy*_nav_js helpers
25
27
  Pagy.nav =
26
- function(pagyEl, tags, sequels, trimParam) {
27
- var lastWidth,
28
- pageREg = new RegExp(/__pagy_page__/g),
29
- widths = []
28
+ function(pagyEl, tags, sequels, label_sequels, trimParam ) {
29
+ label_sequels = (label_sequels === null) ? sequels : label_sequels
30
+ var widths = [], lastWidth,
31
+ fill = function(string, item, label) { return string.replace(/__pagy_page__/g, item)
32
+ .replace(/__pagy_label__/g, label) }
30
33
  for (var width in sequels) {
31
34
  if (sequels.hasOwnProperty(width)) { widths.push(parseInt(width, 10)) }
32
35
  }
@@ -40,13 +43,15 @@ Pagy.nav =
40
43
  }
41
44
  if (width !== lastWidth) {
42
45
  var html = tags.before,
43
- series = sequels[width]
46
+ series = sequels[width],
47
+ labels = label_sequels[width]
44
48
  for (i = 0, len = series.length; i < len; i++) {
45
- var item = series[i]
46
- if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(tags.link.replace(pageREg, item), trimParam) }
47
- else if (typeof(item) === 'number') { html += tags.link.replace(pageREg, item) }
49
+ var item = series[i],
50
+ label = labels[i]
51
+ if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(fill(tags.link, item, label), trimParam) }
52
+ else if (typeof(item) === 'number') { html += fill(tags.link, item, label) }
48
53
  else if (item === 'gap') { html += tags.gap }
49
- else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
54
+ else if (typeof(item) === 'string') { html += fill(tags.active, item, label) }
50
55
  }
51
56
  html += tags.after
52
57
  this.insertAdjacentHTML('afterbegin', html)
@@ -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 = time_for(@page)
20
+ @to = @from + DAY
21
+ end
22
+
23
+ # Time for the page
24
+ def time_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 = time_for(@page)
20
+ @to = bump_month(@from)
21
+ end
22
+
23
+ # Time for the page
24
+ def time_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 = time_for(@page)
22
+ @to = @from + WEEK
23
+ end
24
+
25
+ # Time for the page
26
+ def time_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 = time_for(@page)
20
+ @to = new_time(@from.year + 1)
21
+ end
22
+
23
+ # Time for the page
24
+ def time_for(page)
25
+ new_time(@initial.year + snap(page))
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/pagy/calendar.rb CHANGED
@@ -2,122 +2,68 @@
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, 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
+ 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
- setup_vars(page: 1, week_offset: 0)
19
+ @vars = self.class::DEFAULT.merge(@vars)
20
+ setup_vars(page: 1)
26
21
  setup_unit_vars
22
+ setup_params_var
27
23
  raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
28
24
 
29
25
  @prev = (@page - 1 unless @page == 1)
30
26
  @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
31
27
  end
32
28
 
33
- # Generate a label for each page, with the specific `Time` period it refers to
34
- def page_label(num = @page, format = nil)
35
- snap = snap(num.to_i)
36
- format ||= @vars[:"#{@unit}_format"]
37
- case @unit
38
- when :year then new_time(@initial.year + snap)
39
- when :month then bump_month(@initial, snap)
40
- when :week then @initial + (snap * WEEK)
41
- when :day then @initial + (snap * DAY)
42
- else raise InternalError, "expected @unit to be in [:year, :month, :week, :day]; got #{@unit.inspect}"
43
- end.strftime(format)
29
+ # The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
30
+ def label(**opts)
31
+ label_for(@page, **opts)
44
32
  end
45
33
 
46
- def current_page_label(format = nil)
47
- page_label(@page, format)
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(time_for(page.to_i), **opts)
48
38
  end
49
39
 
50
- DAY = 60 * 60 * 24
51
- WEEK = DAY * 7
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
52
44
 
53
45
  protected
54
46
 
47
+ # Base class method for the setup of the unit variables
55
48
  def setup_unit_vars
56
- (units = %i[year month week day]).each do |unit|
57
- raise VariableError.new(self, :format, 'to be a strftime format', @vars[:"#{unit}_format"]) \
58
- unless @vars[:"#{unit}_format"].is_a?(String)
59
- end
60
- raise VariableError.new(self, :unit, "to be in #{units.inspect}", @unit) \
61
- 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)
62
50
  raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
63
51
  unless %i[asc desc].include?(@order = @vars[:order])
64
52
 
65
- min, max = @vars[:local_minmax]
66
- raise VariableError.new(self, :local_minmax, 'to be a an Array of min and max local Time instances', @vars[:local_minmax]) \
67
- unless min.is_a?(Time) && max.is_a?(Time) && !min.utc? && !min.utc? && min <= max \
68
- && (@utc_offset = min.utc_offset) == max.utc_offset
69
-
70
- send :"setup_#{@unit}_vars", min, max
71
- end
72
-
73
- # IMPORTANT: all the Time objects created and passed as arguments MUST be local!
74
-
75
- # @initial: beginning of the first day of the period that encloses the min local time
76
- # @final: beginning of the first day of the NEXT period AFTER the period that encloses the max local time
77
- # @utc_from: beginning of the first day of the period of the current page as UTC time
78
- # @utc_to: beginning of the first day of the NEXT period AFTER the current page as UTC time
79
-
80
- # Setup the calendar vars when the unit is :year
81
- def setup_year_vars(min, max)
82
- @initial = new_time(min.year)
83
- @final = new_time(max.year + 1)
84
- @pages = @last = @final.year - @initial.year
85
- @utc_from = new_time(@initial.year + snap).utc
86
- @utc_to = new_time(@initial.year + snap + 1).utc
87
- end
88
-
89
- # Setup the calendar vars when the unit is :month
90
- def setup_month_vars(min, max)
91
- @initial = new_time(min.year, min.month)
92
- @final = bump_month(max)
93
- @pages = @last = months(@final) - months(@initial)
94
- @utc_from = bump_month(@initial, snap).utc
95
- @utc_to = bump_month(@initial, snap + 1).utc
96
- end
97
-
98
- # Setup the calendar vars when the unit is :week
99
- def setup_week_vars(min, max)
100
- @initial = week_start(min)
101
- @final = week_start(max) + WEEK
102
- @pages = @last = (@final - @initial).to_i / WEEK
103
- @utc_from = (@initial + (snap * WEEK)).utc
104
- @utc_to = @utc_from + WEEK
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
105
57
  end
106
58
 
107
- # Setup the calendar vars when the unit is :day
108
- def setup_day_vars(min, max)
109
- @initial = new_time(min.year, min.month, min.day)
110
- @final = new_time(max.year, max.month, max.day) + DAY
111
- @pages = @last = (@final - @initial).to_i / DAY
112
- @utc_from = (@initial + (snap * DAY)).utc
113
- @utc_to = @utc_from + DAY
59
+ # Apply the strftime format to the time (overridden by the i18n extra when localization is required)
60
+ def localize(time, opts)
61
+ time.strftime(opts[:format])
114
62
  end
115
63
 
116
- private
117
-
118
- # Simple trick to snap the page into its ordered position,
119
- # without actually reordering anything in the internal structure
120
- def snap(page = @page)
64
+ # Simple trick to snap the page into its ordered position, without actually reordering anything in the internal structure.
65
+ # Tech note: use for @from but not for @to, which must be one period after @from also in :desc order!
66
+ def snap(page)
121
67
  @order == :asc ? page - 1 : @pages - page
122
68
  end
123
69
 
@@ -125,24 +71,20 @@ class Pagy # :nodoc:
125
71
  def new_time(year, month = 1, day = 1)
126
72
  Time.new(year, month, day, 0, 0, 0, @utc_offset)
127
73
  end
74
+ end
75
+ require 'pagy/calendar/year'
76
+ require 'pagy/calendar/month'
77
+ require 'pagy/calendar/week'
78
+ require 'pagy/calendar/day'
128
79
 
129
- # Months in local time
130
- def months(time)
131
- (time.year * 12) + time.month
132
- end
80
+ class Calendar # :nodoc:
81
+ UNITS = { year: Year, month: Month, week: Week, day: Day }.freeze
133
82
 
134
- # Add 1 or more months to local time
135
- def bump_month(time, months = 1)
136
- months += months(time)
137
- year = months / 12
138
- month = months % 12
139
- month.zero? ? new_time(year - 1, 12) : new_time(year, month)
140
- end
83
+ # Create a subclass instance by unit name (internal use)
84
+ def self.create(unit, vars)
85
+ raise InternalError, "unit must be in #{UNITS.keys.inspect}; got #{unit}" unless UNITS.key?(unit)
141
86
 
142
- # Return the start of the week for local time
143
- def week_start(time)
144
- start = time - (((time.wday - @week_offset) * DAY) % WEEK)
145
- new_time(start.year, start.month, start.day)
87
+ UNITS[unit].new(vars)
146
88
  end
147
89
  end
148
90
  end
@@ -11,6 +11,7 @@ class Pagy
11
11
  normalize_vars(vars)
12
12
  setup_vars(page: 1, outset: 0)
13
13
  setup_items_var
14
+ setup_params_var
14
15
  @offset = (@items * (@page - 1)) + @outset
15
16
  end
16
17
 
@@ -29,7 +30,7 @@ class Pagy
29
30
 
30
31
  # Override the original series.
31
32
  # Return nil if :countless_minimal is enabled
32
- def series(_size = @vars[:size])
33
+ def series(*)
33
34
  super unless @vars[:countless_minimal]
34
35
  end
35
36
  end
@@ -1,20 +1,20 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/shared'
4
+ require 'pagy/extras/frontend_helpers'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  # Frontend modules are specially optimized for performance.
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,17 +30,17 @@ 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}),
37
- 'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
37
+ 'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</li>),
38
38
  'active' => %(<li class="page-item active">#{mark}</li>),
39
39
  'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
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, pagy.sequels(steps))}></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
@@ -1,26 +1,26 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pagy/extras/shared'
4
+ require 'pagy/extras/frontend_helpers'
5
5
 
6
6
  class Pagy # :nodoc:
7
7
  # Frontend modules are specially optimized for performance.
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
- %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}")}</li>)
21
+ %(<li>#{link.call item, pagy.label_for(item), %(class="pagination-link" aria-label="goto page #{item}")}</li>)
22
22
  when String
23
- %(<li>#{link.call item, item,
23
+ %(<li>#{link.call item, pagy.label_for(item),
24
24
  %(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>)
25
25
  when :gap
26
26
  %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>)
@@ -30,21 +30,20 @@ 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">),
37
- 'link' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER,
37
+ 'link' => %(<li>#{link.call PAGE_PLACEHOLDER, LABEL_PLACEHOLDER,
38
38
  %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}")}</li>),
39
- 'active' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER,
39
+ 'active' => %(<li>#{link.call PAGE_PLACEHOLDER, LABEL_PLACEHOLDER,
40
40
  %(class="pagination-link is-current" aria-current="page" aria-label="page #{
41
41
  PAGE_PLACEHOLDER}")}</li>),
42
42
  'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>),
43
43
  'after' => '</ul>' }
44
44
 
45
- %(<nav#{p_id} class="pagy-njs pagy-bulma-nav-js pagination is-centered" aria-label="pagination" #{pagy_json_attr(
46
- pagy, :nav, tags, pagy.sequels(steps)
47
- )}></nav>)
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(**vars)), pagy.label_sequels(sequels))}></nav>)
48
47
  end
49
48
 
50
49
  # Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript