pagy 0.14.0 → 0.15.0
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 +1 -1
- data/lib/pagy/extras/compact.rb +10 -6
- data/lib/pagy/extras/initializer_example.rb +4 -0
- data/lib/pagy/extras/items.rb +7 -6
- data/lib/pagy/extras/javascripts/pagy.js +8 -4
- data/lib/pagy/extras/trim.rb +30 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 681052934a39cf55ae637f4760440afea264bdef4edb5b6d3f42cfc1a22f78d5
|
4
|
+
data.tar.gz: '0728e6ad1211af132b074c0a41419136b4554406a78d002c07af29db9b6e97eb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2577f76f006a80e85001f0d16eb85f87b4f47d1439040754355131e5032e75e997273d9174c18fd2979b21e57fe709dcee5acdbc7c6c8264b0d5a438bbede6e2
|
7
|
+
data.tar.gz: 0a0d7c7a41ea3020c60b1e3461ff5a3a68e6ddbc592f74492e17a3741905e5dd0219734ad0361058dba0a7b15432462cc41fa5fcb391742ee1917ee442e3d97e
|
data/lib/pagy.rb
CHANGED
data/lib/pagy/extras/compact.rb
CHANGED
@@ -12,13 +12,14 @@ class Pagy
|
|
12
12
|
|
13
13
|
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
|
14
14
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
15
|
-
html <<
|
15
|
+
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
16
|
+
html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
16
17
|
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
17
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;">)
|
18
19
|
html << %(<span class="pagy-compact-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</span> )
|
19
20
|
html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
20
21
|
: %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
|
21
|
-
html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
22
|
+
html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
22
23
|
end
|
23
24
|
|
24
25
|
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
|
@@ -28,14 +29,15 @@ class Pagy
|
|
28
29
|
|
29
30
|
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">)
|
30
31
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
31
|
-
html << %(
|
32
|
+
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
33
|
+
html << %(<div class="btn-group" role="group">)
|
32
34
|
html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
|
33
35
|
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
|
34
36
|
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;">)
|
35
37
|
html << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
|
36
38
|
html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
|
37
39
|
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
|
38
|
-
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
40
|
+
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
39
41
|
end
|
40
42
|
|
41
43
|
# Compact pagination for Bulma: it returns the html with the series of links to the pages
|
@@ -45,6 +47,7 @@ class Pagy
|
|
45
47
|
|
46
48
|
html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bulma" role="navigation" aria-label="pagination">)
|
47
49
|
html << link.call(MARKER, '', 'style="display: none;"')
|
50
|
+
(html << link.call(1, '', %(style="display: none;"))) if defined?(TRIM)
|
48
51
|
html << %(<div class="field is-grouped is-grouped-centered" role="group">)
|
49
52
|
html << (p_prev ? %(<p class="control">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}</p>)
|
50
53
|
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.prev')}</a></p>))
|
@@ -52,7 +55,7 @@ class Pagy
|
|
52
55
|
html << %(<div class="pagy-compact-input control level is-mobile">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
|
53
56
|
html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
|
54
57
|
: %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
|
55
|
-
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
58
|
+
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
56
59
|
end
|
57
60
|
|
58
61
|
# Compact pagination for materialize: it returns the html with the series of links to the pages
|
@@ -62,6 +65,7 @@ class Pagy
|
|
62
65
|
|
63
66
|
html << %(<div id="pagy-nav-#{id}" class="pagy-nav-compact-materialize pagination" role="navigation" aria-label="pager">)
|
64
67
|
html << link.call(MARKER, '', %(style="display: none;" ))
|
68
|
+
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
65
69
|
html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
|
66
70
|
html << '<ul class="pagination" style="margin: 0px;">'
|
67
71
|
li_style = 'style="vertical-align: middle;"'
|
@@ -71,7 +75,7 @@ class Pagy
|
|
71
75
|
html << %(<div class="pagy-compact-input btn-flat" style="cursor: default; padding: 0px">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
|
72
76
|
html << (p_next ? %(<li class="waves-effect next" #{li_style}>#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
73
77
|
: %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
74
|
-
html << %(</ul></div><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
78
|
+
html << %(</ul></div><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
75
79
|
end
|
76
80
|
|
77
81
|
end
|
@@ -41,6 +41,10 @@
|
|
41
41
|
# See https://ddnexus.github.io/pagy/extras/responsive#breakpoints
|
42
42
|
# Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
|
43
43
|
|
44
|
+
# Trim: Remove the page=1 param from links
|
45
|
+
# See https://ddnexus.github.io/pagy/extras/trim
|
46
|
+
# require 'pagy/extras/trim'
|
47
|
+
|
44
48
|
|
45
49
|
# Pagy Variables
|
46
50
|
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -10,23 +10,24 @@ class Pagy
|
|
10
10
|
# Handle a custom number of :items from params
|
11
11
|
module Backend ; private
|
12
12
|
|
13
|
-
alias_method :
|
14
|
-
|
15
|
-
def pagy_get_vars(collection, vars)
|
13
|
+
alias_method :pagy_get_vars_without_items, :pagy_get_vars
|
14
|
+
def pagy_get_vars_with_items(collection, vars)
|
16
15
|
vars[:items] ||= (items = params[vars[:items_param] || VARS[:items_param]]) && # :items from :items_param
|
17
16
|
[items&.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items
|
18
|
-
|
17
|
+
pagy_get_vars_without_items(collection, vars)
|
19
18
|
end
|
19
|
+
alias_method :pagy_get_vars, :pagy_get_vars_with_items
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
23
|
module Frontend
|
24
24
|
|
25
|
-
|
26
|
-
def
|
25
|
+
alias_method :pagy_url_for_without_items, :pagy_url_for
|
26
|
+
def pagy_url_for_with_items(page, pagy)
|
27
27
|
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param] => page, p_vars[:items_param] => p_vars[:items]).merge!(p_vars[:params])
|
28
28
|
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
29
29
|
end
|
30
|
+
alias_method :pagy_url_for, :pagy_url_for_with_items
|
30
31
|
|
31
32
|
# Return the items selector HTML. For example "Show [20] items per page"
|
32
33
|
def pagy_items_selector(pagy, id=caller(1,1)[0].hash)
|
@@ -13,15 +13,19 @@ Pagy.addInputEventListeners = function(input, handler){
|
|
13
13
|
input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
|
14
14
|
};
|
15
15
|
|
16
|
-
Pagy.compact = function(id, marker, page){
|
16
|
+
Pagy.compact = function(id, marker, page, trim){
|
17
17
|
var pagyNav = document.getElementById('pagy-nav-'+id),
|
18
18
|
input = pagyNav.getElementsByTagName('input')[0],
|
19
19
|
link = pagyNav.getElementsByTagName('a')[0],
|
20
|
+
linkP1 = pagyNav.getElementsByTagName('a')[1],
|
20
21
|
go = function(){
|
21
22
|
if (page !== input.value) {
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
if (trim === true && input.value === '1') { linkP1.click() }
|
24
|
+
else {
|
25
|
+
var href = link.getAttribute('href').replace(marker, input.value);
|
26
|
+
link.setAttribute('href', href);
|
27
|
+
link.click();
|
28
|
+
}
|
25
29
|
}
|
26
30
|
};
|
27
31
|
Pagy.addInputEventListeners(input, go);
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy
|
5
|
+
|
6
|
+
module Frontend
|
7
|
+
|
8
|
+
# boolean used by the compact extra
|
9
|
+
TRIM = true
|
10
|
+
|
11
|
+
def pagy_trim_url(url, param_string)
|
12
|
+
url.sub(/((?:[?&])#{param_string}\z|\b(?<=[?&])#{param_string}&)/, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :pagy_link_proc_without_trim, :pagy_link_proc
|
16
|
+
def pagy_link_proc_with_trim(pagy, link_extra='')
|
17
|
+
p_prev, p_next, p_vars = pagy.prev, pagy.next, pagy.vars
|
18
|
+
url = pagy_url_for(MARKER, pagy)
|
19
|
+
p1url = pagy_trim_url(url, "#{p_vars[:page_param]}=#{MARKER}")
|
20
|
+
p1 = %(<a href="#{p1url}" #{p_vars[:link_extra]} #{link_extra})
|
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}"
|
23
|
+
"#{start}#{ if n == p_prev ; ' rel="prev"'
|
24
|
+
elsif n == p_next ; ' rel="next"'
|
25
|
+
else '' end } #{extra}>#{text}</a>" }
|
26
|
+
end
|
27
|
+
alias_method :pagy_link_proc, :pagy_link_proc_with_trim
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
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.
|
4
|
+
version: 0.15.0
|
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-
|
11
|
+
date: 2018-07-29 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,
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/pagy/extras/templates/nav_bulma.html.erb
|
46
46
|
- lib/pagy/extras/templates/nav_bulma.html.haml
|
47
47
|
- lib/pagy/extras/templates/nav_bulma.html.slim
|
48
|
+
- lib/pagy/extras/trim.rb
|
48
49
|
- lib/pagy/frontend.rb
|
49
50
|
- pagy.gemspec
|
50
51
|
homepage: https://github.com/ddnexus/pagy
|