pagy 5.0.0 → 5.0.1
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 +4 -4
- data/lib/config/pagy.rb +1 -1
- data/lib/javascripts/pagy.js +1 -1
- data/lib/pagy/countless.rb +5 -2
- data/lib/pagy/exceptions.rb +14 -13
- data/lib/pagy/extras/bootstrap.rb +1 -0
- data/lib/pagy/extras/bulma.rb +1 -0
- data/lib/pagy/extras/foundation.rb +1 -0
- data/lib/pagy/extras/gearbox.rb +1 -1
- data/lib/pagy/extras/materialize.rb +1 -0
- data/lib/pagy/extras/metadata.rb +6 -28
- data/lib/pagy/extras/overflow.rb +2 -4
- data/lib/pagy/extras/semantic.rb +1 -0
- data/lib/pagy/extras/shared.rb +1 -2
- data/lib/pagy/extras/standalone.rb +1 -1
- data/lib/pagy/extras/uikit.rb +1 -0
- data/lib/pagy/frontend.rb +1 -0
- data/lib/pagy/i18n.rb +1 -1
- data/lib/pagy/url_helpers.rb +1 -1
- data/lib/pagy.rb +4 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1345a70a6c730b386f155905f1f64821d0843704a378906cec76a27a68f77bc
|
4
|
+
data.tar.gz: b067a51f4178b84cf164374382b41e061e4d0e257819961abb2ef8d3e516c83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa6a995fff4c56eade45efb978ad63beb36f2ee10152dbf89365cf18d66911f89a7f84f36b35ce94b4228a286f18b6343a6c30c80434bd9ad6a12c177b47b3e
|
7
|
+
data.tar.gz: 4a9288306aff02bfc789a3198f38c02ed6b7d038d2caddf1eba1d3b4102e4f1f61c111eefd60c126c6a4f5c2e3b88dd745802732324d506bed8bbd118361027f
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (5.0.
|
3
|
+
# Pagy initializer file (5.0.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
|
|
data/lib/javascripts/pagy.js
CHANGED
data/lib/pagy/countless.rb
CHANGED
@@ -16,8 +16,7 @@ class Pagy
|
|
16
16
|
|
17
17
|
# Finalize the instance variables based on the fetched items
|
18
18
|
def finalize(fetched)
|
19
|
-
raise OverflowError.new(self
|
20
|
-
if fetched.zero? && @page > 1
|
19
|
+
raise OverflowError.new(self, :page, "to be < #{@page}") if fetched.zero? && @page > 1
|
21
20
|
|
22
21
|
@pages = @last = (fetched > @items ? @page + 1 : @page)
|
23
22
|
@in = [fetched, @items].min
|
@@ -27,5 +26,9 @@ class Pagy
|
|
27
26
|
@next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
|
28
27
|
self
|
29
28
|
end
|
29
|
+
|
30
|
+
def series(_size = @vars[:size])
|
31
|
+
super unless @vars[:countless_minimal]
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
data/lib/pagy/exceptions.rb
CHANGED
@@ -3,23 +3,24 @@
|
|
3
3
|
class Pagy
|
4
4
|
# Generic variable error
|
5
5
|
class VariableError < ArgumentError
|
6
|
-
attr_reader :pagy
|
6
|
+
attr_reader :pagy, :variable, :value
|
7
7
|
|
8
|
-
def initialize(pagy)
|
9
|
-
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
message
|
15
|
-
Regexp.last_match(1)&.to_sym
|
16
|
-
end
|
17
|
-
|
18
|
-
def value
|
19
|
-
pagy.vars[variable]
|
8
|
+
def initialize(pagy, variable, description, value = nil)
|
9
|
+
@pagy = pagy
|
10
|
+
@variable = variable
|
11
|
+
@value = value
|
12
|
+
message = +"expected :#{@variable} #{description}"
|
13
|
+
message << "; got #{@value.inspect}" if value
|
14
|
+
super message
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
18
|
# Specific overflow error
|
24
19
|
class OverflowError < VariableError; end
|
20
|
+
|
21
|
+
# I18n configuration error
|
22
|
+
class I18nError < StandardError; end
|
23
|
+
|
24
|
+
# Generic internal error
|
25
|
+
class InternalError < StandardError; end
|
25
26
|
end
|
@@ -20,6 +20,7 @@ class Pagy
|
|
20
20
|
%(<li class="page-item active">#{link.call item}</li>)
|
21
21
|
when :gap
|
22
22
|
%(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>)
|
23
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
html << pagy_bootstrap_next_html(pagy, link)
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -22,6 +22,7 @@ class Pagy
|
|
22
22
|
%(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>)
|
23
23
|
when :gap
|
24
24
|
%(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>)
|
25
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
25
26
|
end
|
26
27
|
end
|
27
28
|
html << %(</ul></nav>)
|
@@ -17,6 +17,7 @@ class Pagy
|
|
17
17
|
when Integer then %(<li>#{link.call item}</li>) # page link
|
18
18
|
when String then %(<li class="current">#{item}</li>) # active page
|
19
19
|
when :gap then %(<li class="ellipsis gap" aria-hidden="true"></li>) # page gap
|
20
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
html << pagy_foundation_next_html(pagy, link)
|
data/lib/pagy/extras/gearbox.rb
CHANGED
@@ -13,7 +13,7 @@ class Pagy
|
|
13
13
|
return super if !@vars[:gearbox_extra] || @vars[:items_extra]
|
14
14
|
|
15
15
|
gearbox_items = @vars[:gearbox_items]
|
16
|
-
raise VariableError.new(self
|
16
|
+
raise VariableError.new(self, :gearbox_items, 'to be an Array of positives', gearbox_items) \
|
17
17
|
unless gearbox_items.is_a?(Array) && gearbox_items.all? { |num| num.positive? rescue false } # rubocop:disable Style/RescueModifier
|
18
18
|
|
19
19
|
@items = gearbox_items[@page - 1] || gearbox_items.last
|
@@ -17,6 +17,7 @@ class Pagy
|
|
17
17
|
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
18
18
|
when String then %(<li class="active">#{link.call item}</li>) # active page
|
19
19
|
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
|
20
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
html << pagy_materialize_next_html(pagy, link)
|
data/lib/pagy/extras/metadata.rb
CHANGED
@@ -4,44 +4,20 @@
|
|
4
4
|
require 'pagy/url_helpers'
|
5
5
|
|
6
6
|
class Pagy
|
7
|
+
DEFAULT[:metadata] = %i[ scaffold_url first_url prev_url page_url next_url last_url
|
8
|
+
count page items vars pages last in from to prev next series ]
|
9
|
+
|
7
10
|
# Add a specialized backend method for pagination metadata
|
8
11
|
module MetadataExtra
|
9
12
|
private
|
10
13
|
|
11
|
-
# Store the array of all the internal variable names usable as METADATA
|
12
|
-
METADATA = %i[ scaffold_url
|
13
|
-
first_url
|
14
|
-
prev_url
|
15
|
-
page_url
|
16
|
-
next_url
|
17
|
-
last_url
|
18
|
-
count page
|
19
|
-
items
|
20
|
-
vars
|
21
|
-
pages
|
22
|
-
last
|
23
|
-
in
|
24
|
-
from
|
25
|
-
to
|
26
|
-
prev
|
27
|
-
next
|
28
|
-
series ].tap { |m| m << :sequels if DEFAULT.key?(:steps) }.freeze
|
29
|
-
|
30
|
-
# Set the default metadata variable
|
31
|
-
Pagy::DEFAULT[:metadata] = METADATA.dup
|
32
|
-
|
33
14
|
include UrlHelpers
|
34
15
|
|
35
16
|
# Return the metadata hash
|
36
17
|
def pagy_metadata(pagy, absolute: nil)
|
37
|
-
names = pagy.vars[:metadata]
|
38
|
-
unknown = names - METADATA
|
39
|
-
raise VariableError.new(pagy), "expected :metadata to be in #{DEFAULT[:metadata].inspect}, got #{unknown.inspect} unknown" \
|
40
|
-
unless unknown.empty?
|
41
|
-
|
42
18
|
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: absolute)
|
43
19
|
{}.tap do |metadata|
|
44
|
-
|
20
|
+
pagy.vars[:metadata].each do |key|
|
45
21
|
metadata[key] = case key
|
46
22
|
when :scaffold_url then scaffold_url
|
47
23
|
when :first_url then scaffold_url.sub(PAGE_PLACEHOLDER, 1.to_s)
|
@@ -51,6 +27,8 @@ class Pagy
|
|
51
27
|
when :last_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.last.to_s)
|
52
28
|
else pagy.send(key)
|
53
29
|
end
|
30
|
+
rescue NoMethodError
|
31
|
+
raise VariableError.new(pagy, :metadata, 'to contain known keys', key)
|
54
32
|
end
|
55
33
|
end
|
56
34
|
end
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -31,8 +31,7 @@ class Pagy
|
|
31
31
|
@prev = @last # prev relative to the actual page
|
32
32
|
extend Series # special series for :empty_page
|
33
33
|
else
|
34
|
-
raise VariableError.new(self
|
35
|
-
"expected :overflow to be in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
34
|
+
raise VariableError.new(self, :overflow, 'to be in [:last_page, :empty_page, :exception]', @vars[:overflow])
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -63,8 +62,7 @@ class Pagy
|
|
63
62
|
@vars[:size] = [] # no page in the series
|
64
63
|
self
|
65
64
|
else
|
66
|
-
raise VariableError.new(self
|
67
|
-
"expected :overflow to be in [:empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
65
|
+
raise VariableError.new(self, :overflow, 'to be in [:empty_page, :exception]', @vars[:overflow])
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -17,6 +17,7 @@ class Pagy
|
|
17
17
|
when Integer then link.call item # page link
|
18
18
|
when String then %(<a class="item active">#{item}</a>) # current page
|
19
19
|
when :gap then %(<div class="disabled item">#{pagy_t 'pagy.nav.gap'}</div>) # page gap
|
20
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
html << pagy_semantic_next_html(pagy, link)
|
data/lib/pagy/extras/shared.rb
CHANGED
@@ -19,8 +19,7 @@ class Pagy
|
|
19
19
|
# Notice: if :steps is false it will use the single {0 => @vars[:size]} size
|
20
20
|
def sequels(steps = nil)
|
21
21
|
steps ||= @vars[:steps] || { 0 => @vars[:size] }
|
22
|
-
raise VariableError.new(self
|
23
|
-
unless steps.key?(0)
|
22
|
+
raise VariableError.new(self, :steps, 'to define the 0 width', steps) unless steps.key?(0)
|
24
23
|
|
25
24
|
{}.tap do |sequels|
|
26
25
|
steps.each { |width, size| sequels[width.to_s] = series(size) }
|
@@ -40,7 +40,7 @@ class Pagy
|
|
40
40
|
params[p_vars[:page_param].to_s] = page
|
41
41
|
params[p_vars[:items_param].to_s] = p_vars[:items] if defined?(ItemsExtra)
|
42
42
|
# no Rack required in standalone mode
|
43
|
-
query_string = "?#{QueryUtils.build_nested_query(pagy_massage_params(params))}"
|
43
|
+
query_string = "?#{QueryUtils.build_nested_query(pagy_massage_params(params))}"
|
44
44
|
"#{url}#{query_string}#{p_vars[:fragment]}"
|
45
45
|
end
|
46
46
|
end
|
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -16,6 +16,7 @@ class Pagy
|
|
16
16
|
when Integer then %(<li>#{link.call item}</li>)
|
17
17
|
when String then %(<li class="uk-active"><span>#{item}</span></li>)
|
18
18
|
when :gap then %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>)
|
19
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
19
20
|
end
|
20
21
|
end
|
21
22
|
html << pagy_uikit_next_html(pagy, link)
|
data/lib/pagy/frontend.rb
CHANGED
@@ -31,6 +31,7 @@ class Pagy
|
|
31
31
|
when Integer then %(<span class="page">#{link.call item}</span> ) # page link
|
32
32
|
when String then %(<span class="page active">#{item}</span> ) # current page
|
33
33
|
when :gap then %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
34
|
+
else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
34
35
|
end
|
35
36
|
end
|
36
37
|
html << if p_next
|
data/lib/pagy/i18n.rb
CHANGED
@@ -130,7 +130,7 @@ class Pagy
|
|
130
130
|
locale[:filepath] ||= Pagy.root.join('locales', "#{locale[:locale]}.yml")
|
131
131
|
locale[:pluralize] ||= P11n::LOCALE[locale[:locale]]
|
132
132
|
dictionary = YAML.safe_load(File.read(locale[:filepath], encoding: 'UTF-8'))
|
133
|
-
raise
|
133
|
+
raise I18nError, %(expected :locale "#{locale[:locale]}" not found in :filepath "#{locale[:filepath].inspect}") \
|
134
134
|
unless dictionary.key?(locale[:locale])
|
135
135
|
|
136
136
|
DATA[locale[:locale]] = [flatten(dictionary[locale[:locale]]), locale[:pluralize]]
|
data/lib/pagy/url_helpers.rb
CHANGED
@@ -10,7 +10,7 @@ class Pagy
|
|
10
10
|
params[p_vars[:page_param].to_s] = page
|
11
11
|
params[p_vars[:items_param].to_s] = p_vars[:items] if defined?(ItemsExtra)
|
12
12
|
# we rely on Rack by default: use the standalone extra in non rack environments
|
13
|
-
query_string = "?#{Rack::Utils.build_nested_query(pagy_massage_params(params))}"
|
13
|
+
query_string = "?#{Rack::Utils.build_nested_query(pagy_massage_params(params))}"
|
14
14
|
"#{request.base_url if absolute}#{request.path}#{query_string}#{p_vars[:fragment]}"
|
15
15
|
end
|
16
16
|
|
data/lib/pagy.rb
CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# Core class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '5.0.
|
8
|
+
VERSION = '5.0.1'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
@@ -32,8 +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
|
-
raise OverflowError.new(self
|
36
|
-
if @page > @last
|
35
|
+
raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
|
37
36
|
|
38
37
|
@offset = (@items * (@page - 1)) + @outset
|
39
38
|
@from = [@offset - @outset + 1, @count].min
|
@@ -46,7 +45,7 @@ class Pagy
|
|
46
45
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
47
46
|
def series(size = @vars[:size])
|
48
47
|
return [] if size.empty?
|
49
|
-
raise VariableError.new(self
|
48
|
+
raise VariableError.new(self, :size, 'to contain 4 items >= 0', size) \
|
50
49
|
unless size.size == 4 && size.all? { |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
|
51
50
|
|
52
51
|
# This algorithm is up to ~5x faster and ~2.3x lighter than the previous one (pagy < 4.3)
|
@@ -81,7 +80,7 @@ class Pagy
|
|
81
80
|
# Setup and validates the passed vars: var must be present and value.to_i must be >= to min
|
82
81
|
def setup_vars(name_min)
|
83
82
|
name_min.each do |name, min|
|
84
|
-
raise VariableError.new(self
|
83
|
+
raise VariableError.new(self, name, ">= #{min}", @vars[name]) \
|
85
84
|
unless @vars[name] && instance_variable_set(:"@#{name}", @vars[name].to_i) >= min
|
86
85
|
end
|
87
86
|
end
|
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.0.
|
4
|
+
version: 5.0.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-10-
|
11
|
+
date: 2021-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|