pagy 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pagy.rb +7 -7
- data/lib/pagy/backend.rb +6 -0
- 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: 4eb355e2e788692b281d40f9ef2d101eef85485ca76793194d53cd5f5a5b2d18
|
4
|
+
data.tar.gz: 6b3090fa7074a6b3ad109c6cf2d1bf7e92ab168818dc68aeb2dd08a5dbaf8f2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c114e92d07dac9f3a47efc6c754d8b3ca8f7dfde8e46f7c04bbb35dd76e99879e52cf565d889645b841d363380db3c7c2bd15a571aaabc65675af1bb0ab738a6
|
7
|
+
data.tar.gz: 8ab8eac80d11c27af0b69d7fa32be4d3e8968981b993b19c3cfd2048ca9ce2632c640c366f25a8f40d377311ab07cee1293b6fcf1d0436a1ff0e3aa764f35521
|
data/lib/pagy.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
-
class Pagy ; VERSION = '0.7.
|
5
|
+
class Pagy ; VERSION = '0.7.1'
|
6
6
|
|
7
7
|
autoload :Backend, 'pagy/backend'
|
8
8
|
autoload :Frontend, 'pagy/frontend'
|
@@ -22,15 +22,15 @@ class Pagy ; VERSION = '0.7.0'
|
|
22
22
|
|
23
23
|
# merge and validate the options, do some simple aritmetic and set the instance variables
|
24
24
|
def initialize(vars)
|
25
|
-
@vars = VARS.merge(vars.delete_if{|k,v| v.nil?
|
25
|
+
@vars = VARS.merge(vars.delete_if{|k,v| v.nil? || v == '' }) # default vars + cleaned instance vars
|
26
26
|
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate core variables
|
27
|
-
(@vars[k] && @vars
|
28
|
-
|
27
|
+
(@vars[k] && instance_variable_set(:"@#{k}", @vars.delete(k).to_i) >= min) \
|
28
|
+
or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}")
|
29
29
|
end
|
30
30
|
@pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings
|
31
|
-
|
31
|
+
@page >= 1 && @page <= @last or raise(OutOfRangeError, "expected :page in 1..#{@last}; got #{@page.inspect}")
|
32
32
|
@offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
|
33
|
-
@items = @count
|
33
|
+
@items = @count - ((@pages-1) * @items) if @page == @last # adjust items for last page
|
34
34
|
@from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
|
35
35
|
@to = @offset + @items - @outset # page ends to item
|
36
36
|
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
@@ -39,7 +39,7 @@ class Pagy ; VERSION = '0.7.0'
|
|
39
39
|
|
40
40
|
# return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
41
41
|
def series(size=@vars[:size])
|
42
|
-
|
42
|
+
4.times{|i| (size[i]>=0 rescue nil) or raise(ArgumentError, "expected 4 items >= 0 in :size; got #{size.inspect}")}
|
43
43
|
series = []
|
44
44
|
[*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
|
45
45
|
if a<0 || a==b || a>@last # skip out of range and duplicates
|
data/lib/pagy/backend.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# See Pagy::Backend API documentation: https://ddnexus.github.io/pagy/api/backend
|
2
2
|
|
3
3
|
class Pagy
|
4
|
+
# Defines a few generic methods to paginate a ORM collection out of the box,
|
5
|
+
# or any collection by overriding pagy_get_items in your controller
|
6
|
+
|
7
|
+
# See also the pagy-extras gem if you need specialized methods to paginate
|
8
|
+
# Arrays, ORM, and other TBD collections
|
9
|
+
|
4
10
|
module Backend ; private # the whole module is private so no problem with including it in a controller
|
5
11
|
|
6
12
|
# return pagy object and items
|
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.7.
|
4
|
+
version: 0.7.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: 2018-05-
|
11
|
+
date: 2018-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|