pagy 5.2.3 → 5.5.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.
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # Core class
7
7
  class Pagy
8
- VERSION = '5.2.3'
8
+ VERSION = '5.5.0'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -24,7 +24,7 @@ class Pagy
24
24
  i18n_key: 'pagy.item_name',
25
25
  cycle: false }
26
26
 
27
- attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :in, :from, :to, :prev, :next
27
+ attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :in, :from, :to, :prev, :next, :params
28
28
 
29
29
  # Merge and validate the options, do some simple arithmetic and set the instance variables
30
30
  def initialize(vars)
@@ -32,6 +32,7 @@ class Pagy
32
32
  setup_vars(count: 0, page: 1, outset: 0)
33
33
  setup_items_var
34
34
  setup_pages_var
35
+ setup_params_var
35
36
  raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
36
37
 
37
38
  @offset = (@items * (@page - 1)) + @outset
@@ -43,7 +44,7 @@ class Pagy
43
44
  end
44
45
 
45
46
  # Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
46
- def series(size = @vars[:size])
47
+ def series(size: @vars[:size])
47
48
  return [] if size.empty?
48
49
  raise VariableError.new(self, :size, 'to contain 4 items >= 0', size) \
49
50
  unless size.is_a?(Array) && size.size == 4 && size.all? { |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
@@ -70,6 +71,15 @@ class Pagy
70
71
  series
71
72
  end
72
73
 
74
+ # Allow the customization of the output (overridden by the calendar extra)
75
+ def label_for(page)
76
+ page.to_s
77
+ end
78
+
79
+ def label
80
+ @page.to_s
81
+ end
82
+
73
83
  protected
74
84
 
75
85
  # Apply defaults, cleanup blanks and set @vars
@@ -94,6 +104,12 @@ class Pagy
94
104
  def setup_pages_var
95
105
  @pages = @last = [(@count.to_f / @items).ceil, 1].max
96
106
  end
107
+
108
+ # Setup and validates the params
109
+ def setup_params_var
110
+ raise VariableError.new(self, :params, 'must be a Hash or a Proc', @params) \
111
+ unless (@params = @vars[:params]).is_a?(Hash) || @params.is_a?(Proc)
112
+ end
97
113
  end
98
114
 
99
115
  require 'pagy/backend'
@@ -13,7 +13,7 @@
13
13
  <% end -%>
14
14
  <% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%>
15
15
  <% if item.is_a?(Integer) -%> <li><%== link.call(item) %></li>
16
- <% elsif item.is_a?(String) -%> <li class="current"><%= pagy_labeler(pagy, item) %></li>
16
+ <% elsif item.is_a?(String) -%> <li class="current"><%= pagy.label_for(item) %></li>
17
17
  <% elsif item == :gap -%> <li class="ellipsis gap" aria-hidden="true"></li>
18
18
  <% end -%>
19
19
  <% end -%>
@@ -22,7 +22,7 @@
22
22
 
23
23
  - elsif item.is_a?(String) # current page
24
24
  %li.current
25
- = pagy_labeler(pagy, item)
25
+ = pagy.label_for(item)
26
26
 
27
27
  - elsif item == :gap # page gap
28
28
  %li.ellipsis.gap{"aria-hidden" => true}
@@ -22,7 +22,7 @@ nav.pagy-foundation-nav role="navigation" aria-label="Pagination"
22
22
 
23
23
  - elsif item.is_a?(String) # current page
24
24
  li.current
25
- = pagy_labeler(pagy, item)
25
+ = pagy.label_for(item)
26
26
 
27
27
  - elsif item == :gap # page gap
28
28
  li.ellipsis.gap aria-hidden="true"
@@ -5,7 +5,7 @@
5
5
  <% end -%>
6
6
  <% pagy.series.each do |item| -%>
7
7
  <% if item.is_a?(Integer) -%> <li><%== link.call(item) %></li>
8
- <% elsif item.is_a?(String) -%> <li class="uk-active"><span><%== pagy_labeler(pagy, item) %></span></li>
8
+ <% elsif item.is_a?(String) -%> <li class="uk-active"><span><%== pagy.label_for(item) %></span></li>
9
9
  <% elsif item == :gap -%> <li class="uk-disabled"><span><%== pagy_t('pagy.nav.gap') %></span></li>
10
10
  <% end -%>
11
11
  <% end -%>
@@ -14,7 +14,7 @@
14
14
 
15
15
  - elsif item.is_a?(String)
16
16
  %li.uk-active
17
- %span!= pagy_labeler(pagy, item)
17
+ %span!= pagy.label_for(item)
18
18
 
19
19
  - elsif item == :gap
20
20
  %li.uk-disabled
@@ -14,7 +14,7 @@ ul.uk-pagination.uk-flex-center
14
14
 
15
15
  - elsif item.is_a?(String)
16
16
  li.uk-active
17
- span== pagy_labeler(pagy, item)
17
+ span== pagy.label_for(item)
18
18
 
19
19
  - elsif item == :gap
20
20
  li.uk-disabled
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.3
4
+ version: 5.5.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-10 00:00:00.000000000 Z
11
+ date: 2021-11-22 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
@@ -65,6 +69,7 @@ files:
65
69
  - lib/pagy/extras/countless.rb
66
70
  - lib/pagy/extras/elasticsearch_rails.rb
67
71
  - lib/pagy/extras/foundation.rb
72
+ - lib/pagy/extras/frontend_helpers.rb
68
73
  - lib/pagy/extras/gearbox.rb
69
74
  - lib/pagy/extras/headers.rb
70
75
  - lib/pagy/extras/i18n.rb
@@ -76,7 +81,6 @@ files:
76
81
  - lib/pagy/extras/overflow.rb
77
82
  - lib/pagy/extras/searchkick.rb
78
83
  - lib/pagy/extras/semantic.rb
79
- - lib/pagy/extras/shared.rb
80
84
  - lib/pagy/extras/standalone.rb
81
85
  - lib/pagy/extras/support.rb
82
86
  - lib/pagy/extras/trim.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: