pagy 0.9.1 → 0.9.2
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 +7 -6
- data/lib/pagy/extras/compact.rb +13 -12
- data/lib/pagy/extras/items.rb +3 -2
- data/lib/pagy/extras/responsive.rb +13 -13
- data/lib/pagy/frontend.rb +17 -20
- data/lib/pagy.rb +4 -3
- 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: d25549587b5ffb4311920d5a1f52f1e181e2c0b062c27936fe85cf453c4d3361
|
4
|
+
data.tar.gz: 912cc77296b4e6ba9db0feef70c92580ceaaa8bc2b4794d7a5d3e2bd7700c0d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c76ee653cc0693cb646b9ed4bbc552e2c91541c3860120322b1105e7197b311b2d3c052f760bda7af2483c5f7f964aeca0b0b84512969b3fb6dab94b54ecdd24
|
7
|
+
data.tar.gz: 0126c853a4edd59214f791c1ada7c26661b90bc098fd6c252f89b70354b8db59a09162494ccb9df6243dceb88e721d5c4ab02a3110607ee613e1a27dfe619fe4
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
class Pagy
|
4
5
|
# Add nav helper for bootstrap pagination
|
@@ -6,18 +7,18 @@ class Pagy
|
|
6
7
|
|
7
8
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
8
9
|
def pagy_nav_bootstrap(pagy)
|
9
|
-
tags, link, p_prev, p_next = '', pagy_link_proc(pagy, 'class="page-link"'
|
10
|
+
tags, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
|
10
11
|
|
11
|
-
tags << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'
|
12
|
-
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev'
|
12
|
+
tags << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
13
|
+
: %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
|
13
14
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
14
15
|
tags << if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
|
15
16
|
elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
|
16
|
-
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap'
|
17
|
+
elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
|
17
18
|
end
|
18
19
|
end
|
19
|
-
tags << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'
|
20
|
-
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next'
|
20
|
+
tags << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
21
|
+
: %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
|
21
22
|
%(<nav class="pagy-nav-boostrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{tags}</ul></nav>)
|
22
23
|
end
|
23
24
|
|
data/lib/pagy/extras/compact.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/compact
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
class Pagy
|
4
5
|
# Add nav helpers for compact pagination
|
@@ -7,19 +8,19 @@ class Pagy
|
|
7
8
|
# Generic compact pagination: it returns the html with the series of links to the pages
|
8
9
|
# we use a numeric input tag to set the page and the PagyCompact javascript to navigate
|
9
10
|
def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
|
10
|
-
tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
11
|
+
tags, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
11
12
|
|
12
13
|
tags << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
|
13
14
|
|
14
15
|
tags << link.call(MARKER, '', %(style="display: none;" ))
|
15
|
-
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'
|
16
|
-
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'
|
16
|
+
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
17
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
17
18
|
|
18
19
|
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'
|
20
|
+
tags << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</span> )
|
20
21
|
|
21
|
-
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'
|
22
|
-
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next'
|
22
|
+
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
23
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
23
24
|
|
24
25
|
tags << %(</nav><script>PagyCompact('#{id}', '#{MARKER}', '#{p_page}');</script>)
|
25
26
|
end
|
@@ -27,21 +28,21 @@ class Pagy
|
|
27
28
|
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
|
28
29
|
# we use a numeric input tag to set the page and the PagyCompact javascript to navigate
|
29
30
|
def pagy_nav_bootstrap_compact(pagy, id=caller(1,1)[0].hash)
|
30
|
-
tags, link, p_prev, p_next, p_page, p_pages = '', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
31
|
+
tags, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
31
32
|
|
32
33
|
tags << %(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">)
|
33
34
|
|
34
35
|
tags << link.call(MARKER, '', %(style="display: none;" ))
|
35
36
|
|
36
37
|
tags << %(<div class="btn-group" role="group">)
|
37
|
-
tags << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'
|
38
|
-
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev'
|
38
|
+
tags << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
|
39
|
+
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
|
39
40
|
|
40
41
|
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'
|
42
|
+
tags << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
|
42
43
|
|
43
|
-
tags << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'
|
44
|
-
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next'
|
44
|
+
tags << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
45
|
+
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
45
46
|
|
46
47
|
tags << %(</div></nav><script>PagyCompact('#{id}', '#{MARKER}', '#{p_page}');</script>)
|
47
48
|
end
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
class Pagy
|
4
5
|
|
@@ -31,11 +32,11 @@ class Pagy
|
|
31
32
|
def pagy_items_selector(pagy, id=caller(1,1)[0].hash)
|
32
33
|
pagy = pagy.clone; p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
|
33
34
|
|
34
|
-
tags =
|
35
|
+
tags = +%(<span id="pagy-items-#{id}">)
|
35
36
|
|
36
37
|
tags << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
|
37
38
|
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
|
38
|
-
tags << %(#{pagy_t('pagy.items.show'
|
39
|
+
tags << %(#{pagy_t('pagy.items.show')} #{input} #{pagy_t('pagy.items.items')})
|
39
40
|
|
40
41
|
tags << %(</span><script>PagyItems('#{id}', '#{MARKER}', #{pagy.from});</script>)
|
41
42
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/responsive
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'json'
|
4
5
|
|
@@ -33,38 +34,37 @@ class Pagy
|
|
33
34
|
# Generic responsive pagination: it returns the html with the series of links to the pages
|
34
35
|
# we build the tags as a json object string and render them with the PagyResponsive javascript
|
35
36
|
def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
|
36
|
-
tags, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
37
|
+
tags, link, p_prev, p_next, responsive = +'{', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
37
38
|
|
38
|
-
tags << (p_prev ? %('prev':'<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'
|
39
|
-
: %('prev':'<span class="page prev disabled">#{pagy_t('pagy.nav.prev'
|
39
|
+
tags << (p_prev ? %('prev':'<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> ',)
|
40
|
+
: %('prev':'<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ',))
|
40
41
|
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
41
42
|
tags << if item.is_a?(Integer); %('#{item}':'<span class="page">#{link.call item}</span> ',) # page link
|
42
43
|
elsif item.is_a?(String) ; %('#{item}':'<span class="page active">#{item}</span> ',) # current page
|
43
|
-
elsif item == :gap ; %('#{item}':'<span class="page gap">#{pagy_t('pagy.nav.gap'
|
44
|
+
elsif item == :gap ; %('#{item}':'<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ',) # page gap
|
44
45
|
end
|
45
46
|
end
|
46
|
-
tags << (p_next ? %('next':'<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'
|
47
|
-
: %('next':'<span class="page next disabled">#{pagy_t('pagy.nav.next'
|
47
|
+
tags << (p_next ? %('next':'<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>'})
|
48
|
+
: %('next':'<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>'}))
|
48
49
|
script = %(<script>PagyResponsive('#{id}', #{tags}, #{responsive[:widths].to_json}, #{responsive[:series].to_json});</script>)
|
49
50
|
%(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
|
50
51
|
end
|
51
52
|
|
52
|
-
|
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, link, p_prev, p_next, responsive = '{', pagy_link_proc(pagy, 'class="page-link"'
|
56
|
+
tags, link, p_prev, p_next, responsive = +'{', pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
|
57
57
|
|
58
|
-
tags << (p_prev ? %('prev':'<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'
|
59
|
-
: %('prev':'<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev'
|
58
|
+
tags << (p_prev ? %('prev':'<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>',)
|
59
|
+
: %('prev':'<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</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
|
-
elsif item == :gap ; %('#{item}':'<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap'
|
63
|
+
elsif item == :gap ; %('#{item}':'<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>',) # page gap
|
64
64
|
end
|
65
65
|
end
|
66
|
-
tags << (p_next ? %('next':'<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'
|
67
|
-
: %('next':'<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next'
|
66
|
+
tags << (p_next ? %('next':'<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>'})
|
67
|
+
: %('next':'<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</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
@@ -1,4 +1,5 @@
|
|
1
1
|
# See Pagy::Frontend API documentation: https://ddnexus.github.io/pagy/api/frontend
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'yaml'
|
4
5
|
|
@@ -10,63 +11,59 @@ class Pagy
|
|
10
11
|
|
11
12
|
# Generic pagination: it returns the html with the series of links to the pages
|
12
13
|
def pagy_nav(pagy)
|
13
|
-
tags, link, p_prev, p_next = '', pagy_link_proc(pagy), pagy.prev, pagy.next
|
14
|
+
tags, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
14
15
|
|
15
|
-
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'
|
16
|
-
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev'
|
16
|
+
tags << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
17
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
17
18
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
|
-
tags << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> )
|
19
|
-
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> )
|
20
|
-
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap'
|
19
|
+
tags << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
20
|
+
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
21
|
+
elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
|
21
22
|
end
|
22
23
|
end
|
23
|
-
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'
|
24
|
-
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next'
|
24
|
+
tags << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
25
|
+
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
25
26
|
%(<nav class="pagy-nav pagination" role="navigation" aria-label="pager">#{tags}</nav>)
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
29
|
# Return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
|
30
30
|
def pagy_info(pagy)
|
31
31
|
name = pagy_t(pagy.vars[:item_path], count: pagy.count)
|
32
|
-
path = pagy.pages == 1 ? 'pagy.info.single_page'
|
32
|
+
path = pagy.pages == 1 ? 'pagy.info.single_page' : 'pagy.info.multiple_pages'
|
33
33
|
pagy_t(path, item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
# this works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
38
37
|
def pagy_url_for(page, pagy)
|
39
38
|
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, **p_vars[:params])
|
40
39
|
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
41
40
|
end
|
42
41
|
|
43
|
-
|
44
42
|
# Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
|
45
43
|
def pagy_get_params(params) params end
|
46
44
|
|
47
|
-
|
48
|
-
MARKER = "-pagy-#{'pagy'.hash}-".freeze
|
45
|
+
MARKER = "-pagy-#{'pagy'.hash}-"
|
49
46
|
|
50
47
|
# Returns a performance optimized proc to generate the HTML links
|
51
48
|
# Benchmarked on a 20 link nav: it is ~27x faster and uses ~13x less memory than rails' link_to
|
52
|
-
def pagy_link_proc(pagy, link_extra=''
|
49
|
+
def pagy_link_proc(pagy, link_extra='')
|
53
50
|
p_prev, p_next = pagy.prev, pagy.next
|
54
51
|
a, b = %(<a href="#{pagy_url_for(MARKER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(MARKER, 2)
|
55
|
-
-> (n, text=n, extra=''
|
56
|
-
|
57
|
-
|
52
|
+
-> (n, text=n, extra='') { "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'
|
53
|
+
elsif n == p_next ; ' rel="next"'
|
54
|
+
else '' end } #{extra}>#{text}</a>" }
|
58
55
|
end
|
59
56
|
|
60
57
|
# Pagy::Frontend::I18N constant
|
61
58
|
I18N_DATA = YAML.load_file(Pagy.root.join('locales', 'pagy.yml')).first[1]
|
62
|
-
zero_one = ['zero'
|
59
|
+
zero_one = ['zero', 'one']; I18N = { plurals: -> (c) {zero_one[c] || 'other'}}
|
63
60
|
def I18N.load_file(file) I18N_DATA.replace(YAML.load_file(file).first[1]) end
|
64
61
|
|
65
62
|
# Similar to I18n.t for interpolation and pluralization but without translation
|
66
63
|
# Use only for single-language apps: it is specialized for Pagy and 5x faster than I18n.t
|
67
64
|
# See also https://ddnexus.github.io/pagy/extras/i18n to use the standard I18n gem instead
|
68
65
|
def pagy_t(path, vars={})
|
69
|
-
value = I18N_DATA.dig(*path.to_s.split('.'
|
66
|
+
value = I18N_DATA.dig(*path.to_s.split('.')) or return %(translation missing: "#{path}")
|
70
67
|
if value.is_a?(Hash)
|
71
68
|
vars.key?(:count) or return value
|
72
69
|
plural = I18N[:plurals].call(vars[:count])
|
data/lib/pagy.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# See Pagy API documentation: https://ddnexus.github.io/pagy/api/pagy
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'pathname'
|
4
5
|
|
5
|
-
class Pagy ; VERSION = '0.9.
|
6
|
+
class Pagy ; VERSION = '0.9.2'
|
6
7
|
|
7
8
|
class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
|
8
9
|
|
@@ -10,13 +11,13 @@ class Pagy ; VERSION = '0.9.1'
|
|
10
11
|
def self.root; Pathname.new(__FILE__).dirname end
|
11
12
|
|
12
13
|
# default vars
|
13
|
-
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:''
|
14
|
+
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name' }
|
14
15
|
|
15
16
|
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
|
16
17
|
|
17
18
|
# Merge and validate the options, do some simple aritmetic and set the instance variables
|
18
19
|
def initialize(vars)
|
19
|
-
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == ''
|
20
|
+
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars
|
20
21
|
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
|
21
22
|
(@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
|
22
23
|
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.9.
|
4
|
+
version: 0.9.2
|
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-20 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,
|