pagy 5.6.4 → 5.6.8

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: 5436ee5b008a1f9db93ba52363fbae559f6444600c5925fcd87541b606e2a8ad
4
- data.tar.gz: 6159c1b56724cf1e10af6c15c2a141200d1795ed3da6fa6655cb1e7ee3f7056c
3
+ metadata.gz: ac9dce9d5ec1d5f58d2ff3da74572fc5f8b2a1853d03a2e5da63187ceed389c5
4
+ data.tar.gz: a181627b90698ae6450fba8bf4470774e76e8f0643cbd96798198db3dcb07c12
5
5
  SHA512:
6
- metadata.gz: 6d2e0aa3e7a4a9bfee7b4360b1d6ae35d931a1aa7fd4959436adf78cb43c153149ebb80455d9a63f7ef36558c5d673191fcd5ad10ce7e4be2e75ca42be645d05
7
- data.tar.gz: ee07cd90d3908f52c879cebf1956ee5cb1c12739b21e4a0519e7a8432e3ead0304a2bca94ca6a9444035e72563e2de2dd4a5191c279183fad39d22b7703babae
6
+ metadata.gz: 7468f2d14bb91b4c2df9b73a05609fe25ca4a2e722be22b540cc4806951a2fa6acf18fdfa7df4e9defd0c852a7f02566088c771b548eebd50aff6dd98262926d
7
+ data.tar.gz: 24e98a0fee02b4f0b3942e593385937715cfe69421a07166b861d4cc1eeaddf11eda6efe6f0257a782d0cf0c3bfe85631dffb17b96b6b241cd38c8c2749ece31
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.6.4)
3
+ # Pagy initializer file (5.6.8)
4
4
  # Customize only what you really need and notice that the core Pagy works also without any of the following lines.
5
5
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
6
6
 
@@ -1,136 +1,3 @@
1
- // See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
1
+ "use strict";function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c["return"]||c["return"]()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}var Pagy={version:"5.6.8",init:function init(a){var b,c=a instanceof HTMLElement?a:document,d=c.querySelectorAll("[data-pagy-json]"),e=_createForOfIteratorHelper(d);try{for(e.s();!(b=e.n()).done;){var f=b.value,g=f.getAttribute("data-pagy-json");if(null!==g){var h=JSON.parse(g),i=h.shift();"nav"===i?Pagy.nav.apply(Pagy,[f].concat(_toConsumableArray(h))):"combo_nav"===i?Pagy.combo_nav.apply(Pagy,[f].concat(_toConsumableArray(h))):"items_selector"===i&&Pagy.items_selector.apply(Pagy,[f].concat(_toConsumableArray(h)))}}}catch(a){e.e(a)}finally{e.f()}},nav:function nav(a,b,c,d,e){var f={};if(null===d)for(var k in c)f[k]=c[k].map(function(a){return a.toString()});else f=d;var g,h=Object.getOwnPropertyNames(c).map(function(a){return parseInt(a)}).sort(function(c,a){return a-c}),j=function(a,b,c){return a.replace(/__pagy_page__/g,b).replace(/__pagy_label__/g,c)};a.pagyRender=function(){var a,d=0,k=_createForOfIteratorHelper(h);try{for(k.s();!(a=k.n()).done;){var q=a.value;if(null!==this.parentElement&&this.parentElement.clientWidth>q){d=q;break}}}catch(a){k.e(a)}finally{k.f()}if(d!==g){var l=b.before,m=c[d.toString()],n=f[d.toString()];for(var r in m){var o=m[r],p=n[r];if("string"==typeof e&&1===o){var i=j(b.link,o.toString(),p);l+=Pagy.trim(i,e)}else l+="number"==typeof o?j(b.link,o.toString(),p):"gap"===o?b.gap:j(b.active,o,p)}l+=b.after,this.innerHTML="",this.insertAdjacentHTML("afterbegin",l),g=d}}.bind(a),a.pagyRender(),"undefined"!=typeof window&&window.addEventListener("resize",Pagy.throttleRenderNavs,!0)},throttleRenderNavsTID:0,throttleRenderNavsDelay:100,throttleRenderNavs:function throttleRenderNavs(){clearTimeout(Pagy.throttleRenderNavsTID),Pagy.throttleRenderNavsTID=window.setTimeout(Pagy.renderNavs,Pagy.throttleRenderNavsDelay)},renderNavs:function renderNavs(){var a,b=document.getElementsByClassName("pagy-njs"),c=_createForOfIteratorHelper(b);try{for(c.s();!(a=c.n()).done;){var d=a.value;d.pagyRender()}}catch(a){c.e(a)}finally{c.f()}},combo_nav:function combo_nav(a,b,c,d){var e=a.getElementsByTagName("input")[0];Pagy.addInputBehavior(e,function goToPage(){if(b!==e.value){var f=c.replace(/__pagy_page__/,e.value);"string"==typeof d&&"1"===e.value&&(f=Pagy.trim(f,d)),a.insertAdjacentHTML("afterbegin",f),a.getElementsByTagName("a")[0].click()}})},trim:function trim(a,b){var c=new RegExp("[?&]".concat(b,"=1\\b(?!&)|\\b").concat(b,"=1&"));return a.replace(c,"")},items_selector:function items_selector(a,b,c,d){var e=a.getElementsByTagName("input")[0],f=e.value;Pagy.addInputBehavior(e,function goToPage(){var g=Math.max,h=Math.ceil,i=e.value;if("0"!==i&&""!==i&&f!==i){var j=g(h(b/parseInt(i)),1).toString(),k=c.replace(/__pagy_page__/,j).replace(/__pagy_items__/,i);"string"==typeof d&&"1"===j&&(k=Pagy.trim(k,d)),a.insertAdjacentHTML("afterbegin",k),a.getElementsByTagName("a")[0].click()}})},addInputBehavior:function addInputBehavior(a,b){a.addEventListener("click",function(){this.select()}),a.addEventListener("focusout",function(){b()}),a.addEventListener("keypress",function(a){"Enter"===a.key&&b()}.bind(this))}};
2
2
 
3
- // This code should be OK also with very old browsers
4
-
5
- // Container for the whole pagy stuff
6
- function Pagy(){}
7
-
8
- Pagy.version = '5.6.4'
9
-
10
- // Used by the waitForMe function
11
- Pagy.delay = 100
12
-
13
- // Scan the target for data-pagy-json elements and apply their functions
14
- Pagy.init =
15
- function(arg) {
16
- var target = arg instanceof Event || arg === undefined ? document : arg,
17
- elements = target.querySelectorAll('[data-pagy-json]')
18
- for (var i = 0, len = elements.length; i < len; i++) {
19
- var args = JSON.parse(elements[i].getAttribute('data-pagy-json')),
20
- fname = args.shift()
21
- args.unshift(elements[i])
22
- Pagy[fname].apply(null, args)
23
- }
24
- }
25
-
26
- // Power the pagy*_nav_js helpers
27
- Pagy.nav =
28
- function(pagyEl, tags, sequels, label_sequels, trimParam ) {
29
- label_sequels = (label_sequels === null) ? sequels : label_sequels
30
- var widths = [], lastWidth,
31
- fill = function(string, item, label) { return string.replace(/__pagy_page__/g, item)
32
- .replace(/__pagy_label__/g, label) }
33
- for (var width in sequels) {
34
- if (sequels.hasOwnProperty(width)) { widths.push(parseInt(width, 10)) }
35
- }
36
- widths.sort(function(a, b) { return b - a })
37
-
38
- pagyEl.render =
39
- function() {
40
- var width, i, len
41
- for (i = 0, len = widths.length; i < len; i++) {
42
- if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
43
- }
44
- if (width !== lastWidth) {
45
- var html = tags.before,
46
- series = sequels[width],
47
- labels = label_sequels[width]
48
- for (i = 0, len = series.length; i < len; i++) {
49
- var item = series[i],
50
- label = labels[i]
51
- if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(fill(tags.link, item, label), trimParam) }
52
- else if (typeof(item) === 'number') { html += fill(tags.link, item, label) }
53
- else if (item === 'gap') { html += tags.gap }
54
- else if (typeof(item) === 'string') { html += fill(tags.active, item, label) }
55
- }
56
- html += tags.after
57
- this.innerHTML = ''
58
- this.insertAdjacentHTML('afterbegin', html)
59
- lastWidth = width
60
- }
61
- }.bind(pagyEl)
62
- pagyEl.render()
63
- }
64
-
65
- // Power the pagy*_combo_nav_js helpers
66
- Pagy.combo_nav =
67
- function(pagyEl, page, link, trimParam) {
68
- var input = pagyEl.getElementsByTagName('input')[0],
69
- toPage =
70
- function() {
71
- if (page !== input.value) {
72
- var html = link.replace(/__pagy_page__/, input.value)
73
- if (typeof (trimParam) === 'string' && input.value === '1') { html = Pagy.trim(html, trimParam) }
74
- pagyEl.insertAdjacentHTML('afterbegin', html)
75
- pagyEl.getElementsByTagName('a')[0].click()
76
- }
77
- }
78
- Pagy.addInputEventListeners(input, toPage)
79
- }
80
-
81
- // Power the pagy_items_selector_js helper
82
- Pagy.items_selector =
83
- function(pagyEl, from, link, param) {
84
- var input = pagyEl.getElementsByTagName('input')[0],
85
- current = input.value,
86
- toPage =
87
- function() {
88
- var items = input.value
89
- if (items === 0 || items === '') { return }
90
- if (current !== items) {
91
- var page = Math.max(Math.ceil(from / items), 1),
92
- html = link.replace(/__pagy_page__/, page).replace(/__pagy_items__/, items)
93
- if (typeof (param) === 'string' && page === 1) { html = Pagy.trim(html, param) }
94
- pagyEl.insertAdjacentHTML('afterbegin', html)
95
- pagyEl.getElementsByTagName('a')[0].click()
96
- }
97
- }
98
- Pagy.addInputEventListeners(input, toPage)
99
- }
100
-
101
- // Utility for input fields
102
- Pagy.addInputEventListeners =
103
- function(input, toPage) {
104
- // select the content on click: easier for typing a number
105
- input.addEventListener('click', function() { this.select() })
106
- // toPage when the input looses focus
107
- input.addEventListener('focusout', toPage)
108
- // … and when pressing enter inside the input
109
- input.addEventListener('keyup', function(e) { if (e.which === 13) {toPage()} }.bind(this))
110
- }
111
-
112
- // Power the trim extra for js helpers
113
- Pagy.trim =
114
- function(html, param) {
115
- var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&')
116
- return html.replace(re, '')
117
- }
118
-
119
- // Render all *nav_js helpers
120
- Pagy.renderNavs =
121
- function() {
122
- var navs = document.getElementsByClassName('pagy-njs') // 'pagy-njs' is common to all *nav_js helpers
123
- for (var i = 0, len = navs.length; i < len; i++) { navs[i].render() }
124
- }
125
-
126
- // Throttle to avoid to fire multiple time the renderNavs on resize
127
- Pagy.waitForMe =
128
- function() {
129
- if (typeof(Pagy.tid) === 'number') { clearTimeout(Pagy.tid) }
130
- Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay)
131
- }
132
-
133
- // If there is a window object then add the event listener on resize
134
- if (typeof window !== 'undefined') {
135
- window.addEventListener('resize', Pagy.waitForMe, true)
136
- }
3
+ //# sourceMappingURL=pagy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../ts/src/pagy.ts"],"names":[],"mappings":"mrDAkCA,GAAM,CAAA,IAAI,CAAG,CACT,OAAO,CAAE,OADA,CAIT,IAJS,eAIJ,CAJI,CAIM,OACL,CAA2B,CAAG,CAAG,WAAY,CAAA,WAAf,CAA6B,CAA7B,CAAmC,QAD5D,CAEL,CAAQ,CAAG,CAAM,CAAC,gBAAP,CAAwB,kBAAxB,CAFN,8BAGW,CAHX,MAGX,2BAAgC,IAArB,CAAA,CAAqB,SACtB,CAAI,CAAG,CAAO,CAAC,YAAR,CAAqB,gBAArB,CADe,CAE5B,GAAa,IAAT,GAA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KAApC,EACH,CACJ,CACD,CACH,CAvJQ,CA0JT,gBA1JS,2BA0JQ,CA1JR,CA0JgC,CA1JhC,CA0JmD,CAExD,CAAK,CAAC,gBAAN,CAAuB,OAAvB,CAAgC,UAAc,CAC1C,KAAK,MAAL,EACH,CAFD,CAFwD,CAMxD,CAAK,CAAC,gBAAN,CAAuB,UAAvB,CAAmC,UAAc,CAC7C,CAAQ,EACX,CAFD,CANwD,CAUxD,CAAK,CAAC,gBAAN,CAAuB,UAAvB,CAAmC,SAAU,CAAV,CAA2B,CAC5C,OAAV,GAAA,CAAC,CAAC,GADoD,EAEtD,CAAQ,EAEf,CAJkC,CAIjC,IAJiC,CAI5B,IAJ4B,CAAnC,CAKH,CAzKQ,CAAb","file":"pagy.js","sourcesContent":["// This file is the source that generates pagy.js, polyfilled with the `@babel/preset-env` `\"useBuiltIns\": \"entry\"`.\n// You can generate a custom targeted javascript file for the browsers you need by changing that settings in package.json,\n// then compile it with `npm run compile -w ts`.\n\n// Add pagyRender to Element\ninterface Element {\n pagyRender():void;\n}\n\n// Add pagyRender to HTMLElement\ninterface HTMLElement {\n pagyRender():void;\n}\n\n// Tags from the data-pagy-json of *nav_js helpers\ninterface NavTags {\n readonly before:string;\n readonly link:string;\n readonly active:string;\n readonly gap:string;\n readonly after:string;\n}\n\n// Tags from the data-pagy-json of *nav_js helpers\ninterface NavSequels {\n readonly [width:string]:(string|number|\"gap\")[];\n}\n\n// Tags from the data-pagy-json of *nav_js helpers\ninterface NavLabelSequels {\n [width:string]:(string|\"gap\")[];\n}\n\n// The Pagy object\nconst Pagy = {\n version: \"5.6.8\",\n\n // Scan for \"data-pagy-json\" elements, parse their JSON content and apply their functions\n init(arg?:any) {\n const target:Document|HTMLElement = arg instanceof HTMLElement ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy-json]\");\n for (const element of elements) {\n const json = element.getAttribute(\"data-pagy-json\");\n if (json === null) {\n continue;\n }\n let args = JSON.parse(json);\n const fname:\"nav\"|\"combo_nav\"|\"items_selector\" = args.shift();\n if (fname === \"nav\") {\n Pagy.nav(element, ...<[NavTags, NavSequels, null|NavLabelSequels, string]>args);\n }\n else if (fname === \"combo_nav\") {\n Pagy.combo_nav(element, ...<[string, string, string]>args);\n }\n else if (fname === \"items_selector\") {\n Pagy.items_selector(element, ...<[number, string, string]>args);\n }\n }\n },\n\n // Power the *_nav_js helpers\n nav(pagyEl:Element, tags:NavTags, sequels:NavSequels, opt_label_sequels:null|NavLabelSequels, trimParam?:string) {\n let label_sequels:NavLabelSequels = {};\n // Handle null label_sequels\n if (opt_label_sequels === null) {\n for (const width in sequels) {\n label_sequels[width] = sequels[width].map((item) => item.toString());\n }\n }\n else {\n label_sequels = opt_label_sequels;\n }\n // Set and sort the widths as number[]\n const widths = Object.getOwnPropertyNames(sequels)\n .map((w) => parseInt(w))\n .sort((a, b) => b - a);\n let lastWidth:number;\n const fillIn = (string:string, item:string, label:string):string =>\n string.replace(/__pagy_page__/g, item)\n .replace(/__pagy_label__/g, label);\n\n pagyEl.pagyRender = function (this:Element) {\n let width:number = 0;\n for (const w of widths) {\n if (this.parentElement !== null && this.parentElement.clientWidth > w) {\n width = w;\n break;\n }\n }\n // Only if the width changed\n if (width !== lastWidth) {\n let html = tags.before;\n const series = sequels[width.toString()];\n const labels = label_sequels[width.toString()];\n for (const i in series) {\n const item = series[i];\n const label = labels[i];\n if (typeof trimParam === \"string\" && item === 1) {\n const link = fillIn(tags.link, item.toString(), label);\n html += Pagy.trim(link, trimParam);\n }\n else if (typeof item === \"number\") {\n html += fillIn(tags.link, item.toString(), label);\n }\n else if (item === \"gap\") {\n html += tags.gap;\n }\n else { // active page\n html += fillIn(tags.active, item, label);\n }\n }\n html += tags.after;\n this.innerHTML = \"\";\n this.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n }\n }.bind(pagyEl);\n pagyEl.pagyRender();\n // If there is a window object then add a single \"resize\" event listener\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"resize\", Pagy.throttleRenderNavs, true);\n }\n },\n\n // throttleRenderNavs properties\n throttleRenderNavsTID: 0, // private\n throttleRenderNavsDelay: 100, // set a default delay\n\n // Avoid to fire the pagyRender multiple times\n throttleRenderNavs() {\n clearTimeout(Pagy.throttleRenderNavsTID);\n Pagy.throttleRenderNavsTID = window.setTimeout(Pagy.renderNavs, Pagy.throttleRenderNavsDelay);\n },\n\n // Render all *nav_js helpers (i.e. all the elements of class \"pagy-njs\")\n renderNavs() {\n const navs:HTMLCollectionOf<Element> = document.getElementsByClassName(\"pagy-njs\");\n for (const nav of navs) {\n nav.pagyRender();\n }\n },\n\n // Power the *_combo_nav_js helpers\n combo_nav(pagyEl:Element, page:string, link:string, trimParam?:string) {\n const input:HTMLInputElement = pagyEl.getElementsByTagName(\"input\")[0];\n const goToPage = function () {\n if (page !== input.value) {\n let html = link.replace(/__pagy_page__/, input.value);\n if (typeof trimParam === \"string\" && input.value === \"1\") {\n html = Pagy.trim(html, trimParam);\n }\n pagyEl.insertAdjacentHTML(\"afterbegin\", html);\n pagyEl.getElementsByTagName(\"a\")[0].click();\n }\n };\n Pagy.addInputBehavior(input, goToPage);\n },\n\n // Power the trim extra for js helpers\n trim(link:string, param:string):string {\n const re = new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`);\n return link.replace(re, \"\");\n },\n\n // Power the pagy_items_selector_js helper\n items_selector(pagyEl:Element, from:number, link:string, trimParam?:string) {\n const input:HTMLInputElement = pagyEl.getElementsByTagName(\"input\")[0];\n const current = input.value;\n const goToPage = function () {\n const items = input.value;\n if (items === \"0\" || items === \"\") {\n return;\n }\n if (current !== items) {\n const page = Math.max(Math.ceil(from / parseInt(items)), 1).toString();\n let html = link.replace(/__pagy_page__/, page)\n .replace(/__pagy_items__/, items);\n if (typeof trimParam === \"string\" && page === \"1\") {\n html = Pagy.trim(html, trimParam);\n }\n pagyEl.insertAdjacentHTML(\"afterbegin\", html);\n pagyEl.getElementsByTagName(\"a\")[0].click();\n }\n };\n Pagy.addInputBehavior(input, goToPage);\n },\n\n // Add behavior to input fields\n addInputBehavior(input:HTMLInputElement, goToPage:Function) {\n // select the content on click: easier for direct typing\n input.addEventListener(\"click\", function (_e) {\n this.select();\n });\n // goToPage when the input loses focus\n input.addEventListener(\"focusout\", function (_e) {\n goToPage();\n });\n // goToPage when pressing enter while the input has focus\n input.addEventListener(\"keypress\", function (e:KeyboardEvent) {\n if (e.key === \"Enter\") {\n goToPage();\n }\n }.bind(this));\n }\n};\n"]}
data/lib/pagy/backend.rb CHANGED
@@ -8,7 +8,7 @@ class Pagy
8
8
  module Backend
9
9
  private
10
10
 
11
- # Return Pagy object and items
11
+ # Return Pagy object and paginated items/results
12
12
  def pagy(collection, vars = {})
13
13
  pagy = Pagy.new(pagy_get_vars(collection, vars))
14
14
  [pagy, pagy_get_items(collection, pagy)]
data/lib/pagy/calendar.rb CHANGED
@@ -41,7 +41,7 @@ class Pagy # :nodoc:
41
41
 
42
42
  protected
43
43
 
44
- # Base class method for the setup of the unit variables
44
+ # Base class method for the setup of the unit variables (subclasses must implement it and call super)
45
45
  def setup_unit_vars
46
46
  raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
47
47
  raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
@@ -85,6 +85,6 @@ class Pagy # :nodoc:
85
85
  end
86
86
  end
87
87
  end
88
-
88
+ # Require the subclass files in UNITS (no custom unit at this point yet)
89
89
  Calendar::UNITS.each { |unit| require "pagy/calendar/#{unit}" }
90
90
  end
@@ -6,11 +6,13 @@ class Pagy # :nodoc:
6
6
  module ArelExtra
7
7
  private
8
8
 
9
+ # Return Pagy object and paginated collection/results
9
10
  def pagy_arel(collection, vars = {})
10
11
  pagy = Pagy.new(pagy_arel_get_vars(collection, vars))
11
12
  [pagy, pagy_get_items(collection, pagy)]
12
13
  end
13
14
 
15
+ # Sub-method called only by #pagy_arel: here for easy customization of variables by overriding
14
16
  def pagy_arel_get_vars(collection, vars)
15
17
  pagy_set_items_from_params(vars) if defined?(ItemsExtra)
16
18
  vars[:count] ||= pagy_arel_count(collection)
@@ -18,6 +20,7 @@ class Pagy # :nodoc:
18
20
  vars
19
21
  end
20
22
 
23
+ # Count using Arel when grouping
21
24
  def pagy_arel_count(collection)
22
25
  if collection.group_values.empty?
23
26
  # COUNT(*)
@@ -6,7 +6,7 @@ class Pagy # :nodoc:
6
6
  module ArrayExtra
7
7
  private
8
8
 
9
- # Return Pagy object and items
9
+ # Return Pagy object and paginated items
10
10
  def pagy_array(array, vars = {})
11
11
  pagy = Pagy.new(pagy_array_get_vars(array, vars))
12
12
  [pagy, array[pagy.offset, pagy.items]]
@@ -26,7 +26,9 @@ class Pagy # :nodoc:
26
26
 
27
27
  # Setup and return the calendar objects and the filtered collection
28
28
  def pagy_setup_calendar(collection, conf)
29
- units = Calendar::UNITS & conf.keys # get the units in time length desc order
29
+ units = Calendar::UNITS & conf.keys # get the units in time length desc order
30
+ raise ArgumentError, 'no calendar unit found in pagy_calendar configuration' if units.empty?
31
+
30
32
  page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
31
33
  units.each do |unit| # set all the :page_param vars for later deletion
32
34
  unit_page_param = :"#{unit}_#{page_param}"
@@ -18,7 +18,7 @@ class Pagy # :nodoc:
18
18
  # "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
19
19
  # "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
20
20
  # Notice: if :steps is false it will use the single {0 => @vars[:size]} size
21
- def sequels(steps: @vars[:steps] || { 0 => @vars[:size] })
21
+ def sequels(steps: @vars[:steps] || { 0 => @vars[:size] }, **_)
22
22
  raise VariableError.new(self, :steps, 'to define the 0 width', steps) unless steps.key?(0)
23
23
 
24
24
  {}.tap do |sequels|
@@ -4,14 +4,14 @@
4
4
  class Pagy # :nodoc:
5
5
  # Use ::I18n gem
6
6
  module I18nExtra
7
- # Frontend overriding
7
+ # Frontend overriding for translation
8
8
  module Frontend
9
9
  def pagy_t(key, **opts)
10
10
  ::I18n.t(key, **opts)
11
11
  end
12
12
  end
13
13
 
14
- # Calendar overriding
14
+ # Calendar overriding for localization (see also the block in the calendar section of the config/pagy.rb initializer)
15
15
  module Calendar
16
16
  def localize(time, opts)
17
17
  ::I18n.l(time, **opts)
data/lib/pagy/frontend.rb CHANGED
@@ -77,7 +77,7 @@ class Pagy
77
77
  # Similar to I18n.t: just ~18x faster using ~10x less memory
78
78
  # (@pagy_locale explicitly initialized in order to avoid warning)
79
79
  def pagy_t(key, opts = {})
80
- Pagy::I18n.t(@pagy_locale ||= nil, key, opts)
80
+ Pagy::I18n.translate(@pagy_locale ||= nil, key, opts)
81
81
  end
82
82
  end
83
83
  end
data/lib/pagy/i18n.rb CHANGED
@@ -153,11 +153,12 @@ class Pagy
153
153
  end
154
154
 
155
155
  # Translate and pluralize the key with the locale DATA
156
- def t(locale, key, opts = {})
156
+ def translate(locale, key, opts = {})
157
157
  data, pluralize = DATA[locale]
158
158
  translation = data[key] || (opts[:count] && data[key += ".#{pluralize.call(opts[:count])}"]) \
159
159
  or return %([translation missing: "#{key}"])
160
160
  translation.gsub(/%{[^}]+?}/) { |match| opts[:"#{match[2..-2]}"] || match }
161
161
  end
162
+ alias t translate
162
163
  end
163
164
  end
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # Core class
7
7
  class Pagy
8
- VERSION = '5.6.4'
8
+ VERSION = '5.6.8'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -44,7 +44,7 @@ class Pagy
44
44
  end
45
45
 
46
46
  # Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
47
- def series(size: @vars[:size])
47
+ def series(size: @vars[:size], **_)
48
48
  return [] if size.empty?
49
49
  raise VariableError.new(self, :size, 'to contain 4 items >= 0', size) \
50
50
  unless size.is_a?(Array) && size.size == 4 && size.all? { |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
@@ -76,6 +76,7 @@ class Pagy
76
76
  page.to_s
77
77
  end
78
78
 
79
+ # Allow the customization of the output (overridden by the calendar extra)
79
80
  def label
80
81
  @page.to_s
81
82
  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: 5.6.4
4
+ version: 5.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-03 00:00:00.000000000 Z
11
+ date: 2021-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Agnostic pagination in plain ruby. It does it all. Better.
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - LICENSE.txt
21
21
  - lib/config/pagy.rb
22
22
  - lib/javascripts/pagy.js
23
+ - lib/javascripts/pagy.js.map
23
24
  - lib/locales/ar.yml
24
25
  - lib/locales/bg.yml
25
26
  - lib/locales/bs.yml
@@ -111,6 +112,11 @@ licenses:
111
112
  - MIT
112
113
  metadata:
113
114
  rubygems_mfa_required: 'true'
115
+ homepage_uri: https://github.com/ddnexus/pagy
116
+ documentation_uri: https://ddnexus.github.io/pagy
117
+ bug_tracker_uri: https://github.com/ddnexus/pagy/issues
118
+ changelog_uri: https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md
119
+ live_support: https://gitter.im/ruby-pagy/Lobby
114
120
  post_install_message:
115
121
  rdoc_options: []
116
122
  require_paths:
@@ -126,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  - !ruby/object:Gem::Version
127
133
  version: '0'
128
134
  requirements: []
129
- rubygems_version: 3.2.3
135
+ rubygems_version: 3.2.32
130
136
  signing_key:
131
137
  specification_version: 4
132
138
  summary: The kick-ass pagination ruby gem