pagy 0.13.1 → 0.14.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 +19 -0
- data/lib/pagy/extras/initializer_example.rb +7 -3
- data/lib/pagy/extras/materialize.rb +25 -0
- data/lib/pagy/extras/out_of_range.rb +3 -0
- data/lib/pagy/extras/responsive.rb +21 -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: 3ea9f5556f76cbbc137144639af45e161a9caf36bde512201911ed04103c7707
|
4
|
+
data.tar.gz: c3a0337dd4d124275e33bab79e2ff30d0f7a56a6a715a602dfc06deef88dda86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8be1f7f3369f8ce276d04bf67436e3bd40c3a1f788720f04a9928da63a60a4157fea59344c5bebabb6f7303f8a45d094aa6993c7b87bc1534ac219fa4efa6f0
|
7
|
+
data.tar.gz: e676ffa46c89159efe7272b4250e3819762355b3c45e73f4a1ad5e6d378697bfe5048ec27c2fef2a19dd597fd288d3bf7b453c19839c00f8fd4cdfd37eeea87a
|
data/lib/pagy.rb
CHANGED
data/lib/pagy/extras/compact.rb
CHANGED
@@ -55,5 +55,24 @@ class Pagy
|
|
55
55
|
html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}"]</script>)
|
56
56
|
end
|
57
57
|
|
58
|
+
# Compact pagination for materialize: it returns the html with the series of links to the pages
|
59
|
+
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
60
|
+
def pagy_nav_compact_materialize(pagy, id=caller(1,1)[0].hash)
|
61
|
+
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
|
62
|
+
|
63
|
+
html << %(<div id="pagy-nav-#{id}" class="pagy-nav-compact-materialize pagination" role="navigation" aria-label="pager">)
|
64
|
+
html << link.call(MARKER, '', %(style="display: none;" ))
|
65
|
+
html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
|
66
|
+
html << '<ul class="pagination" style="margin: 0px;">'
|
67
|
+
li_style = 'style="vertical-align: middle;"'
|
68
|
+
html << (p_prev ? %(<li class="waves-effect prev" #{li_style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
69
|
+
: %(<li class="prev disabled" #{li_style}><a href="#"><i class="material-icons">chevron_left</i></a></li>))
|
70
|
+
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
71
|
+
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
|
+
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
|
+
: %(<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>)
|
75
|
+
end
|
76
|
+
|
58
77
|
end
|
59
78
|
end
|
@@ -21,17 +21,21 @@
|
|
21
21
|
# See https://ddnexus.github.io/pagy/extras/compact
|
22
22
|
# require 'pagy/extras/compact'
|
23
23
|
|
24
|
-
# Items:
|
24
|
+
# Items: Allow the client to request a custom number of items per page with a ready to use selector UI
|
25
25
|
# See https://ddnexus.github.io/pagy/extras/items
|
26
26
|
# require 'pagy/extras/items'
|
27
27
|
# Pagy::VARS[:items_param] = :items # default
|
28
28
|
# Pagy::VARS[:max_items] = 100 # default
|
29
29
|
|
30
|
+
# Materialize: Nav helper for Materialize pagination
|
31
|
+
# See https://ddnexus.github.io/pagy/extras/materialize
|
32
|
+
# require 'pagy/extras/materialize'
|
33
|
+
|
30
34
|
# Out Of Range: Allow for easy handling of out of range pages
|
31
35
|
# See https://ddnexus.github.io/pagy/extras/out_of_range
|
32
|
-
# Pagy::VARS[:out_of_range_mode] = :last_page # default (other options :empty_page and :exception
|
36
|
+
# Pagy::VARS[:out_of_range_mode] = :last_page # default (other options: :empty_page and :exception)
|
33
37
|
|
34
|
-
# Responsive: On resize, the number of page links will adapt in real-time to the available window
|
38
|
+
# Responsive: On resize, the number of page links will adapt in real-time to the available window/container width
|
35
39
|
# See https://ddnexus.github.io/pagy/extras/responsive
|
36
40
|
# require 'pagy/extras/responsive'
|
37
41
|
# See https://ddnexus.github.io/pagy/extras/responsive#breakpoints
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Pagy
|
5
|
+
# Add nav helper for materialize pagination
|
6
|
+
module Frontend
|
7
|
+
|
8
|
+
# Pagination for materialize: it returns the html with the series of links to the pages
|
9
|
+
def pagy_nav_materialize(pagy)
|
10
|
+
html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
|
11
|
+
html << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
12
|
+
: %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
|
13
|
+
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
14
|
+
html << if item.is_a?(Integer); %(<li class="waves-effect">#{link.call item}</li>) # page link
|
15
|
+
elsif item.is_a?(String) ; %(<li class="active">#{link.call item}</li>) # active page
|
16
|
+
elsif item == :gap ; %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
|
17
|
+
end
|
18
|
+
end
|
19
|
+
html << (p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
20
|
+
: %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
21
|
+
%(<div class="pagy-nav-materialize pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -92,5 +92,26 @@ class Pagy
|
|
92
92
|
%(<nav id="pagy-nav-#{id}" class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
|
93
93
|
end
|
94
94
|
|
95
|
+
# Responsive pagination for Materialize: it returns the html with the series of links to the pages
|
96
|
+
# rendered by the Pagy.responsive javascript
|
97
|
+
def pagy_nav_responsive_materialize(pagy, id=caller(1,1)[0].hash)
|
98
|
+
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
|
99
|
+
|
100
|
+
tags['before'] = +'<ul class="pagination">'
|
101
|
+
tags['before'] << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
102
|
+
: %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
|
103
|
+
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
104
|
+
tags[item.to_s] = if item.is_a?(Integer); %(<li class="waves-effect">#{link.call item}</li>) # page link
|
105
|
+
elsif item.is_a?(String) ; %(<li class="active">#{link.call item}</li>) # active page
|
106
|
+
elsif item == :gap ; %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
|
107
|
+
end
|
108
|
+
end
|
109
|
+
tags['after'] = +(p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
110
|
+
: %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
|
111
|
+
tags['after'] << '</ul>'
|
112
|
+
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
113
|
+
%(<div id="pagy-nav-#{id}" class="pagy-nav-responsive-materialize pagination" role="navigation" aria-label="pager"></div>#{script})
|
114
|
+
end
|
115
|
+
|
95
116
|
end
|
96
117
|
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.14.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-17 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,
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/pagy/extras/initializer_example.rb
|
34
34
|
- lib/pagy/extras/items.rb
|
35
35
|
- lib/pagy/extras/javascripts/pagy.js
|
36
|
+
- lib/pagy/extras/materialize.rb
|
36
37
|
- lib/pagy/extras/out_of_range.rb
|
37
38
|
- lib/pagy/extras/responsive.rb
|
38
39
|
- lib/pagy/extras/templates/nav.html.erb
|