pagy 0.15.0 → 0.15.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/extras/trim.rb +1 -1
- data/lib/pagy/frontend.rb +1 -1
- data/lib/pagy.rb +10 -10
- 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: 4854a1fd5d27c6aff098679de26bf6d8d9798ae80ac8437018ffea9453bd8278
|
4
|
+
data.tar.gz: 7e3d14f097eb00734df266131a8284d71bc1112898fed0fccac4b52abfca1809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 860cb78c32a7e439496940ae2a5083b47bbae26b5bd5c5c9590b5e2f6d251feb1ec8bd9dbdcbcab0ffcc972c0a0832522f68ed410e9900ce5f5ee3c7cdbf0a62
|
7
|
+
data.tar.gz: 2a0003898d272902131032fef6edad510596f70ca1a52c937a79cb3a384bc5c1a5147604eec93dd0b895a5c16669872423b1093bd777cd4c80ad692d1d060aa8
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -19,7 +19,7 @@ class Pagy
|
|
19
19
|
p1url = pagy_trim_url(url, "#{p_vars[:page_param]}=#{MARKER}")
|
20
20
|
p1 = %(<a href="#{p1url}" #{p_vars[:link_extra]} #{link_extra})
|
21
21
|
a, b = %(<a href="#{url}" #{p_vars[:link_extra]} #{link_extra}).split(MARKER, 2)
|
22
|
-
-> (n, text=n, extra='') { start = n == 1 ? p1 : "#{a}#{n}#{b}"
|
22
|
+
-> (n, text=n, extra='') { start = n.to_i == 1 ? p1 : "#{a}#{n}#{b}"
|
23
23
|
"#{start}#{ if n == p_prev ; ' rel="prev"'
|
24
24
|
elsif n == p_next ; ' rel="next"'
|
25
25
|
else '' end } #{extra}>#{text}</a>" }
|
data/lib/pagy/frontend.rb
CHANGED
@@ -35,7 +35,7 @@ class Pagy
|
|
35
35
|
|
36
36
|
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
37
37
|
def pagy_url_for(page, pagy)
|
38
|
-
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page).merge!(p_vars[:params])
|
38
|
+
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param].to_s => page).merge!(p_vars[:params])
|
39
39
|
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
40
40
|
end
|
41
41
|
|
data/lib/pagy.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
class Pagy ; VERSION = '0.15.
|
6
|
+
class Pagy ; VERSION = '0.15.1'
|
7
7
|
|
8
8
|
class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
|
9
9
|
|
@@ -17,19 +17,19 @@ class Pagy ; VERSION = '0.15.0'
|
|
17
17
|
|
18
18
|
# Merge and validate the options, do some simple aritmetic and set the instance variables
|
19
19
|
def initialize(vars)
|
20
|
-
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' })
|
21
|
-
{ count:0, items:1, outset:0, page:1 }.each do |k,min|
|
20
|
+
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars
|
21
|
+
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
|
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 = @last = [(@count.to_f / @items).ceil, 1].max
|
25
|
+
@pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings
|
26
26
|
@page <= @last or raise(OutOfRangeError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}")
|
27
|
-
@offset = @items * (@page - 1) + @outset
|
28
|
-
@items = @count - ((@pages-1) * @items) if @page == @last
|
29
|
-
@from = @count == 0 ? 0 : @offset+1 - @outset
|
30
|
-
@to = @offset + @items - @outset
|
31
|
-
@prev = (@page-1 unless @page == 1)
|
32
|
-
@next = (@page+1 unless @page == @last)
|
27
|
+
@offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
|
28
|
+
@items = @count - ((@pages-1) * @items) if @page == @last && @count > 0 # adjust items for last non-empty page
|
29
|
+
@from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
|
30
|
+
@to = @count == 0 ? 0 : @offset + @items - @outset # page ends to item
|
31
|
+
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
32
|
+
@next = (@page+1 unless @page == @last) # nil if no next page
|
33
33
|
end
|
34
34
|
|
35
35
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
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.15.
|
4
|
+
version: 0.15.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-
|
11
|
+
date: 2018-08-04 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,
|