pagy 1.2.1 → 1.3

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: 404671150cf9cb3580df7ec51a52715dbec0ea879140f16b0f41d67714a9760e
4
- data.tar.gz: 9074cfed85d9465b2484222b6063e3b282e4c910fc01388bd5155ce4348181e3
3
+ metadata.gz: b17506ef8c1eb28b4d309d528129738e50df21e8133a5a5b93b513770bd166df
4
+ data.tar.gz: 2083ac8f294973bb99fa458bb97ca70894b07299bf430ccb0e30739a08b72b98
5
5
  SHA512:
6
- metadata.gz: bbba1646133377c9dc118fdb184d694dd5b137d780cdd55009f61b7190f276e737e46cf0dd0ebd63957b4f8fb7a67cbc1ed409c0ac3a0055ab6a58db0eadece6
7
- data.tar.gz: e7ef0461dc55852c9f6d1baa594cb495256d7cefdd6a230c36b139fcf9adfc16684d4e9b3e65a075c93891a2f315912c1e3f33e3c6bef5d909aa5f21f77e7303
6
+ metadata.gz: 23b98cd8d721407c821f32305c8acff47ced168eead12030fa54b5547323a444afb524e834e4ab2417aaebac593e832e6fd93df64045164b6f31d90aa2a0fd8e
7
+ data.tar.gz: 1d66cffcb0396a788db7f2fbf2818e7d440e3f6530bb8e50262d07b888e5ad1be5cc717e3f97da0750172c27248bfd33b465452e20331e241b4fb57617cf135b
@@ -1,8 +1,9 @@
1
1
  // See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
2
2
 
3
+ // Pagy namespace
3
4
  function Pagy(){}
4
5
 
5
- Pagy.windowListeners = [];
6
+ Pagy.windowListeners = {};
6
7
 
7
8
  Pagy.addInputEventListeners = function(input, handler){
8
9
  // select the content on click: easier for typing a number
@@ -49,33 +50,37 @@ Pagy.items = function(id, marker, from){
49
50
  };
50
51
 
51
52
  Pagy.responsive = function(id, tags, widths, series){
52
- var pagyEl = document.getElementById(id),
53
- pagyParent = pagyEl.parentElement,
54
- lastWidth = undefined,
55
- render = function(){
56
- var parentWidth = parseInt(pagyParent.clientWidth),
57
- width = widths.find(function(w){return parentWidth > w});
58
- if (width !== lastWidth) {
59
- while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
60
- var html = tags['before'];
61
- series[width].forEach(function(item){html += tags[item]});
62
- html += tags['after'];
63
- pagyEl.insertAdjacentHTML('beforeend', html);
64
- lastWidth = width;
65
- }
66
- }.bind(this);
67
- window.addEventListener('resize', render, true);
68
- Pagy.windowListeners.push(render);
53
+ var pagyEl = document.getElementById(id),
54
+ container = pagyEl.parentElement,
55
+ lastWidth = undefined,
56
+ resizeId = 0,
57
+ render = function(){
58
+ var width = widths.find(function(w) {return container.clientWidth > w});
59
+ if (width !== lastWidth) {
60
+ while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
61
+ var html = tags['before'];
62
+ series[width].forEach(function(item) {html += tags[item]});
63
+ html += tags['after'];
64
+ pagyEl.insertAdjacentHTML('beforeend', html);
65
+ lastWidth = width;
66
+ }
67
+ },
68
+ resize = function(){ // call render once, after window.resize is done
69
+ clearTimeout(resizeId);
70
+ resizeId = setTimeout(render, 300);
71
+ };
72
+ // remove the previous window resize listener which may result in firing the render multiple times
73
+ window.removeEventListener('resize', Pagy.windowListeners[id], true);
74
+ window.addEventListener('resize', resize, true);
75
+ Pagy.windowListeners[id] = resize;
69
76
  render();
70
77
  };
71
78
 
72
- Pagy.init = function(){
73
- // we need to explicitly remove the window listeners because turbolinks persists the window object
74
- Pagy.windowListeners.forEach(function(l){window.removeEventListener('resize', l, true)});
75
- Pagy.windowListeners = [];
76
- var json = document.getElementsByClassName('pagy-json');
77
- for (var i = 0, len = json.length; i < len; i++) {
78
- var args = JSON.parse(json[i].innerHTML);
79
+ Pagy.init = function(arg){
80
+ var target = arg instanceof Event || arg === undefined ? document : arg,
81
+ jsonTags = target.getElementsByClassName('pagy-json');
82
+ for (var i = 0, len = jsonTags.length; i < len; i++) {
83
+ var args = JSON.parse(jsonTags[i].innerHTML);
79
84
  Pagy[args.shift()].apply(null, args);
80
85
  }
81
86
  // Support for legacy overridden helpers. It will be removed in 2.0
@@ -87,6 +92,7 @@ Pagy.init = function(){
87
92
  })
88
93
  };
89
94
 
95
+ // namespace for custom init functions
90
96
  function PagyInit(){}
91
97
 
92
98
  Pagy.applyInit = function(name, payload){ PagyInit[name].apply(null, [payload]) };
@@ -0,0 +1,15 @@
1
+ # Pagy locales
2
+
3
+ ### Please, submit your translation!
4
+
5
+ If you are using pagy with some language missing from the dictionary files, please, submit your translation!
6
+
7
+ The `pagy.info.single_page`, `pagy.info.item_name` and `pagy.items` keys of the yaml file are pluralized according to the plural rules of the language.
8
+
9
+ If you are going to submit a dictionary, please check wether the pluralization type of your language exists in the [plurals.rb](https://github.com/ddnexus/pagy/blob/master/lib/locales/plurals.rb) file. If it is missing, please, report it. Thanks.
10
+
11
+ ### Useful Links
12
+
13
+ * [Pagy I18n Documentation](https://ddnexus.github.io/pagy/api/frontend#i18n)
14
+ * [i18n extra](https://ddnexus.github.io/pagy/extra/i18n)
15
+
@@ -0,0 +1,20 @@
1
+ nl:
2
+ pagy:
3
+ nav:
4
+ prev: "&lsaquo;&nbsp;Vorige"
5
+ next: "Volgende&nbsp;&rsaquo;"
6
+ gap: "&hellip;"
7
+ info:
8
+ single_page:
9
+ zero: "Geen %{item_name} gevonden"
10
+ one: "Toont <b>1</b> %{item_name}"
11
+ other: "Toont <b>alle %{count}</b> %{item_name}"
12
+ multiple_pages: "Toont <b>%{from}-%{to}</b> %{item_name} van <b>%{count}</b> in totaal"
13
+ item_name:
14
+ zero: "stuks"
15
+ one: "stuk"
16
+ other: "stuks"
17
+ compact: "Pagina %{page_input} van %{pages}"
18
+ items:
19
+ one: "Toont %{items_input} item per pagina"
20
+ other: "Toont %{items_input} items per pagina"
@@ -3,24 +3,36 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  # utility variables
6
- zero_one = ['zero', 'one']
7
- from2to4 = (2..4)
8
- from5to9 = (5..9)
9
- from11to14 = (11..14)
10
- from12to14 = (12..14)
6
+ zero_one = ['zero', 'one'].freeze
7
+ from2to4 = (2..4).freeze
8
+ from5to9 = (5..9).freeze
9
+ from11to14 = (11..14).freeze
10
+ from12to14 = (12..14).freeze
11
11
 
12
12
  # Plurals
13
13
  # A plural proc returns a plural type string based on the passed count
14
14
  # Each plural proc may apply to one or more languages below
15
15
  plurals = {
16
- zero_one_other: -> (count) {zero_one[count] || 'other'},
17
- one_few_many_other: -> (count) do
16
+ zero_one_other: -> (count) {zero_one[count] || 'other'},
17
+
18
+ zero_one_few_many_other: -> (count) do
18
19
  mod10, mod100 = count % 10, count % 100
19
- if mod10 == 1 && mod100 != 11 ; 'one'
20
+ if count == 0 ; 'zero'
21
+ elsif mod10 == 1 && mod100 != 11 ; 'one'
20
22
  elsif from2to4.cover?(mod10) && !from12to14.cover?(mod100) ; 'few'
21
23
  elsif mod10 == 0 || from5to9.cover?(mod10) || from11to14.cover?(mod100) ; 'many'
22
24
  else 'other'
23
25
  end
26
+ end,
27
+
28
+ pl: -> (count) do
29
+ mod10, mod100 = count % 10, count % 100
30
+ if count == 0 ; 'zero'
31
+ elsif count == 1 ; 'one'
32
+ elsif from2to4.cover?(mod10) && !from12to14.cover?(mod100) ; 'few'
33
+ elsif [0, 1].include?(mod10) || from5to9.cover?(mod10) || from12to14.cover?(mod100) ; 'many'
34
+ else 'other'
35
+ end
24
36
  end
25
37
  }
26
38
 
@@ -30,7 +42,8 @@ plurals = {
30
42
  # is the :zero_one_other plural (used for English)
31
43
  Hash.new(plurals[:zero_one_other]).tap do |languages|
32
44
  languages['en'] = plurals[:zero_one_other]
33
- languages['ru'] = plurals[:one_few_many_other]
45
+ languages['ru'] = plurals[:zero_one_few_many_other]
46
+ languages['pl'] = plurals[:pl]
34
47
  end
35
48
 
36
49
  # PR for other languages and plurals are very welcome. Thanks!
data/lib/pagy.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'pathname'
5
5
 
6
- class Pagy ; VERSION = '1.2.1'
6
+ class Pagy ; VERSION = '1.3'
7
7
 
8
8
  class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
9
9
 
@@ -14,16 +14,15 @@ class Pagy
14
14
  @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
15
15
  end
16
16
 
17
- # Finalize the instance variables based on the retrieved items
18
- def finalize(items)
19
- items == 0 && @page > 1 and raise(OverflowError.new(self), "page #{@page} got no items")
20
- @pages = @last = (items > @items ? @page + 1 : @page) # set the @pages and @last
21
- @items = items if items < @items && items > 0 # adjust items for last non-empty page
22
- @from = items == 0 ? 0 : @offset+1 - @outset # page begins from item
23
- @to = items == 0 ? 0 : @offset + @items - @outset # page ends to item
24
- @prev = (@page-1 unless @page == 1) # nil if no prev page
25
- @next = (@page+1 unless @page == @last) # nil if no next page
26
- @next = (@page == @last ? (1 if @vars[:cycle]) : @page+1) # nil if no next page
17
+ # Finalize the instance variables based on the fetched items
18
+ def finalize(fetched)
19
+ fetched == 0 && @page > 1 and raise(OverflowError.new(self), "page #{@page} got no items")
20
+ @pages = @last = (fetched > @items ? @page + 1 : @page) # set the @pages and @last
21
+ @items = fetched if fetched < @items && fetched > 0 # adjust items for last non-empty page
22
+ @from = fetched == 0 ? 0 : @offset+1 - @outset # page begins from item
23
+ @to = fetched == 0 ? 0 : @offset + @items - @outset # page ends to item
24
+ @prev = (@page-1 unless @page == 1) # nil if no prev page
25
+ @next = @page == @last ? (1 if @vars[:cycle]) : @page+1 # nil if no next page, 1 if :cycle
27
26
  self
28
27
  end
29
28
 
@@ -22,11 +22,11 @@ class Pagy
22
22
  : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
23
23
  %(<nav class="pagy-nav-bootstrap pagy-bootstrap-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
24
24
  end
25
- Pagy.deprecate self, :pagy_nav_bootstrap, :pagy_bootstrap_nav
25
+ deprecate :pagy_nav_bootstrap, :pagy_bootstrap_nav
26
26
 
27
27
  # Compact pagination for bootstrap: it returns the html with the series of links to the pages
28
28
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_bootstrap_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
29
+ def pagy_bootstrap_compact_nav(pagy, id=pagy_id)
30
30
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
31
31
 
32
32
  html << %(<nav id="#{id}" class="pagy-nav-compact-bootstrap pagy-bootstrap-compact-nav pagination" role="navigation" aria-label="pager">)
@@ -41,11 +41,11 @@ class Pagy
41
41
  : %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
42
42
  html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
43
43
  end
44
- Pagy.deprecate self, :pagy_nav_compact_bootstrap, :pagy_bootstrap_compact_nav
44
+ deprecate :pagy_nav_compact_bootstrap, :pagy_bootstrap_compact_nav
45
45
 
46
46
  # Responsive pagination for bootstrap: it returns the html with the series of links to the pages
47
47
  # rendered by the Pagy.responsive javascript
48
- def pagy_bootstrap_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
48
+ def pagy_bootstrap_responsive_nav(pagy, id=pagy_id)
49
49
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
50
50
 
51
51
  tags['before'] = +'<ul class="pagination">'
@@ -63,7 +63,7 @@ class Pagy
63
63
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
64
64
  %(<nav id="#{id}" class="pagy-nav-responsive-bootstrap pagy-bootstrap-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
65
65
  end
66
- Pagy.deprecate self, :pagy_nav_responsive_bootstrap, :pagy_bootstrap_responsive_nav
66
+ deprecate :pagy_nav_responsive_bootstrap, :pagy_bootstrap_responsive_nav
67
67
 
68
68
  end
69
69
  end
@@ -24,11 +24,11 @@ class Pagy
24
24
  html << '</ul>'
25
25
  %(<nav class="pagy-nav-bulma pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
26
26
  end
27
- Pagy.deprecate self, :pagy_nav_bulma, :pagy_bulma_nav
27
+ deprecate :pagy_nav_bulma, :pagy_bulma_nav
28
28
 
29
29
  # Compact pagination for Bulma: it returns the html with the series of links to the pages
30
30
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
31
- def pagy_bulma_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
31
+ def pagy_bulma_compact_nav(pagy, id=pagy_id)
32
32
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
33
33
 
34
34
  html << %(<nav id="#{id}" class="pagy-nav-compact-bulma pagy-bulma-compact-nav" role="navigation" aria-label="pagination">)
@@ -43,11 +43,11 @@ class Pagy
43
43
  : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
44
44
  html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
45
45
  end
46
- Pagy.deprecate self, :pagy_nav_compact_bulma, :pagy_bulma_compact_nav
46
+ deprecate :pagy_nav_compact_bulma, :pagy_bulma_compact_nav
47
47
 
48
48
  # Responsive pagination for Bulma: it returns the html with the series of links to the pages
49
49
  # rendered by the Pagy.responsive javascript
50
- def pagy_bulma_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
50
+ def pagy_bulma_responsive_nav(pagy, id=pagy_id)
51
51
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
52
52
 
53
53
  tags['before'] = +(p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
@@ -65,7 +65,7 @@ class Pagy
65
65
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
66
66
  %(<nav id="#{id}" class="pagy-nav-responsive-bulma pagy-bulma-responsive-nav pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
67
67
  end
68
- Pagy.deprecate self, :pagy_nav_responsive_bulma, :pagy_bulma_responsive_nav
68
+ deprecate :pagy_nav_responsive_bulma, :pagy_bulma_responsive_nav
69
69
 
70
70
  end
71
71
  end
@@ -22,11 +22,11 @@ class Pagy
22
22
  : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
23
23
  %(<nav class="pagy-nav-foundation pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
24
24
  end
25
- Pagy.deprecate self, :pagy_nav_foundation, :pagy_foundation_nav
25
+ deprecate :pagy_nav_foundation, :pagy_foundation_nav
26
26
 
27
27
  # Compact pagination for Foundation: it returns the html with the series of links to the pages
28
28
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_foundation_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
29
+ def pagy_foundation_compact_nav(pagy, id=pagy_id)
30
30
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
31
31
 
32
32
  html << %(<nav id="#{id}" class="pagy-nav-compact-foundation pagy-foundation-compact-nav" role="navigation" aria-label="Pagination">)
@@ -41,11 +41,11 @@ class Pagy
41
41
  : %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
42
42
  html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
43
43
  end
44
- Pagy.deprecate self, :pagy_nav_compact_foundation, :pagy_foundation_compact_nav
44
+ deprecate :pagy_nav_compact_foundation, :pagy_foundation_compact_nav
45
45
 
46
46
  # Responsive pagination for Foundation: it returns the html with the series of links to the pages
47
47
  # rendered by the Pagy.responsive javascript
48
- def pagy_foundation_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
48
+ def pagy_foundation_responsive_nav(pagy, id=pagy_id)
49
49
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
50
50
 
51
51
  tags['before'] = +'<ul class="pagination">'
@@ -63,7 +63,7 @@ class Pagy
63
63
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
64
64
  %(<nav id="#{id}" class="pagy-nav-responsive-foundation pagy-foundation-responsive-nav" aria-label="Pagination"></nav>#{script})
65
65
  end
66
- Pagy.deprecate self, :pagy_nav_responsive_foundation, :pagy_foundation_responsive_nav
66
+ deprecate :pagy_nav_responsive_foundation, :pagy_foundation_responsive_nav
67
67
 
68
68
  end
69
69
  end
@@ -46,7 +46,7 @@ class Pagy
46
46
  alias_method :pagy_url_for, :pagy_url_for_with_items
47
47
 
48
48
  # Return the items selector HTML. For example "Show [20] items per page"
49
- def pagy_items_selector(pagy, id=caller(1,1)[0].hash.to_s)
49
+ def pagy_items_selector(pagy, id=pagy_id)
50
50
  pagy = pagy.clone; p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
51
51
 
52
52
  html = +%(<span id="#{id}">)
@@ -21,11 +21,11 @@ class Pagy
21
21
  : %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
22
22
  %(<div class="pagy-nav-materialize pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
23
23
  end
24
- Pagy.deprecate self, :pagy_nav_materialize, :pagy_materialize_nav
24
+ deprecate :pagy_nav_materialize, :pagy_materialize_nav
25
25
 
26
26
  # Compact pagination for materialize: it returns the html with the series of links to the pages
27
27
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
28
- def pagy_materialize_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
28
+ def pagy_materialize_compact_nav(pagy, id=pagy_id)
29
29
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
30
30
 
31
31
  html << %(<div id="#{id}" class="pagy-nav-compact-materialize pagy-materialize-compact-nav pagination" role="navigation" aria-label="pager">)
@@ -42,11 +42,11 @@ class Pagy
42
42
  : %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
43
43
  html << %(</ul></div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
44
44
  end
45
- Pagy.deprecate self, :pagy_nav_compact_materialize, :pagy_materialize_compact_nav
45
+ deprecate :pagy_nav_compact_materialize, :pagy_materialize_compact_nav
46
46
 
47
47
  # Responsive pagination for Materialize: it returns the html with the series of links to the pages
48
48
  # rendered by the Pagy.responsive javascript
49
- def pagy_materialize_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
49
+ def pagy_materialize_responsive_nav(pagy, id=pagy_id)
50
50
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
51
51
 
52
52
  tags['before'] = +'<ul class="pagination">'
@@ -64,7 +64,7 @@ class Pagy
64
64
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
65
65
  %(<div id="#{id}" class="pagy-nav-responsive-materialize pagy-materialize-responsive-nav pagination" role="navigation" aria-label="pager"></div>#{script})
66
66
  end
67
- Pagy.deprecate self, :pagy_nav_responsive_materialize, :pagy_materialize_responsive_nav
67
+ deprecate :pagy_nav_responsive_materialize, :pagy_materialize_responsive_nav
68
68
 
69
69
  end
70
70
  end
@@ -11,7 +11,7 @@ class Pagy
11
11
 
12
12
  # Plain compact pagination: it returns the html with the series of links to the pages
13
13
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
14
- def pagy_plain_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
14
+ def pagy_plain_compact_nav(pagy, id=pagy_id)
15
15
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
16
16
 
17
17
  html << %(<nav id="#{id}" class="pagy-nav-compact pagy-plain-compact-nav pagination" role="navigation" aria-label="pager">)
@@ -25,11 +25,11 @@ class Pagy
25
25
  : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
26
26
  html << %(</nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
27
27
  end
28
- Pagy.deprecate self, :pagy_nav_compact, :pagy_plain_compact_nav
28
+ deprecate :pagy_nav_compact, :pagy_plain_compact_nav
29
29
 
30
30
  # Plain responsive pagination: it returns the html with the series of links to the pages
31
31
  # rendered by the Pagy.responsive javascript
32
- def pagy_plain_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
32
+ def pagy_plain_responsive_nav(pagy, id=pagy_id)
33
33
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
34
34
 
35
35
  tags['before'] = (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
@@ -45,7 +45,7 @@ class Pagy
45
45
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
46
46
  %(<nav id="#{id}" class="pagy-nav-responsive pagy-plain-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
47
47
  end
48
- Pagy.deprecate self, :pagy_nav_responsive, :pagy_plain_responsive_nav
48
+ deprecate :pagy_nav_responsive, :pagy_plain_responsive_nav
49
49
 
50
50
  end
51
51
  end
@@ -22,11 +22,11 @@ class Pagy
22
22
  : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
23
23
  %(<div class="pagy-nav-semantic pagy-semantic-nav ui pagination menu" aria-label="pager">#{html}</div>)
24
24
  end
25
- Pagy.deprecate self, :pagy_nav_semantic, :pagy_semantic_nav
25
+ deprecate :pagy_nav_semantic, :pagy_semantic_nav
26
26
 
27
27
  # Compact pagination for semantic: it returns the html with the series of links to the pages
28
28
  # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_semantic_compact_nav(pagy, id=caller(1,1)[0].hash.to_s)
29
+ def pagy_semantic_compact_nav(pagy, id=pagy_id)
30
30
  html, link, p_prev, p_next, p_page, p_pages = +'', pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
31
31
 
32
32
  html << %(<div id="#{id}" class="pagy-nav-compact-semantic pagy-semantic-compact-nav ui compact menu" role="navigation" aria-label="pager">)
@@ -40,11 +40,11 @@ class Pagy
40
40
  : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
41
41
  html << %(</div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
42
42
  end
43
- Pagy.deprecate self, :pagy_nav_compact_semantic, :pagy_semantic_compact_nav
43
+ deprecate :pagy_nav_compact_semantic, :pagy_semantic_compact_nav
44
44
 
45
45
  # Responsive pagination for semantic: it returns the html with the series of links to the pages
46
46
  # rendered by the Pagy.responsive javascript
47
- def pagy_semantic_responsive_nav(pagy, id=caller(1,1)[0].hash.to_s)
47
+ def pagy_semantic_responsive_nav(pagy, id=pagy_id)
48
48
  tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.responsive
49
49
 
50
50
  tags['before'] = (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
@@ -60,7 +60,7 @@ class Pagy
60
60
  script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
61
61
  %(<div id="#{id}" class="pagy-nav-responsive-semantic pagy-semantic-responsive-nav ui pagination menu" role="navigation" aria-label="pager"></div>#{script})
62
62
  end
63
- Pagy.deprecate self, :pagy_nav_responsive_semantic, :pagy_semantic_responsive_nav
63
+ deprecate :pagy_nav_responsive_semantic, :pagy_semantic_responsive_nav
64
64
 
65
65
  end
66
66
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'digest'
4
5
 
5
6
  class Pagy
6
7
 
@@ -27,19 +28,24 @@ class Pagy
27
28
  end
28
29
  end
29
30
 
30
- def self.deprecate(mod, old_meth, new_meth)
31
- mod.send(:define_method, old_meth) do |pagy, id=caller(1,1)[0].hash.to_s|
32
- Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
33
- mod.instance_method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
34
- end
35
- end
36
-
37
31
  module Frontend
38
32
 
39
33
  def pagy_json_tag(*args)
40
34
  %(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
41
35
  end
42
36
 
37
+ def pagy_id
38
+ # SHA1 is the fastest on modern ruby
39
+ "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
40
+ end
41
+
42
+ def self.deprecate(old_meth, new_meth)
43
+ send(:define_method, old_meth) do |pagy, id=pagy_id|
44
+ Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
45
+ method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
46
+ end
47
+ end
48
+
43
49
  end
44
50
 
45
51
  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: 1.2.1
4
+ version: '1.3'
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-12-10 00:00:00.000000000 Z
11
+ date: 2019-01-15 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,
@@ -23,12 +23,14 @@ files:
23
23
  - LICENSE.txt
24
24
  - lib/config/pagy.rb
25
25
  - lib/javascripts/pagy.js
26
+ - lib/locales/README.md
26
27
  - lib/locales/de.yml
27
28
  - lib/locales/en.yml
28
29
  - lib/locales/es.yml
29
30
  - lib/locales/id.yml
30
31
  - lib/locales/ja.yml
31
32
  - lib/locales/nb.yml
33
+ - lib/locales/nl.yml
32
34
  - lib/locales/plurals.rb
33
35
  - lib/locales/pt-br.yml
34
36
  - lib/locales/ru.yml