pagy 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +6 -3
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/semantic.rb +63 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8687d221589df328c1fc7a367ee8b1e1a1e3da87c83cbe92800af0ac514b603
|
4
|
+
data.tar.gz: b6327ed3bb6aae4daedbfb92c472f136283746be36012951a9da3ff96ec1ad1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f6881f9d58f5f4a30d1d4b97829dd2915072477d8b84d64b3f49417f6c9b04a72bcbf8e6fca90d085c04d4161952e12fdbebb81d2fa553e239b29b629246ec
|
7
|
+
data.tar.gz: e23a969cc2414b7291f48d60b0b6e55e8fe7e0ade2657243b595b24a03d7567fc7d4ebe87fdf825f2c6676360251e5f048188d799dc1ba3c458cab1c48c5c95d
|
data/lib/config/pagy.rb
CHANGED
@@ -41,12 +41,15 @@
|
|
41
41
|
# See https://ddnexus.github.io/pagy/extras/materialize
|
42
42
|
# require 'pagy/extras/materialize'
|
43
43
|
|
44
|
-
#
|
44
|
+
# Semantic: Nav helper for Semantic UI pagination
|
45
|
+
# See https://ddnexus.github.io/pagy/extras/semantic
|
46
|
+
# require 'pagy/extras/semantic'
|
47
|
+
|
48
|
+
# Breakoints var used by the responsive nav helpers
|
45
49
|
# See https://ddnexus.github.io/pagy/extras/navs#breakpoints
|
46
50
|
# Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
|
47
51
|
|
48
52
|
|
49
|
-
|
50
53
|
# Feature Extras
|
51
54
|
|
52
55
|
# Items: Allow the client to request a custom number of items per page with a ready to use selector UI
|
@@ -88,7 +91,7 @@
|
|
88
91
|
|
89
92
|
# Rails
|
90
93
|
|
91
|
-
# Rails: extras assets path required by compact
|
94
|
+
# Rails: extras assets path required by the compact and responsive navs, and the items extra
|
92
95
|
# See https://ddnexus.github.io/pagy/extras#javascript
|
93
96
|
# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
|
94
97
|
|
data/lib/pagy.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pagy/extras/shared'
|
5
|
+
|
6
|
+
class Pagy
|
7
|
+
module Frontend
|
8
|
+
|
9
|
+
# Pagination for semantic-ui: it returns the html with the series of links to the pages
|
10
|
+
def pagy_nav_semantic(pagy)
|
11
|
+
html, link, p_prev, p_next = +'', pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
|
12
|
+
|
13
|
+
html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
14
|
+
: %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
|
15
|
+
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
|
+
html << if item.is_a?(Integer); %(#{link.call item}) # page link
|
17
|
+
elsif item.is_a?(String) ; %(<a class="item active">#{item}</a>) # current page
|
18
|
+
elsif item == :gap ; %(<div class="disabled item">...</div>) # page gap
|
19
|
+
end
|
20
|
+
end
|
21
|
+
html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
22
|
+
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
23
|
+
%(<div class="ui pagination menu" aria-label="pager">#{html}</div>)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Compact pagination for semantic: it returns the html with the series of links to the pages
|
27
|
+
# we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
|
28
|
+
def pagy_nav_compact_semantic(pagy, id=caller(1,1)[0].hash)
|
29
|
+
html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
|
30
|
+
|
31
|
+
html << %(<div id="pagy-nav-#{id}" class="pagy-nav-compact-semantic ui compact menu" role="navigation" aria-label="pager">)
|
32
|
+
html << link.call(MARKER, '', %(style="display: none;" ))
|
33
|
+
(html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
|
34
|
+
html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
35
|
+
: %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
|
36
|
+
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;">)
|
37
|
+
html << %(<div class="pagy-compact-input item">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div> )
|
38
|
+
html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
39
|
+
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
40
|
+
html << %(</div><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Responsive pagination for semantic: it returns the html with the series of links to the pages
|
44
|
+
# rendered by the Pagy.responsive javascript
|
45
|
+
def pagy_nav_responsive_semantic(pagy, id=caller(1,1)[0].hash)
|
46
|
+
tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.responsive
|
47
|
+
|
48
|
+
tags['before'] = (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
|
49
|
+
: %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
|
50
|
+
responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
51
|
+
tags[item.to_s] = if item.is_a?(Integer); %(#{link.call item}) # page link
|
52
|
+
elsif item.is_a?(String) ; %(<a class="item active">#{item}</a>) # current page
|
53
|
+
elsif item == :gap ; %(<div class="disabled item">...</div>) # page gap
|
54
|
+
end
|
55
|
+
end
|
56
|
+
tags['after'] = (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
|
57
|
+
: %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
|
58
|
+
script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
|
59
|
+
%(<div id="pagy-nav-#{id}" class="pagy-nav-responsive-semantic ui pagination menu" role="navigation" aria-label="pager"></div>#{script})
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/pagy/extras/navs.rb
|
38
38
|
- lib/pagy/extras/out_of_range.rb
|
39
39
|
- lib/pagy/extras/searchkick.rb
|
40
|
+
- lib/pagy/extras/semantic.rb
|
40
41
|
- lib/pagy/extras/shared.rb
|
41
42
|
- lib/pagy/extras/trim.rb
|
42
43
|
- lib/pagy/frontend.rb
|