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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 681052934a39cf55ae637f4760440afea264bdef4edb5b6d3f42cfc1a22f78d5
4
- data.tar.gz: '0728e6ad1211af132b074c0a41419136b4554406a78d002c07af29db9b6e97eb'
3
+ metadata.gz: 4854a1fd5d27c6aff098679de26bf6d8d9798ae80ac8437018ffea9453bd8278
4
+ data.tar.gz: 7e3d14f097eb00734df266131a8284d71bc1112898fed0fccac4b52abfca1809
5
5
  SHA512:
6
- metadata.gz: 2577f76f006a80e85001f0d16eb85f87b4f47d1439040754355131e5032e75e997273d9174c18fd2979b21e57fe709dcee5acdbc7c6c8264b0d5a438bbede6e2
7
- data.tar.gz: 0a0d7c7a41ea3020c60b1e3461ff5a3a68e6ddbc592f74492e17a3741905e5dd0219734ad0361058dba0a7b15432462cc41fa5fcb391742ee1917ee442e3d97e
6
+ metadata.gz: 860cb78c32a7e439496940ae2a5083b47bbae26b5bd5c5c9590b5e2f6d251feb1ec8bd9dbdcbcab0ffcc972c0a0832522f68ed410e9900ce5f5ee3c7cdbf0a62
7
+ data.tar.gz: 2a0003898d272902131032fef6edad510596f70ca1a52c937a79cb3a384bc5c1a5147604eec93dd0b895a5c16669872423b1093bd777cd4c80ad692d1d060aa8
@@ -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.0'
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 == '' }) # default vars + cleaned vars
21
- { count:0, items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
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 # cardinal and ordinal meanings
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 # pagination offset + outset (initial offset)
28
- @items = @count - ((@pages-1) * @items) if @page == @last # adjust items for last page
29
- @from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
30
- @to = @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
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.0
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-07-29 00:00:00.000000000 Z
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,