pagy 0.16.0 → 0.17.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: da9304305299f0be41d53a9d6f13619fd5c625fafe1719b7d2606dc4d41689c2
4
- data.tar.gz: 860fd52099ad641fc92ae5a0a1139a2eb93e041aa314071916f80b968dcb27fd
3
+ metadata.gz: 6c29e24c7c57ca390d1d7b1418a29db73e6b60449dd0149147247ddbd9e9468c
4
+ data.tar.gz: 5971ae0908e0b570f3288036f94fb2039c5286de5bfae23a99412c5c9a7854bc
5
5
  SHA512:
6
- metadata.gz: 1092d3a3c662c9e88ceafd7a5062ca157b1115129878bdb8751de0609422360d07607eb60d4b277a2c18b1253acaf6d39552d314fdd0b679326b445874af00a6
7
- data.tar.gz: 2ade9847094373264920036d0ce2fa9eaebcc7d912115f6614799a3f5b078d3b32317db627e2ec23c8dee8df119cc6c976dce1371781e16b1631aac7798b543e
6
+ metadata.gz: 48390fcfb1c9a03ecf3f5c722c016545af0ab107aebf3f380704535319f46b330caa81fd2347428dd1f87dacf9b2e4e0ca40a61ed32f66d290a92b00cbd8ac8f
7
+ data.tar.gz: 7c39db7c431d6072267128bb0c7af080b63bb0ae32aab803c7c5aff2fd269660b70611eb256a74228e97c9a7bc2cc5cb59182522386f1195c8bf974f625bfcaf
data/lib/locales/pagy.yml CHANGED
@@ -6,6 +6,7 @@ en:
6
6
  prev: "‹ Prev"
7
7
  next: "Next ›"
8
8
  gap: "…"
9
+ current: "You're on page"
9
10
  info:
10
11
  single_page:
11
12
  zero: "No %{item_name} found"
data/lib/pagy.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'pathname'
5
5
 
6
- class Pagy ; VERSION = '0.16.0'
6
+ class Pagy ; VERSION = '0.17.0'
7
7
 
8
8
  class OutOfRangeError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
9
9
 
@@ -58,6 +58,24 @@ class Pagy
58
58
  html << %(</div></nav><script type="application/json" class="pagy-compact-json">["#{id}", "#{MARKER}", "#{p_page}", #{!!defined?(TRIM)}]</script>)
59
59
  end
60
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
+
61
79
  # Compact pagination for materialize: it returns the html with the series of links to the pages
62
80
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
63
81
  def pagy_nav_compact_materialize(pagy, id=caller(1,1)[0].hash)
@@ -0,0 +1,26 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation
2
+ # frozen_string_literal: true
3
+
4
+ class Pagy
5
+ # Add nav helper for foundation pagination
6
+ module Frontend
7
+
8
+ # Pagination for foundation: it returns the html with the series of links to the pages
9
+ def pagy_nav_foundation(pagy)
10
+ html, link, p_prev, p_next = +'', pagy_link_proc(pagy), pagy.prev, pagy.next
11
+
12
+ html << (p_prev ? %(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
13
+ : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>))
14
+ pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
15
+ html << if item.is_a?(Integer); %(<li>#{link.call item}</li>) # page link
16
+ elsif item.is_a?(String) ; %(<li class="current"><span class="show-for-sr">#{pagy_t('pagy.nav.current')}</span> #{item}</li>) # active page
17
+ elsif item == :gap ; %(<li class="ellipsis" aria-hidden="true"></li>) # page gap
18
+ end
19
+ end
20
+ html << (p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
21
+ : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
22
+ %(<nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
23
+ end
24
+
25
+ end
26
+ end
@@ -5,10 +5,33 @@
5
5
  # Extras
6
6
  # See https://ddnexus.github.io/pagy/extras
7
7
 
8
- # Array: Paginate arrays efficiently avoiding expensive array-wrapping and without overriding
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
+ # Backend Extras
23
+
24
+ # Array: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
9
25
  # See https://ddnexus.github.io/pagy/extras/array
10
26
  # require 'pagy/extras/array'
11
27
 
28
+ # Searchkick: Paginate `Searchkick::Results` objects efficiently, avoiding expensive oject-wrapping and without overriding.
29
+ # See https://ddnexus.github.io/pagy/extras/searchkick
30
+ # require 'pagy/extras/searchkick'
31
+
32
+
33
+ # Frontend Extras
34
+
12
35
  # Bootstrap: Nav helper and templates for Bootstrap pagination
13
36
  # See https://ddnexus.github.io/pagy/extras/bootstrap
14
37
  # require 'pagy/extras/bootstrap'
@@ -17,9 +40,16 @@
17
40
  # See https://ddnexus.github.io/pagy/extras/bulma
18
41
  # require 'pagy/extras/bulma'
19
42
 
20
- # Compact: An alternative UI that combines the pagination with the nav info in one compact element
21
- # See https://ddnexus.github.io/pagy/extras/compact
22
- # require 'pagy/extras/compact'
43
+ # Foundation: Nav helper and templates for Foundation pagination
44
+ # See https://ddnexus.github.io/pagy/extras/foundation
45
+ # require 'pagy/extras/foundation'
46
+
47
+ # Materialize: Nav helper for Materialize pagination
48
+ # See https://ddnexus.github.io/pagy/extras/materialize
49
+ # require 'pagy/extras/materialize'
50
+
51
+
52
+ # Feature Extras
23
53
 
24
54
  # Items: Allow the client to request a custom number of items per page with a ready to use selector UI
25
55
  # See https://ddnexus.github.io/pagy/extras/items
@@ -27,38 +57,27 @@
27
57
  # Pagy::VARS[:items_param] = :items # default
28
58
  # Pagy::VARS[:max_items] = 100 # default
29
59
 
30
- # Materialize: Nav helper for Materialize pagination
31
- # See https://ddnexus.github.io/pagy/extras/materialize
32
- # require 'pagy/extras/materialize'
33
-
34
60
  # Out Of Range: Allow for easy handling of out of range pages
35
61
  # See https://ddnexus.github.io/pagy/extras/out_of_range
36
62
  # Pagy::VARS[:out_of_range_mode] = :last_page # default (other options: :empty_page and :exception)
37
63
 
38
- # Responsive: On resize, the number of page links will adapt in real-time to the available window/container width
39
- # See https://ddnexus.github.io/pagy/extras/responsive
40
- # require 'pagy/extras/responsive'
41
- # See https://ddnexus.github.io/pagy/extras/responsive#breakpoints
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
-
44
- # Searchkick: Paginate `Searchkick::Results` objects efficiently avoiding expensive oject-wrapping and without overriding.
45
- # See https://ddnexus.github.io/pagy/extras/searchkick
46
- # require 'pagy/extras/searchkick'
47
-
48
64
  # Trim: Remove the page=1 param from links
49
65
  # See https://ddnexus.github.io/pagy/extras/trim
50
66
  # require 'pagy/extras/trim'
51
67
 
52
68
 
69
+
53
70
  # Pagy Variables
54
71
  # See https://ddnexus.github.io/pagy/api/pagy#variables
55
72
  # All the Pagy::VARS are set for all the Pagy instances but can be overridden
56
73
  # per instance by just passing them to Pagy.new or the #pagy controller method
57
74
 
75
+
58
76
  # Instance variables
59
77
  # See https://ddnexus.github.io/pagy/api/pagy#instance-variables
60
78
  # Pagy::VARS[:items] = 20 # default
61
79
 
80
+
62
81
  # Other Variables
63
82
  # See https://ddnexus.github.io/pagy/api/pagy#other-variables
64
83
  # Pagy::VARS[:size] = [1,4,4,1] # default
@@ -69,11 +88,15 @@
69
88
  # Pagy::VARS[:item_path] = 'activerecord.models.product' # example
70
89
 
71
90
 
91
+ # Rails
92
+
72
93
  # Rails: extras assets path required by compact, items and responsive extras
73
94
  # See https://ddnexus.github.io/pagy/extras
74
95
  # Rails.application.config.assets.paths << Pagy.root.join('pagy', 'extras', 'javascripts')
75
96
 
76
97
 
98
+ # I18n
99
+
77
100
  # I18n: faster internal pagy implementation (does not use the I18n gem)
78
101
  # Use only for single language apps that don't need dynamic translation between multiple languages
79
102
  # See https://ddnexus.github.io/pagy/api/frontend#i18n
@@ -57,7 +57,7 @@ class Pagy
57
57
 
58
58
  tags['before'] = +'<ul class="pagination">'
59
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>))
60
+ : %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
61
61
  responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
62
62
  tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
63
63
  elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
@@ -92,6 +92,27 @@ 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 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
+
95
116
  # Responsive pagination for Materialize: it returns the html with the series of links to the pages
96
117
  # rendered by the Pagy.responsive javascript
97
118
  def pagy_nav_responsive_materialize(pagy, id=caller(1,1)[0].hash)
@@ -0,0 +1,24 @@
1
+ <%#
2
+ This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t
3
+ calls with the actual strings ("&lsaquo; Prev", "Next &rsaquo;", "&hellip;").
4
+
5
+ The link variable is set to a proc that returns the link tag.
6
+ Usage: link.call( page_number [, text [, extra_attributes_string ]])
7
+ -%>
8
+ <% link = pagy_link_proc(pagy) -%>
9
+ <%# -%><nav class="pagy-nav-foundation" role="navigation" aria-label="Pagination">
10
+ <%# -%> <ul class="pagination">
11
+ <% if pagy.prev -%> <li class="prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
12
+ <% else -%> <li class="prev disabled"><%== pagy_t('pagy.nav.prev') %></li>
13
+ <% end -%>
14
+ <% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%>
15
+ <% if item.is_a?(Integer) -%> <li><%== link.call(item) %></li>
16
+ <% elsif item.is_a?(String) -%> <li class="current"><span class="show-for-sr"><%== pagy_t('pagy.nav.current')%></span> <%= item %></li>
17
+ <% elsif item == :gap -%> <li class="disabled gap"><%== pagy_t('pagy.nav.gap') %></li>
18
+ <% end -%>
19
+ <% end -%>
20
+ <% if pagy.next -%> <li class="next"><%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') %></li>
21
+ <% else -%> <li class="next disabled"><%== pagy_t('pagy.nav.next') %></li>
22
+ <% end -%>
23
+ <%# -%> </ul>
24
+ <%# -%></nav>
@@ -0,0 +1,37 @@
1
+ -# This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t
2
+ -# calls with the actual strings ("&lsaquo; Prev", "Next &rsaquo;", "&hellip;").
3
+
4
+ -# The link variable is set to a proc that returns the link tag.
5
+ -# Usage: link.call( page_number [, text [, extra_attributes_string ]])
6
+
7
+ - link = pagy_link_proc(pagy)
8
+
9
+ %nav.pagy-nav-foundation{"role" => "navigation", "aria-label" => "Pagination"}
10
+
11
+ %ul.pagination
12
+
13
+ - if pagy.prev
14
+ %li.prev!= link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"')
15
+ - else
16
+ %li.prev.disabled
17
+ != pagy_t('pagy.nav.prev')
18
+
19
+ - pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
+ - if item.is_a?(Integer) # page link
21
+ %li!= link.call(item)
22
+
23
+ - elsif item.is_a?(String) # current page
24
+ %li.current
25
+ %span.show-for-sr
26
+ != pagy_t('pagy.nav.current')
27
+ != item
28
+
29
+ - elsif item == :gap # page gap
30
+ %li.disabled.gap
31
+ != pagy_t('pagy.nav.gap')
32
+
33
+ - if pagy.next
34
+ %li.next!= link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"')
35
+ - else
36
+ %li.next.disabled
37
+ != pagy_t('pagy.nav.next')
@@ -0,0 +1,37 @@
1
+ / This template is i18n-ready: if you don't use i18n, then you can replace the pagy_t
2
+ / calls with the actual strings ("&lsaquo; Prev", "Next &rsaquo;", "&hellip;").
3
+
4
+ / The link variable is set to a proc that returns the link tag.
5
+ / Usage: link.call( page_number [, text [, extra_attributes_string ]])
6
+
7
+ - link = pagy_link_proc(pagy)
8
+
9
+ nav.pagy-nav-foundation role="navigation" aria-label="Pagination"
10
+
11
+ ul.pagination
12
+
13
+ - if pagy.prev
14
+ li.prev == link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"')
15
+ - else
16
+ li.prev.disabled
17
+ == pagy_t('pagy.nav.prev')
18
+
19
+ - pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
+ - if item.is_a?(Integer) # page link
21
+ li == link.call(item)
22
+
23
+ - elsif item.is_a?(String) # current page
24
+ li.current
25
+ span.show-for-sr
26
+ == pagy_t('pagy.nav.current')
27
+ = item
28
+
29
+ - elsif item == :gap # page gap
30
+ li.disabled.gap
31
+ == pagy_t('pagy.nav.gap')
32
+
33
+ - if pagy.next
34
+ li.next == link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"')
35
+ - else
36
+ li.next.disabled
37
+ == pagy_t('pagy.nav.next')
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.16.0
4
+ version: 0.17.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-05 00:00:00.000000000 Z
11
+ date: 2018-08-18 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,
@@ -29,6 +29,7 @@ files:
29
29
  - lib/pagy/extras/bootstrap.rb
30
30
  - lib/pagy/extras/bulma.rb
31
31
  - lib/pagy/extras/compact.rb
32
+ - lib/pagy/extras/foundation.rb
32
33
  - lib/pagy/extras/i18n.rb
33
34
  - lib/pagy/extras/initializer_example.rb
34
35
  - lib/pagy/extras/items.rb
@@ -46,6 +47,9 @@ files:
46
47
  - lib/pagy/extras/templates/nav_bulma.html.erb
47
48
  - lib/pagy/extras/templates/nav_bulma.html.haml
48
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
49
53
  - lib/pagy/extras/trim.rb
50
54
  - lib/pagy/frontend.rb
51
55
  - pagy.gemspec