pagy 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c29e24c7c57ca390d1d7b1418a29db73e6b60449dd0149147247ddbd9e9468c
4
- data.tar.gz: 5971ae0908e0b570f3288036f94fb2039c5286de5bfae23a99412c5c9a7854bc
3
+ metadata.gz: 2c1bb5b64fb34727fe1c413e7955d77efe07ab9092635a02a28c3fd9755e0c9d
4
+ data.tar.gz: 2a30697bb6be24894258df5a67871f5d07adac6b0868a58c205197484909288e
5
5
  SHA512:
6
- metadata.gz: 48390fcfb1c9a03ecf3f5c722c016545af0ab107aebf3f380704535319f46b330caa81fd2347428dd1f87dacf9b2e4e0ca40a61ed32f66d290a92b00cbd8ac8f
7
- data.tar.gz: 7c39db7c431d6072267128bb0c7af080b63bb0ae32aab803c7c5aff2fd269660b70611eb256a74228e97c9a7bc2cc5cb59182522386f1195c8bf974f625bfcaf
6
+ metadata.gz: befb8dc5ef5ec753f4b644c887de0196e6b5ccb026fe86258c73eb6924af6e535bd0837580b8c30e945f638c65cde5b1fafe31b0729cfd92fb0bd6d48f800d00
7
+ data.tar.gz: dffdcc261a1a2176617774614c453ee12c0dc94761293f202b4d3db43ea281b6dac0c9524eb51806ed52bcf430ebd043717c7dc9bcc809f3721003b3a6b101a8
@@ -1,4 +1,4 @@
1
- # Example of initializer file
1
+ # Pagy initializer file
2
2
  # Customize only what you really need but notice that Pagy works also without any of the following lines.
3
3
 
4
4
 
@@ -6,19 +6,6 @@
6
6
  # See https://ddnexus.github.io/pagy/extras
7
7
 
8
8
 
9
- # Component Extras
10
-
11
- # Compact: An alternative UI that combines the pagination with the nav info in one compact element
12
- # See https://ddnexus.github.io/pagy/extras/compact
13
- # require 'pagy/extras/compact'
14
-
15
- # Responsive: On resize, the number of page links will adapt in real-time to the available window/container width
16
- # See https://ddnexus.github.io/pagy/extras/responsive
17
- # require 'pagy/extras/responsive'
18
- # See https://ddnexus.github.io/pagy/extras/responsive#breakpoints
19
- # Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
20
-
21
-
22
9
  # Backend Extras
23
10
 
24
11
  # Array: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
@@ -32,22 +19,33 @@
32
19
 
33
20
  # Frontend Extras
34
21
 
35
- # Bootstrap: Nav helper and templates for Bootstrap pagination
22
+ # Navs: Add responsive and compact generic/unstyled nav helpers
23
+ # Notice: the other frontend extras add their own framework-styled versions,
24
+ # so require this extra only if you need the plain unstyled version
25
+ # See https://ddnexus.github.io/pagy/extras/navs
26
+ # require 'pagy/extras/navs'
27
+
28
+ # Bootstrap: Nav, responsive and compact helpers and templates for Bootstrap pagination
36
29
  # See https://ddnexus.github.io/pagy/extras/bootstrap
37
30
  # require 'pagy/extras/bootstrap'
38
31
 
39
- # Bulma: Nav helper and templates for Bulma pagination
32
+ # Bulma: Nav, responsive and compact helpers and templates for Bulma pagination
40
33
  # See https://ddnexus.github.io/pagy/extras/bulma
41
34
  # require 'pagy/extras/bulma'
42
35
 
43
- # Foundation: Nav helper and templates for Foundation pagination
36
+ # Foundation: Nav, responsive and compact helpers and templates for Foundation pagination
44
37
  # See https://ddnexus.github.io/pagy/extras/foundation
45
38
  # require 'pagy/extras/foundation'
46
39
 
47
- # Materialize: Nav helper for Materialize pagination
40
+ # Materialize: Nav, responsive and compact helpers for Materialize pagination
48
41
  # See https://ddnexus.github.io/pagy/extras/materialize
49
42
  # require 'pagy/extras/materialize'
50
43
 
44
+ # Breakoints var used byt the responsive helpers
45
+ # See https://ddnexus.github.io/pagy/extras/navs#breakpoints
46
+ # Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
47
+
48
+
51
49
 
52
50
  # Feature Extras
53
51
 
@@ -91,8 +89,8 @@
91
89
  # Rails
92
90
 
93
91
  # Rails: extras assets path required by compact, items and responsive extras
94
- # See https://ddnexus.github.io/pagy/extras
95
- # Rails.application.config.assets.paths << Pagy.root.join('pagy', 'extras', 'javascripts')
92
+ # See https://ddnexus.github.io/pagy/extras#javascript
93
+ # Rails.application.config.assets.paths << Pagy.root.join('javascripts')
96
94
 
97
95
 
98
96
  # I18n
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'pathname'
5
5
 
6
- class Pagy ; VERSION = '0.17.0'
6
+ class Pagy ; VERSION = '0.18.0'
7
7
 
8
8
  class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
9
9
 
@@ -1,8 +1,9 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'pagy/extras/shared'
5
+
4
6
  class Pagy
5
- # Add nav helper for bootstrap pagination
6
7
  module Frontend
7
8
 
8
9
  # Pagination for bootstrap: it returns the html with the series of links to the pages
@@ -22,5 +23,44 @@ class Pagy
22
23
  %(<nav class="pagy-nav-bootstrap pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
23
24
  end
24
25
 
26
+ # Compact pagination for bootstrap: 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_bootstrap(pagy, id=caller(1,1)[0].hash)
29
+ html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
30
+
31
+ html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" 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 << %(<div class="btn-group" role="group">)
35
+ html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
36
+ : %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
37
+ 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;">)
38
+ html << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page')} #{input} #{pagy_t('pagy.compact.of')} #{p_pages}</div>)
39
+ html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
40
+ : %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
41
+ html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
42
+ end
43
+
44
+ # Responsive pagination for bootstrap: it returns the html with the series of links to the pages
45
+ # rendered by the Pagy.responsive javascript
46
+ def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
47
+ tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
48
+
49
+ tags['before'] = +'<ul class="pagination">'
50
+ tags['before'] << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
51
+ : %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
52
+ responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
53
+ tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
54
+ elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
55
+ elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
56
+ end
57
+ end
58
+ tags['after'] = +(p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
59
+ : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
60
+ tags['after'] << '</ul>'
61
+ script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
62
+ %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagination" role="navigation" aria-label="pager"></nav>#{script})
63
+ end
64
+
25
65
  end
26
66
  end
@@ -1,8 +1,9 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'pagy/extras/shared'
5
+
4
6
  class Pagy
5
- # Add nav helper for Bulma pagination
6
7
  module Frontend
7
8
 
8
9
  def pagy_nav_bulma(pagy)
@@ -23,5 +24,44 @@ class Pagy
23
24
  %(<nav class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
24
25
  end
25
26
 
27
+ # Compact pagination for Bulma: it returns the html with the series of links to the pages
28
+ # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
+ def pagy_nav_compact_bulma(pagy, id=caller(1,1)[0].hash)
30
+ html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
31
+
32
+ html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bulma" role="navigation" aria-label="pagination">)
33
+ html << link.call(MARKER, '', 'style="display: none;"')
34
+ (html << link.call(1, '', %(style="display: none;"))) if defined?(TRIM)
35
+ html << %(<div class="field is-grouped is-grouped-centered" role="group">)
36
+ html << (p_prev ? %(<p class="control">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}</p>)
37
+ : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.prev')}</a></p>))
38
+ input = %(<input class="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;">)
39
+ html << %(<div class="pagy-compact-input control level is-mobile">#{pagy_t('pagy.compact.page')}&nbsp;#{input}&nbsp;#{pagy_t('pagy.compact.of')} #{p_pages}</div>)
40
+ html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
41
+ : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
42
+ html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
43
+ end
44
+
45
+ # Responsive pagination for Bulma: it returns the html with the series of links to the pages
46
+ # rendered by the Pagy.responsive javascript
47
+ def pagy_nav_responsive_bulma(pagy, id=caller(1,1)[0].hash)
48
+ tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
49
+
50
+ tags['before'] = +(p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
51
+ : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>))
52
+ tags['before'] << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
53
+ : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
54
+ tags['before'] << '<ul class="pagination-list">'
55
+ responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
56
+ tags[item.to_s] = if item.is_a?(Integer); %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}")}</li>)
57
+ elsif item.is_a?(String) ; %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-current="page" aria-label="page #{item}")}</li>)
58
+ elsif item == :gap ; %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>)
59
+ end
60
+ end
61
+ tags['after'] = '</ul>'
62
+ script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
63
+ %(<nav id="pagy-nav-#{id}" class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
64
+ end
65
+
26
66
  end
27
67
  end
@@ -1,8 +1,9 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'pagy/extras/shared'
5
+
4
6
  class Pagy
5
- # Add nav helper for foundation pagination
6
7
  module Frontend
7
8
 
8
9
  # Pagination for foundation: it returns the html with the series of links to the pages
@@ -22,5 +23,44 @@ class Pagy
22
23
  %(<nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
23
24
  end
24
25
 
26
+ # Compact pagination for foundation: 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_foundation(pagy, id=caller(1,1)[0].hash)
29
+ html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
30
+
31
+ html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-foundation" role="navigation" aria-label="Pagination">)
32
+ html << link.call(MARKER, '', %(style="display: none;" ))
33
+ (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
34
+ html << %(<div class="input-group">)
35
+ html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"')
36
+ : %(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
37
+ input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1.5}rem;">)
38
+ html << %(<span class="input-group-label">#{pagy_t('pagy.compact.page')}</span> #{input} <span class="input-group-label">#{pagy_t('pagy.compact.of')} #{p_pages}</span>)
39
+ html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
40
+ : %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
41
+ html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
42
+ end
43
+
44
+ # Responsive pagination for Foundation: it returns the html with the series of links to the pages
45
+ # rendered by the Pagy.responsive javascript
46
+ def pagy_nav_responsive_foundation(pagy, id=caller(1,1)[0].hash)
47
+ tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
48
+
49
+ tags['before'] = +'<ul class="pagination">'
50
+ tags['before'] << (p_prev ? %(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
51
+ : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>))
52
+ responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
53
+ tags[item.to_s] = if item.is_a?(Integer); %(<li>#{link.call item}</li>) # page link
54
+ elsif item.is_a?(String) ; %(<li class="current"><span class="show-for-sr">#{pagy_t('pagy.nav.current')}</span> #{item}</li>) # active page
55
+ elsif item == :gap ; %(<li class="gap disabled">#{pagy_t('pagy.nav.gap')}</li>) # page gap
56
+ end
57
+ end
58
+ tags['after'] = +(p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
59
+ : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
60
+ tags['after'] << '</ul>'
61
+ script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
62
+ %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-foundation" aria-label="Pagination"></nav>#{script})
63
+ end
64
+
25
65
  end
26
66
  end
@@ -1,8 +1,9 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'pagy/extras/shared'
5
+
4
6
  class Pagy
5
- # Add nav helper for materialize pagination
6
7
  module Frontend
7
8
 
8
9
  # Pagination for materialize: it returns the html with the series of links to the pages
@@ -21,5 +22,46 @@ class Pagy
21
22
  %(<div class="pagy-nav-materialize pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
22
23
  end
23
24
 
25
+ # Compact pagination for materialize: it returns the html with the series of links to the pages
26
+ # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
27
+ def pagy_nav_compact_materialize(pagy, id=caller(1,1)[0].hash)
28
+ html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
29
+
30
+ html << %(<div id="pagy-nav-#{id}" class="pagy-nav-compact-materialize pagination" role="navigation" aria-label="pager">)
31
+ html << link.call(MARKER, '', %(style="display: none;" ))
32
+ (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
33
+ html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
34
+ html << '<ul class="pagination" style="margin: 0px;">'
35
+ li_style = 'style="vertical-align: middle;"'
36
+ 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>)
37
+ : %(<li class="prev disabled" #{li_style}><a href="#"><i class="material-icons">chevron_left</i></a></li>))
38
+ 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;">)
39
+ 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>)
40
+ 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>)
41
+ : %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
42
+ html << %(</ul></div><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
43
+ end
44
+
45
+ # Responsive pagination for Materialize: it returns the html with the series of links to the pages
46
+ # rendered by the Pagy.responsive javascript
47
+ def pagy_nav_responsive_materialize(pagy, id=caller(1,1)[0].hash)
48
+ tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
49
+
50
+ tags['before'] = +'<ul class="pagination">'
51
+ tags['before'] << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
52
+ : %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
53
+ responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
54
+ tags[item.to_s] = if item.is_a?(Integer); %(<li class="waves-effect">#{link.call item}</li>) # page link
55
+ elsif item.is_a?(String) ; %(<li class="active">#{link.call item}</li>) # active page
56
+ elsif item == :gap ; %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
57
+ end
58
+ end
59
+ tags['after'] = +(p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
60
+ : %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
61
+ tags['after'] << '</ul>'
62
+ script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
63
+ %(<div id="pagy-nav-#{id}" class="pagy-nav-responsive-materialize pagination" role="navigation" aria-label="pager"></div>#{script})
64
+ end
65
+
24
66
  end
25
67
  end
@@ -0,0 +1,46 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
2
+ # frozen_string_literal: true
3
+
4
+ require 'pagy/extras/shared'
5
+
6
+ class Pagy
7
+ module Frontend
8
+
9
+ # Generic compact pagination: it returns the html with the series of links to the pages
10
+ # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
11
+ def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
12
+ html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
13
+
14
+ html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
15
+ html << link.call(MARKER, '', %(style="display: none;" ))
16
+ (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
17
+ html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
18
+ : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
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;">)
20
+ 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> )
21
+ html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
22
+ : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
23
+ html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
24
+ end
25
+
26
+ # Generic responsive pagination: it returns the html with the series of links to the pages
27
+ # rendered by the Pagy.responsive javascript
28
+ def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
29
+ tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
30
+
31
+ tags['before'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
32
+ : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
33
+ responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
34
+ tags[item.to_s] = if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
35
+ elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
36
+ elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
37
+ end
38
+ end
39
+ tags['after'] = (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
40
+ : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
41
+ script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
42
+ %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ class Pagy
6
+
7
+ # Default :breakpoints
8
+ VARS[:breakpoints] = { 0 => [1,4,4,1] }
9
+
10
+ # Helper for building the page_nav with javascript. For example:
11
+ # with an object like:
12
+ # Pagy.new count:1000, page: 20, breakpoints: {0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3]}
13
+ # it returns something like:
14
+ # { :items => [1, :gap, 18, 19, "20", 21, 22, 50, 2, 17, 23, 49, 3, 16, 24, 48],
15
+ # :series => { 0 =>[1, :gap, 18, 19, "20", 21, 22, :gap, 50],
16
+ # 350 =>[1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
17
+ # 550 =>[1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] },
18
+ # :widths => [550, 350, 0] }
19
+ # where :items is the unordered array union of all the page numbers for all sizes (passed to the PagyResponsive javascript function)
20
+ # :series is the hash of the series keyed by width (used by the *_responsive helpers to create the JSON string)
21
+ # :widths is the desc-ordered array of widths (passed to the PagyResponsive javascript function)
22
+ def responsive
23
+ @responsive ||= {items: [], series: {}, widths:[]}.tap do |r|
24
+ @vars[:breakpoints].key?(0) || raise(ArgumentError, "expected :breakpoints to contain the 0 size; got #{@vars[:breakpoints].inspect}")
25
+ @vars[:breakpoints].each {|width, size| r[:items] |= r[:series][width] = series(size)}
26
+ r[:widths] = r[:series].keys.sort!{|a,b| b <=> a}
27
+ end
28
+ end
29
+
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.17.0
4
+ version: 0.18.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-08-18 00:00:00.000000000 Z
11
+ date: 2018-08-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,
@@ -21,6 +21,8 @@ extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
23
  - LICENSE.txt
24
+ - lib/config/pagy.rb
25
+ - lib/javascripts/pagy.js
24
26
  - lib/locales/pagy.yml
25
27
  - lib/locales/plurals.rb
26
28
  - lib/pagy.rb
@@ -28,30 +30,28 @@ files:
28
30
  - lib/pagy/extras/array.rb
29
31
  - lib/pagy/extras/bootstrap.rb
30
32
  - lib/pagy/extras/bulma.rb
31
- - lib/pagy/extras/compact.rb
32
33
  - lib/pagy/extras/foundation.rb
33
34
  - lib/pagy/extras/i18n.rb
34
- - lib/pagy/extras/initializer_example.rb
35
35
  - lib/pagy/extras/items.rb
36
- - lib/pagy/extras/javascripts/pagy.js
37
36
  - lib/pagy/extras/materialize.rb
37
+ - lib/pagy/extras/navs.rb
38
38
  - lib/pagy/extras/out_of_range.rb
39
- - lib/pagy/extras/responsive.rb
40
39
  - lib/pagy/extras/searchkick.rb
41
- - lib/pagy/extras/templates/nav.html.erb
42
- - lib/pagy/extras/templates/nav.html.haml
43
- - lib/pagy/extras/templates/nav.html.slim
44
- - lib/pagy/extras/templates/nav_bootstrap.html.erb
45
- - lib/pagy/extras/templates/nav_bootstrap.html.haml
46
- - lib/pagy/extras/templates/nav_bootstrap.html.slim
47
- - lib/pagy/extras/templates/nav_bulma.html.erb
48
- - lib/pagy/extras/templates/nav_bulma.html.haml
49
- - lib/pagy/extras/templates/nav_bulma.html.slim
50
- - lib/pagy/extras/templates/nav_foundation.html.erb
51
- - lib/pagy/extras/templates/nav_foundation.html.haml
52
- - lib/pagy/extras/templates/nav_foundation.html.slim
40
+ - lib/pagy/extras/shared.rb
53
41
  - lib/pagy/extras/trim.rb
54
42
  - lib/pagy/frontend.rb
43
+ - lib/templates/nav.html.erb
44
+ - lib/templates/nav.html.haml
45
+ - lib/templates/nav.html.slim
46
+ - lib/templates/nav_bootstrap.html.erb
47
+ - lib/templates/nav_bootstrap.html.haml
48
+ - lib/templates/nav_bootstrap.html.slim
49
+ - lib/templates/nav_bulma.html.erb
50
+ - lib/templates/nav_bulma.html.haml
51
+ - lib/templates/nav_bulma.html.slim
52
+ - lib/templates/nav_foundation.html.erb
53
+ - lib/templates/nav_foundation.html.haml
54
+ - lib/templates/nav_foundation.html.slim
55
55
  - pagy.gemspec
56
56
  homepage: https://github.com/ddnexus/pagy
57
57
  licenses:
@@ -1,100 +0,0 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/compact
2
- # frozen_string_literal: true
3
-
4
- class Pagy
5
- # Add nav helpers for compact pagination
6
- module Frontend
7
-
8
- # Generic compact pagination: it returns the html with the series of links to the pages
9
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
10
- def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
11
- html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
12
-
13
- html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact pagination" role="navigation" aria-label="pager">)
14
- html << link.call(MARKER, '', %(style="display: none;" ))
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> )
17
- : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
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;">)
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> )
20
- html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
21
- : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
22
- html << %(</nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
23
- end
24
-
25
- # Compact pagination for bootstrap: it returns the html with the series of links to the pages
26
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
27
- def pagy_nav_compact_bootstrap(pagy, id=caller(1,1)[0].hash)
28
- html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
29
-
30
- html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bootstrap pagination" role="navigation" aria-label="pager">)
31
- html << link.call(MARKER, '', %(style="display: none;" ))
32
- (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
33
- html << %(<div class="btn-group" role="group">)
34
- html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
35
- : %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
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;">)
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>)
38
- html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
39
- : %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
40
- html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
41
- end
42
-
43
- # Compact pagination for Bulma: it returns the html with the series of links to the pages
44
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
45
- def pagy_nav_compact_bulma(pagy, id=caller(1,1)[0].hash)
46
- html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
47
-
48
- html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-bulma" role="navigation" aria-label="pagination">)
49
- html << link.call(MARKER, '', 'style="display: none;"')
50
- (html << link.call(1, '', %(style="display: none;"))) if defined?(TRIM)
51
- html << %(<div class="field is-grouped is-grouped-centered" role="group">)
52
- html << (p_prev ? %(<p class="control">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}</p>)
53
- : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.prev')}</a></p>))
54
- input = %(<input class="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;">)
55
- html << %(<div class="pagy-compact-input control level is-mobile">#{pagy_t('pagy.compact.page')}&nbsp;#{input}&nbsp;#{pagy_t('pagy.compact.of')} #{p_pages}</div>)
56
- html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
57
- : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
58
- html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
59
- end
60
-
61
- # Compact pagination for foundation: it returns the html with the series of links to the pages
62
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
63
- def pagy_nav_compact_foundation(pagy, id=caller(1,1)[0].hash)
64
- html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
65
-
66
- html << %(<nav id="pagy-nav-#{id}" class="pagy-nav-compact-foundation" role="navigation" aria-label="Pagination">)
67
- html << link.call(MARKER, '', %(style="display: none;" ))
68
- (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
69
- html << %(<div class="input-group">)
70
- html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"')
71
- : %(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
72
- input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1.5}rem;">)
73
- html << %(<span class="input-group-label">#{pagy_t('pagy.compact.page')}</span> #{input} <span class="input-group-label">#{pagy_t('pagy.compact.of')} #{p_pages}</span>)
74
- html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
75
- : %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
76
- html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
77
- end
78
-
79
- # Compact pagination for materialize: it returns the html with the series of links to the pages
80
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
81
- def pagy_nav_compact_materialize(pagy, id=caller(1,1)[0].hash)
82
- html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
83
-
84
- html << %(<div id="pagy-nav-#{id}" class="pagy-nav-compact-materialize pagination" role="navigation" aria-label="pager">)
85
- html << link.call(MARKER, '', %(style="display: none;" ))
86
- (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
87
- html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
88
- html << '<ul class="pagination" style="margin: 0px;">'
89
- li_style = 'style="vertical-align: middle;"'
90
- 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>)
91
- : %(<li class="prev disabled" #{li_style}><a href="#"><i class="material-icons">chevron_left</i></a></li>))
92
- 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;">)
93
- 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>)
94
- 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>)
95
- : %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
96
- html << %(</ul></div><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
97
- end
98
-
99
- end
100
- end
@@ -1,138 +0,0 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/responsive
2
- # frozen_string_literal: true
3
-
4
- require 'json'
5
-
6
- class Pagy
7
-
8
- # Default :breakpoints
9
- VARS[:breakpoints] = { 0 => [1,4,4,1] }
10
-
11
- # Helper for building the page_nav with javascript. For example:
12
- # with an object like:
13
- # Pagy.new count:1000, page: 20, breakpoints: {0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3]}
14
- # it returns something like:
15
- # { :items => [1, :gap, 18, 19, "20", 21, 22, 50, 2, 17, 23, 49, 3, 16, 24, 48],
16
- # :series => { 0 =>[1, :gap, 18, 19, "20", 21, 22, :gap, 50],
17
- # 350 =>[1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
18
- # 550 =>[1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] },
19
- # :widths => [550, 350, 0] }
20
- # where :items is the unordered array union of all the page numbers for all sizes (passed to the PagyResponsive javascript function)
21
- # :series is the hash of the series keyed by width (used by the *_responsive helpers to create the JSON string)
22
- # :widths is the desc-ordered array of widths (passed to the PagyResponsive javascript function)
23
- def responsive
24
- @responsive ||= {items: [], series: {}, widths:[]}.tap do |r|
25
- @vars[:breakpoints].key?(0) || raise(ArgumentError, "expected :breakpoints to contain the 0 size; got #{@vars[:breakpoints].inspect}")
26
- @vars[:breakpoints].each {|width, size| r[:items] |= r[:series][width] = series(size)}
27
- r[:widths] = r[:series].keys.sort!{|a,b| b <=> a}
28
- end
29
- end
30
-
31
- # Add nav helpers for responsive pagination
32
- module Frontend
33
-
34
- # Generic responsive pagination: it returns the html with the series of links to the pages
35
- # rendered by the Pagy.responsive javascript
36
- def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash)
37
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
38
-
39
- tags['before'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
40
- : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
41
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
42
- tags[item.to_s] = if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
43
- elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
44
- elsif item == :gap ; %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ) # page gap
45
- end
46
- end
47
- tags['after'] = (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
48
- : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
49
- script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
50
- %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive pagination" role="navigation" aria-label="pager"></nav>#{script})
51
- end
52
-
53
- # Responsive pagination for bootstrap: it returns the html with the series of links to the pages
54
- # rendered by the Pagy.responsive javascript
55
- def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash)
56
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
57
-
58
- tags['before'] = +'<ul class="pagination">'
59
- tags['before'] << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
60
- : %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
61
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
62
- tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
63
- elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
64
- elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
65
- end
66
- end
67
- tags['after'] = +(p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
68
- : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
69
- tags['after'] << '</ul>'
70
- script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
71
- %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-bootstrap pagination" role="navigation" aria-label="pager"></nav>#{script})
72
- end
73
-
74
- # Responsive pagination for Bulma: it returns the html with the series of links to the pages
75
- # rendered by the Pagy.responsive javascript
76
- def pagy_nav_responsive_bulma(pagy, id=caller(1,1)[0].hash)
77
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
78
-
79
- tags['before'] = +(p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
80
- : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>))
81
- tags['before'] << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
82
- : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
83
- tags['before'] << '<ul class="pagination-list">'
84
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
85
- tags[item.to_s] = if item.is_a?(Integer); %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}")}</li>)
86
- elsif item.is_a?(String) ; %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-current="page" aria-label="page #{item}")}</li>)
87
- elsif item == :gap ; %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>)
88
- end
89
- end
90
- tags['after'] = '</ul>'
91
- script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
92
- %(<nav id="pagy-nav-#{id}" class="pagy-nav-bulma pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
93
- end
94
-
95
- # Responsive pagination for Foundation: it returns the html with the series of links to the pages
96
- # rendered by the Pagy.responsive javascript
97
- def pagy_nav_responsive_foundation(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="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
102
- : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</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>#{link.call item}</li>) # page link
105
- elsif item.is_a?(String) ; %(<li class="current"><span class="show-for-sr">#{pagy_t('pagy.nav.current')}</span> #{item}</li>) # active page
106
- elsif item == :gap ; %(<li class="gap disabled">#{pagy_t('pagy.nav.gap')}</li>) # page gap
107
- end
108
- end
109
- tags['after'] = +(p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
110
- : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</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
- %(<nav id="pagy-nav-#{id}" class="pagy-nav-responsive-foundation" aria-label="Pagination"></nav>#{script})
114
- end
115
-
116
- # Responsive pagination for Materialize: it returns the html with the series of links to the pages
117
- # rendered by the Pagy.responsive javascript
118
- def pagy_nav_responsive_materialize(pagy, id=caller(1,1)[0].hash)
119
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
120
-
121
- tags['before'] = +'<ul class="pagination">'
122
- tags['before'] << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
123
- : %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
124
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
125
- tags[item.to_s] = if item.is_a?(Integer); %(<li class="waves-effect">#{link.call item}</li>) # page link
126
- elsif item.is_a?(String) ; %(<li class="active">#{link.call item}</li>) # active page
127
- elsif item == :gap ; %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
128
- end
129
- end
130
- tags['after'] = +(p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
131
- : %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
132
- tags['after'] << '</ul>'
133
- script = %(<script type="application/json" class="pagy-responsive-json">["#{id}", #{tags.to_json}, #{responsive[:widths].to_json}, #{responsive[:series].to_json}]</script>)
134
- %(<div id="pagy-nav-#{id}" class="pagy-nav-responsive-materialize pagination" role="navigation" aria-label="pager"></div>#{script})
135
- end
136
-
137
- end
138
- end