pagy 5.6.5 → 5.6.9

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: 3bc0ec346bfde6c907da343d7c3f7ad611cbb69f4ed8e36aa09b69b48276ecb6
4
- data.tar.gz: 9d936c804c00f7eb530c9a7f5d1ecf763704daf84e35b9a3288eae2f88d3e3be
3
+ metadata.gz: 4a0769124a79924740926d3ad51cd5ef72e6f935a5b065045ce4f10e8e84ab67
4
+ data.tar.gz: a855520088ddd6b81fbeb76384c390bb5c886bd1d81cb3d23ff6b0dd8ac77153
5
5
  SHA512:
6
- metadata.gz: a2e92a735ed04def206a2cdd81577ff39042cc03f98a4343b6e8889c008bb5ba8277bd76168b1d3f39067bc68b9e9b4b1805721cac9a12cded2a491b106023db
7
- data.tar.gz: 825ad4c0c076d4dae52ba69772b0c827662181ddd9bd077c41ec5a167b0da506bf7153493a99ab5a704043f08918b1d0e460430c8fa7ee08d0675b1f3d1a5619
6
+ metadata.gz: 8d2f70d1148feeaafa49c1e3ceb39b5e8891007215fc6197a0ea6dbf48f8a888edb6e2edc70a2c5fad9db36ca3b01a7527ff2c0941f53b6b9900156d40976a3b
7
+ data.tar.gz: 69fcd04e4eca0665a949f2cb8db57b2ad26d749c00e58ccfe75d18ab750b56acb84a18d7b5e95448390d1fdb11e16d9360971d6d93cab832adeea03e3b1e5f6e
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017-2021 Domizio Demichelis
3
+ Copyright (c) 2017-2022 Domizio Demichelis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.6.5)
3
+ # Pagy initializer file (5.6.9)
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.9",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 d=h.find(function(b){return null!==a.parentElement&&a.parentElement.clientWidth>b})||0;if(d!==g){var k=b.before,l=c[d.toString()],m=f[d.toString()];for(var p in l){var n=l[p],o=m[p];if("string"==typeof e&&1===n){var i=j(b.link,n.toString(),o);k+=Pagy.trim(i,e)}else k+="number"==typeof n?j(b.link,n.toString(),o):"gap"===n?b.gap:j(b.active,n,o)}k+=b.after,a.innerHTML="",a.insertAdjacentHTML("afterbegin",k),g=d}},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=document.getElementsByClassName("pagy-njs");Array.from(a).forEach(function(a){return a.pagyRender()})},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()}})},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",a.select),a.addEventListener("focusout",b),a.addEventListener("keypress",function(a){"Enter"===a.key&&b()})},trim:function trim(a,b){var c=new RegExp("[?&]".concat(b,"=1\\b(?!&)|\\b").concat(b,"=1&"));return a.replace(c,"")}};
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.5'
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":["../../src/pagy.ts"],"names":[],"mappings":"mrDA6BA,GAAM,CAAA,IAAI,CAAG,CACT,OAAO,CAAE,OADA,CAIT,IAJS,eAIJ,CAJI,CAI6B,OAC5B,CAAM,CAAG,CAAG,WAAY,CAAA,WAAf,CAA6B,CAA7B,CAAmC,QADhB,CAE5B,CAAQ,CAAG,CAAM,CAAC,gBAAP,CAAwB,kBAAxB,CAFiB,8BAGZ,CAHY,MAGlC,2BAAgC,IAArB,CAAA,CAAqB,SACtB,CAAI,CAAG,CAAO,CAA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AAC,gBAAN,CAAuB,UAAvB,CAAmC,CAAnC,CAJ0D,CAM1D,CAAK,CAAC,gBAAN,CAAuB,UAAvB,CAAmC,SAAC,CAAD,CAAqB,CACtC,OAAV,GAAA,CAAC,CAAC,GAD8C,EAEhD,CAAQ,EAEf,CAJD,CAKH,CAlJQ,CAqJT,IArJS,eAqJJ,CArJI,CAqJS,CArJT,CAqJ8B,CACnC,GAAM,CAAA,CAAE,CAAG,GAAI,CAAA,MAAJ,eAAkB,CAAlB,0BAAwC,CAAxC,QAAX,CACA,MAAO,CAAA,CAAI,CAAC,OAAL,CAAa,CAAb,CAAiB,EAAjB,CACV,CAxJQ,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 src`.\n\n// Add pagyRender to Element\ninterface Element {\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.9\",\n\n // Scan for \"data-pagy-json\" elements, parse their JSON content and apply their functions\n init(arg?:HTMLElement|Document|Event) {\n const target = 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 const args = JSON.parse(json);\n const fname = args.shift() as \"nav\"|\"combo_nav\"|\"items_selector\";\n if (fname === \"nav\") {\n Pagy.nav(element, ...args as [NavTags, NavSequels, null|NavLabelSequels, string]);\n } else if (fname === \"combo_nav\") {\n Pagy.combo_nav(element, ...args as [string, string, string]);\n } else if (fname === \"items_selector\") {\n Pagy.items_selector(element, ...args as [number, string, string]);\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 = {} as 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 } 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 = () => {\n // Find the width that fits in parent\n const width = widths.find((w) => pagyEl.parentElement !== null && pagyEl.parentElement.clientWidth > w) || 0;\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 } else if (typeof item === \"number\") {\n html += fillIn(tags.link, item.toString(), label);\n } else if (item === \"gap\") {\n html += tags.gap;\n } else { // active page\n html += fillIn(tags.active, item, label);\n }\n }\n html += tags.after;\n pagyEl.innerHTML = \"\";\n pagyEl.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n }\n };\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 = document.getElementsByClassName(\"pagy-njs\");\n Array.from(navs).forEach((nav) => nav.pagyRender());\n },\n\n // Power the *_combo_nav_js helpers\n combo_nav(pagyEl:Element, page:string, link:string, trimParam?:string) {\n const input = pagyEl.getElementsByTagName(\"input\")[0];\n const goToPage = () => {\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 pagy_items_selector_js helper\n items_selector(pagyEl:Element, from:number, link:string, trimParam?:string) {\n const input = pagyEl.getElementsByTagName(\"input\")[0];\n const current = input.value;\n const goToPage = () => {\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:() => void) {\n // select the content on click: easier for direct typing\n input.addEventListener(\"click\", input.select);\n // goToPage when the input loses focus\n input.addEventListener(\"focusout\", goToPage);\n // goToPage when pressing enter while the input has focus\n input.addEventListener(\"keypress\", (e:KeyboardEvent) => {\n if (e.key === \"Enter\") {\n goToPage();\n }\n });\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"]}
@@ -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|
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.5'
8
+ VERSION = '5.6.9'
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
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.5
4
+ version: 5.6.9
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-08 00:00:00.000000000 Z
11
+ date: 2022-01-02 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