pagy 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c1bb5b64fb34727fe1c413e7955d77efe07ab9092635a02a28c3fd9755e0c9d
4
- data.tar.gz: 2a30697bb6be24894258df5a67871f5d07adac6b0868a58c205197484909288e
3
+ metadata.gz: d8687d221589df328c1fc7a367ee8b1e1a1e3da87c83cbe92800af0ac514b603
4
+ data.tar.gz: b6327ed3bb6aae4daedbfb92c472f136283746be36012951a9da3ff96ec1ad1e
5
5
  SHA512:
6
- metadata.gz: befb8dc5ef5ec753f4b644c887de0196e6b5ccb026fe86258c73eb6924af6e535bd0837580b8c30e945f638c65cde5b1fafe31b0729cfd92fb0bd6d48f800d00
7
- data.tar.gz: dffdcc261a1a2176617774614c453ee12c0dc94761293f202b4d3db43ea281b6dac0c9524eb51806ed52bcf430ebd043717c7dc9bcc809f3721003b3a6b101a8
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
- # Breakoints var used byt the responsive helpers
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, items and responsive extras
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'pathname'
5
5
 
6
- class Pagy ; VERSION = '0.18.0'
6
+ class Pagy ; VERSION = '0.19.0'
7
7
 
8
8
  class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
9
9
 
@@ -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')}&nbsp;#{input}&nbsp;#{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.18.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