pagy 0.12.0 → 0.13.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 +4 -4
- data/lib/pagy.rb +3 -3
- data/lib/pagy/extras/initializer_example.rb +8 -0
- data/lib/pagy/extras/out_of_range.rb +29 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce35faa857fbc47879ebacc7f92ca168b402944ce4403c2c18e2b2eecd0a9c57
|
4
|
+
data.tar.gz: 24f36562a617e7870dc5cd4217979a06faf424f6cf6731d43a2fd6dd7f5e0084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fb53ff09042a732205b3b5f262a6157a014b1ac04a69b7e8a6e5d92402468b7e5a8168a2f46f427d6ec696a283c81ad38e0a463c0124ebb4f62fe17237ce95e
|
7
|
+
data.tar.gz: 2490a4827a62166fbf0a710162bfd8be39aa51b62035053fb08701dd4b01dc0b55200122728588e91bc56e6eaa897290a31fa0b196040720bf0e293476ee959a
|
data/lib/pagy.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
class Pagy ; VERSION = '0.
|
6
|
+
class Pagy ; VERSION = '0.13.0'
|
7
7
|
|
8
8
|
class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
|
9
9
|
|
@@ -22,8 +22,8 @@ class Pagy ; VERSION = '0.12.0'
|
|
22
22
|
(@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
|
23
23
|
or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}")
|
24
24
|
end
|
25
|
-
@pages
|
26
|
-
@page
|
25
|
+
@pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings
|
26
|
+
@page <= @last or raise(OutOfRangeError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}")
|
27
27
|
@offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
|
28
28
|
@items = @count - ((@pages-1) * @items) if @page == @last # adjust items for last page
|
29
29
|
@from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
|
@@ -13,6 +13,10 @@
|
|
13
13
|
# See https://ddnexus.github.io/pagy/extras/bootstrap
|
14
14
|
# require 'pagy/extras/bootstrap'
|
15
15
|
|
16
|
+
# Bulma: Nav helper and templates for Bulma pagination
|
17
|
+
# See https://ddnexus.github.io/pagy/extras/bulma
|
18
|
+
# require 'pagy/extras/bulma'
|
19
|
+
|
16
20
|
# Compact: An alternative UI that combines the pagination with the nav info in one compact element
|
17
21
|
# See https://ddnexus.github.io/pagy/extras/compact
|
18
22
|
# require 'pagy/extras/compact'
|
@@ -23,6 +27,10 @@
|
|
23
27
|
# Pagy::VARS[:items_param] = :items # default
|
24
28
|
# Pagy::VARS[:max_items] = 100 # default
|
25
29
|
|
30
|
+
# Out Of Range: Allow for easy handling of out of range pages
|
31
|
+
# See https://ddnexus.github.io/pagy/extras/out_of_range
|
32
|
+
# Pagy::VARS[:out_of_range_mode] = :last_page # default (other options :empty_page and :exception )
|
33
|
+
|
26
34
|
# Responsive: On resize, the number of page links will adapt in real-time to the available window or container width
|
27
35
|
# See https://ddnexus.github.io/pagy/extras/responsive
|
28
36
|
# require 'pagy/extras/responsive'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Pagy
|
2
|
+
|
3
|
+
VARS[:out_of_range_mode] = :last_page
|
4
|
+
|
5
|
+
def out_of_range?; @out_of_range end
|
6
|
+
|
7
|
+
alias :create :initialize
|
8
|
+
|
9
|
+
def initialize(vars)
|
10
|
+
create(vars)
|
11
|
+
rescue OutOfRangeError => e
|
12
|
+
raise e if @vars[:out_of_range_mode] == :exception
|
13
|
+
@out_of_range = true
|
14
|
+
if @vars[:out_of_range_mode] == :last_page
|
15
|
+
@page = @last # set as last page
|
16
|
+
elsif @vars[:out_of_range_mode] == :empty_page
|
17
|
+
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
18
|
+
@prev = @last # the prev is the last page
|
19
|
+
define_singleton_method(:series) do |size=@vars[:size]|
|
20
|
+
@page = @last # series for last page
|
21
|
+
super(size).tap do |s| # call original series
|
22
|
+
s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
|
23
|
+
@page = @vars[:page] # restore the actual page
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
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: 0.
|
4
|
+
version: 0.13.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: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
|
14
14
|
and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/pagy/extras/initializer_example.rb
|
34
34
|
- lib/pagy/extras/items.rb
|
35
35
|
- lib/pagy/extras/javascripts/pagy.js
|
36
|
+
- lib/pagy/extras/out_of_range.rb
|
36
37
|
- lib/pagy/extras/responsive.rb
|
37
38
|
- lib/pagy/extras/templates/nav.html.erb
|
38
39
|
- lib/pagy/extras/templates/nav.html.haml
|