pagy 0.8.5 → 0.8.6
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/bootstrap.rb +5 -5
- data/lib/pagy/extras/compact.rb +16 -16
- data/lib/pagy/extras/responsive.rb +10 -10
- data/lib/pagy/frontend.rb +11 -11
- data/lib/pagy.rb +2 -2
- 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: 8e60b4173be015ffca66290f5a3cf17ac3a310300384661aa5e2fa247ce58f68
|
4
|
+
data.tar.gz: 358cdc2134cc73f7f289de33cb02c821158797ee8dd21e88e05cf690085e0143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7b4d97d281802fe983e2a748524cad6971bf9df58baa0cf34f1e35a0647ace2644b50b56e76727b2fe231043ed8a34cbc84bf206350596e81fe95c15b3a6e2f
|
7
|
+
data.tar.gz: '083afad91cdb22b2a6e036c25c5fca9cfe147747c3a348b86a9d471c165417f06a3622b88e3b25160fe893b25e533ac2c468434744d1e0f0f677ee274df87ff7'
|
@@ -6,18 +6,18 @@ class Pagy
|
|
6
6
|
|
7
7
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
8
8
|
def pagy_nav_bootstrap(pagy)
|
9
|
-
tags = ''
|
9
|
+
tags, link, p_prev, p_next = '', pagy_link_proc(pagy, 'class="page-link"'.freeze), pagy.prev, pagy.next
|
10
10
|
|
11
|
-
tags << (
|
12
|
-
|
11
|
+
tags << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</li>)
|
12
|
+
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev'.freeze)}</a></li>))
|
13
13
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
14
14
|
tags << if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
|
15
15
|
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
|
16
16
|
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap'.freeze)}</a></li>) # page gap
|
17
17
|
end
|
18
18
|
end
|
19
|
-
tags << (
|
20
|
-
|
19
|
+
tags << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</li>)
|
20
|
+
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next'.freeze)}</a></li>))
|
21
21
|
%(<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{tags}</ul></nav>)
|
22
22
|
end
|
23
23
|
|
data/lib/pagy/extras/compact.rb
CHANGED
@@ -7,43 +7,43 @@ class Pagy
|
|
7
7
|
# Generic compact pagination: it returns the html with the series of links to the pages
|
8
8
|
# we use a numeric input tag to set the page and the PagyCompact javascript to navigate
|
9
9
|
def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
|
10
|
-
tags = ''
|
10
|
+
tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
11
11
|
|
12
12
|
tags << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
|
13
13
|
|
14
14
|
tags << link.call(MARKER, '', %(style="display: none;" ))
|
15
|
-
tags << (
|
16
|
-
|
15
|
+
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</span> )
|
16
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'.freeze)}</span> ))
|
17
17
|
|
18
|
-
input = %(<input type="number" min="1" max="#{
|
19
|
-
tags << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{
|
18
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
19
|
+
tags << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{p_pages}</span> )
|
20
20
|
|
21
|
-
tags << (
|
22
|
-
|
21
|
+
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</span>)
|
22
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next'.freeze)}</span>))
|
23
23
|
|
24
|
-
tags << %(</nav><script>PagyCompact('#{id}', '#{MARKER}', '#{
|
24
|
+
tags << %(</nav><script>PagyCompact('#{id}', '#{MARKER}', '#{p_page}');</script>)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
|
28
28
|
# we use a numeric input tag to set the page and the PagyCompact javascript to navigate
|
29
29
|
def pagy_nav_bootstrap_compact(pagy, id=caller(1,1)[0].hash)
|
30
|
-
tags = ''
|
30
|
+
tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
31
31
|
|
32
32
|
tags << %(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">)
|
33
33
|
|
34
34
|
tags << link.call(MARKER, '', %(style="display: none;" ))
|
35
35
|
|
36
36
|
tags << %(<div class="btn-group" role="group">)
|
37
|
-
tags << (
|
38
|
-
|
37
|
+
tags << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous" class="prev btn btn-primary"'.freeze)
|
38
|
+
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev'.freeze)}</a>))
|
39
39
|
|
40
|
-
input = %(<input type="number" min="1" max="#{
|
41
|
-
tags << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{
|
40
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
41
|
+
tags << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{p_pages}</div>)
|
42
42
|
|
43
|
-
tags << (
|
44
|
-
|
43
|
+
tags << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next" class="next btn btn-primary"'.freeze)
|
44
|
+
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next'.freeze)}</a>))
|
45
45
|
|
46
|
-
tags << %(</div></nav><script>PagyCompact('#{id}', '#{MARKER}', '#{
|
46
|
+
tags << %(</div></nav><script>PagyCompact('#{id}', '#{MARKER}', '#{p_page}');</script>)
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -33,18 +33,18 @@ class Pagy
|
|
33
33
|
# Generic responsive pagination: it returns the html with the series of links to the pages
|
34
34
|
# we build the tags as a json object string and render them with the PagyResponsive javascript
|
35
35
|
def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
|
36
|
-
tags = '{'
|
36
|
+
tags, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
37
37
|
|
38
|
-
tags << (
|
39
|
-
|
38
|
+
tags << (p_prev ? %('prev':'<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</span> ',)
|
39
|
+
: %('prev':'<span class="page prev disabled">#{pagy_t('pagy.nav.prev'.freeze)}</span> ',))
|
40
40
|
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
41
41
|
tags << if item.is_a?(Integer); %('#{item}':'<span class="page">#{link.call item}</span> ',) # page link
|
42
42
|
elsif item.is_a?(String) ; %('#{item}':'<span class="page active">#{item}</span> ',) # current page
|
43
43
|
elsif item == :gap ; %('#{item}':'<span class="page gap">#{pagy_t('pagy.nav.gap'.freeze)}</span> ',) # page gap
|
44
44
|
end
|
45
45
|
end
|
46
|
-
tags << (
|
47
|
-
|
46
|
+
tags << (p_next ? %('next':'<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</span>'})
|
47
|
+
: %('next':'<span class="page next disabled">#{pagy_t('pagy.nav.next'.freeze)}</span>'}))
|
48
48
|
script = %(<script>PagyResponsive('#{id}', #{tags}, #{responsive[:widths].to_json}, #{responsive[:series].to_json});</script>)
|
49
49
|
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
|
50
50
|
end
|
@@ -53,18 +53,18 @@ class Pagy
|
|
53
53
|
# Responsive pagination for bootstrap: it returns the html with the series of links to the pages
|
54
54
|
# we build the tags as a json object string and render them with the PagyResponsive javascript
|
55
55
|
def pagy_nav_bootstrap_responsive(pagy, id=caller(1,1)[0].hash)
|
56
|
-
tags = '{'
|
56
|
+
tags, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy, 'class="page-link"'.freeze), pagy.prev, pagy.next, pagy.responsive
|
57
57
|
|
58
|
-
tags << (
|
59
|
-
|
58
|
+
tags << (p_prev ? %('prev':'<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</li>',)
|
59
|
+
: %('prev':'<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev'.freeze)}</a></li>',))
|
60
60
|
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
61
61
|
tags << if item.is_a?(Integer); %('#{item}':'<li class="page-item">#{link.call item}</li>',) # page link
|
62
62
|
elsif item.is_a?(String) ; %('#{item}':'<li class="page-item active">#{link.call item}</li>',) # active page
|
63
63
|
elsif item == :gap ; %('#{item}':'<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap'.freeze)}</a></li>',) # page gap
|
64
64
|
end
|
65
65
|
end
|
66
|
-
tags << (
|
67
|
-
|
66
|
+
tags << (p_next ? %('next':'<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</li>'})
|
67
|
+
: %('next':'<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next'.freeze)}</a></li>'}))
|
68
68
|
script = %(<script>PagyResponsive('#{id}', #{tags}, #{responsive[:widths].to_json}, #{responsive[:series].to_json});</script>)
|
69
69
|
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-responsive pagination" role="navigation" aria-label="pager"><ul class="pagination"></ul></nav>#{script})
|
70
70
|
end
|
data/lib/pagy/frontend.rb
CHANGED
@@ -10,18 +10,18 @@ class Pagy
|
|
10
10
|
|
11
11
|
# Generic pagination: it returns the html with the series of links to the pages
|
12
12
|
def pagy_nav(pagy)
|
13
|
-
tags = ''
|
13
|
+
tags, link, p_prev, p_next = '', pagy_link_proc(pagy), pagy.prev, pagy.next
|
14
14
|
|
15
|
-
tags << (
|
16
|
-
|
15
|
+
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze}</span> )
|
16
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'.freeze)}</span> ))
|
17
17
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
tags << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
19
19
|
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
20
20
|
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap'.freeze)}</span> ) # page gap
|
21
21
|
end
|
22
22
|
end
|
23
|
-
tags << (
|
24
|
-
|
23
|
+
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze}</span>)
|
24
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next'.freeze)}</span>))
|
25
25
|
%(<nav class="pagy-nav pagination" role="navigation" aria-label="pager">#{tags}</nav>)
|
26
26
|
end
|
27
27
|
|
@@ -36,8 +36,8 @@ class Pagy
|
|
36
36
|
|
37
37
|
# this works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
38
38
|
def pagy_url_for(page, pagy)
|
39
|
-
params = request.GET.merge(
|
40
|
-
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{
|
39
|
+
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, **p_vars[:params])
|
40
|
+
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
41
41
|
end
|
42
42
|
|
43
43
|
|
@@ -57,15 +57,15 @@ class Pagy
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# Pagy::Frontend::I18N constant
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
I18N_DATA = YAML.load_file(Pagy.root.join('locales', 'pagy.yml')).first[1]
|
61
|
+
zero_one = ['zero'.freeze, 'one'.freeze]; I18N = { plurals: -> (c) {zero_one[c] || 'other'.freeze}}
|
62
|
+
def I18N.load_file(file) I18N_DATA.replace(YAML.load_file(file).first[1]) end
|
63
63
|
|
64
64
|
# Similar to I18n.t for interpolation and pluralization but without translation
|
65
65
|
# Use only for single-language apps: it is specialized for pagy and 5x faster than I18n.t
|
66
66
|
# See also https://ddnexus.github.io/pagy/extras/i18n to use the standard I18n gem instead
|
67
67
|
def pagy_t(path, vars={})
|
68
|
-
value =
|
68
|
+
value = I18N_DATA.dig(*path.to_s.split('.'.freeze)) or return %(translation missing: "#{path}")
|
69
69
|
if value.is_a?(Hash)
|
70
70
|
vars.key?(:count) or return value
|
71
71
|
plural = I18N[:plurals].call(vars[:count])
|
data/lib/pagy.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
-
class Pagy ; VERSION = '0.8.
|
5
|
+
class Pagy ; VERSION = '0.8.6'
|
6
6
|
|
7
7
|
class OutOfRangeError < StandardError; end
|
8
8
|
|
@@ -16,7 +16,7 @@ class Pagy ; VERSION = '0.8.5'
|
|
16
16
|
|
17
17
|
# merge and validate the options, do some simple aritmetic and set the instance variables
|
18
18
|
def initialize(vars)
|
19
|
-
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' })
|
19
|
+
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == ''.freeze }) # default vars + cleaned instance vars
|
20
20
|
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate core variables
|
21
21
|
(@vars[k] && instance_variable_set(:"@#{k}", @vars.delete(k).to_i) >= min) \
|
22
22
|
or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}")
|
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.8.
|
4
|
+
version: 0.8.6
|
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-06-
|
11
|
+
date: 2018-06-05 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,
|