pagy 8.6.3 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +1 -1
  3. data/apps/demo.ru +4 -4
  4. data/apps/keyset_ar.ru +236 -0
  5. data/apps/keyset_s.ru +238 -0
  6. data/apps/rails.ru +5 -5
  7. data/apps/repro.ru +4 -4
  8. data/apps/tmp/calendar.sqlite3 +0 -0
  9. data/apps/tmp/calendar.sqlite3-shm +0 -0
  10. data/apps/tmp/calendar.sqlite3-wal +0 -0
  11. data/apps/tmp/local_secret.txt +1 -1
  12. data/apps/tmp/{pagy-keyset.sqlite3 → pagy-keyset-ar.sqlite3} +0 -0
  13. data/apps/tmp/{pagy-keyset.sqlite3-shm → pagy-keyset-ar.sqlite3-shm} +0 -0
  14. data/apps/tmp/{pagy-keyset.sqlite3-wal → pagy-keyset-ar.sqlite3-wal} +0 -0
  15. data/apps/tmp/pagy-keyset-s.sqlite3 +0 -0
  16. data/bin/pagy +4 -2
  17. data/config/pagy.rb +13 -13
  18. data/javascripts/pagy.min.js +2 -2
  19. data/javascripts/pagy.min.js.map +2 -2
  20. data/javascripts/pagy.mjs +2 -2
  21. data/lib/pagy/b64.rb +33 -0
  22. data/lib/pagy/backend.rb +21 -17
  23. data/lib/pagy/calendar/day.rb +1 -1
  24. data/lib/pagy/calendar/month.rb +1 -1
  25. data/lib/pagy/calendar/quarter.rb +1 -1
  26. data/lib/pagy/calendar/unit.rb +7 -10
  27. data/lib/pagy/calendar/week.rb +1 -1
  28. data/lib/pagy/calendar/year.rb +1 -1
  29. data/lib/pagy/calendar.rb +5 -5
  30. data/lib/pagy/countless.rb +10 -14
  31. data/lib/pagy/extras/arel.rb +8 -10
  32. data/lib/pagy/extras/array.rb +4 -6
  33. data/lib/pagy/extras/bootstrap.rb +5 -5
  34. data/lib/pagy/extras/bulma.rb +10 -7
  35. data/lib/pagy/extras/calendar.rb +4 -5
  36. data/lib/pagy/extras/countless.rb +6 -13
  37. data/lib/pagy/extras/elasticsearch_rails.rb +15 -15
  38. data/lib/pagy/extras/gearbox.rb +18 -18
  39. data/lib/pagy/extras/headers.rb +25 -24
  40. data/lib/pagy/extras/js_tools.rb +4 -4
  41. data/lib/pagy/extras/jsonapi.rb +26 -16
  42. data/lib/pagy/extras/keyset.rb +26 -0
  43. data/lib/pagy/extras/limit.rb +63 -0
  44. data/lib/pagy/extras/meilisearch.rb +11 -11
  45. data/lib/pagy/extras/metadata.rb +2 -2
  46. data/lib/pagy/extras/overflow.rb +5 -5
  47. data/lib/pagy/extras/pagy.rb +16 -16
  48. data/lib/pagy/extras/searchkick.rb +11 -11
  49. data/lib/pagy/extras/size.rb +1 -1
  50. data/lib/pagy/extras/standalone.rb +6 -6
  51. data/lib/pagy/extras/trim.rb +2 -2
  52. data/lib/pagy/frontend.rb +32 -33
  53. data/lib/pagy/i18n.rb +1 -1
  54. data/lib/pagy/keyset/active_record.rb +38 -0
  55. data/lib/pagy/keyset/sequel.rb +51 -0
  56. data/lib/pagy/keyset.rb +99 -0
  57. data/lib/pagy/url_helpers.rb +5 -5
  58. data/lib/pagy.rb +73 -65
  59. data/locales/ar.yml +1 -1
  60. data/locales/be.yml +1 -1
  61. data/locales/bg.yml +1 -1
  62. data/locales/bs.yml +1 -1
  63. data/locales/ca.yml +1 -1
  64. data/locales/ckb.yml +1 -1
  65. data/locales/cs.yml +1 -1
  66. data/locales/da.yml +1 -1
  67. data/locales/de.yml +1 -1
  68. data/locales/en.yml +1 -1
  69. data/locales/es.yml +1 -1
  70. data/locales/fr.yml +1 -1
  71. data/locales/hr.yml +1 -1
  72. data/locales/id.yml +1 -1
  73. data/locales/it.yml +1 -1
  74. data/locales/ja.yml +1 -1
  75. data/locales/km.yml +1 -1
  76. data/locales/ko.yml +1 -1
  77. data/locales/nb.yml +1 -1
  78. data/locales/nl.yml +1 -1
  79. data/locales/nn.yml +1 -1
  80. data/locales/pl.yml +1 -1
  81. data/locales/pt-BR.yml +1 -1
  82. data/locales/pt.yml +1 -1
  83. data/locales/ru.yml +1 -1
  84. data/locales/sr.yml +1 -1
  85. data/locales/sv-SE.yml +1 -1
  86. data/locales/sv.yml +1 -1
  87. data/locales/sw.yml +1 -1
  88. data/locales/ta.yml +1 -1
  89. data/locales/tr.yml +1 -1
  90. data/locales/uk.yml +1 -1
  91. data/locales/vi.yml +1 -1
  92. data/locales/zh-CN.yml +1 -1
  93. data/locales/zh-HK.yml +1 -1
  94. data/locales/zh-TW.yml +1 -1
  95. data/pkg/pagy-9.0.0.gem +0 -0
  96. metadata +16 -18
  97. data/lib/pagy/extras/foundation.rb +0 -95
  98. data/lib/pagy/extras/items.rb +0 -64
  99. data/lib/pagy/extras/materialize.rb +0 -100
  100. data/lib/pagy/extras/semantic.rb +0 -94
  101. data/lib/pagy/extras/uikit.rb +0 -98
data/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (8.6.3)
3
+ # Pagy initializer file (9.0.0)
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
 
@@ -10,7 +10,7 @@
10
10
  # You can set any pagy variable as a Pagy::DEFAULT. They can also be overridden per instance by just passing them to
11
11
  # Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
12
12
  # Here are the few that make more sense as DEFAULTs:
13
- # Pagy::DEFAULT[:items] = 20 # default
13
+ # Pagy::DEFAULT[:limit] = 20 # default
14
14
  # Pagy::DEFAULT[:size] = 7 # default
15
15
  # Pagy::DEFAULT[:ends] = true # default
16
16
  # Pagy::DEFAULT[:page_param] = :page # default
@@ -75,7 +75,7 @@
75
75
  # See http://ddnexus.github.io/pagy/extras/headers
76
76
  # require 'pagy/extras/headers'
77
77
  # Pagy::DEFAULT[:headers] = { page: 'Current-Page',
78
- # items: 'Page-Items',
78
+ # limit: 'Page-Items',
79
79
  # count: 'Total-Count',
80
80
  # pages: 'Total-Pages' } # default
81
81
 
@@ -130,20 +130,20 @@
130
130
 
131
131
  # Feature Extras
132
132
 
133
- # Gearbox extra: Automatically change the number of items per page depending on the page number
133
+ # Gearbox extra: Automatically change the limit per page depending on the page number
134
134
  # See https://ddnexus.github.io/pagy/docs/extras/gearbox
135
135
  # require 'pagy/extras/gearbox'
136
136
  # set to false only if you want to make :gearbox_extra an opt-in variable
137
137
  # Pagy::DEFAULT[:gearbox_extra] = false # default true
138
- # Pagy::DEFAULT[:gearbox_items] = [15, 30, 60, 100] # default
138
+ # Pagy::DEFAULT[:gearbox_limit] = [15, 30, 60, 100] # default
139
139
 
140
- # Items extra: Allow the client to request a custom number of items per page with an optional selector UI
141
- # See https://ddnexus.github.io/pagy/docs/extras/items
142
- # require 'pagy/extras/items'
143
- # set to false only if you want to make :items_extra an opt-in variable
144
- # Pagy::DEFAULT[:items_extra] = false # default true
145
- # Pagy::DEFAULT[:items_param] = :items # default
146
- # Pagy::DEFAULT[:max_items] = 100 # default
140
+ # Limit extra: Allow the client to request a custom limit per page with an optional selector UI
141
+ # See https://ddnexus.github.io/pagy/docs/extras/limit
142
+ # require 'pagy/extras/limit'
143
+ # set to false only if you want to make :limit_extra an opt-in variable
144
+ # Pagy::DEFAULT[:limit_extra] = false # default true
145
+ # Pagy::DEFAULT[:limit_param] = :limit # default
146
+ # Pagy::DEFAULT[:limit_max] = 100 # default
147
147
 
148
148
  # Overflow extra: Allow for easy handling of overflowing pages
149
149
  # See https://ddnexus.github.io/pagy/docs/extras/overflow
@@ -169,7 +169,7 @@
169
169
 
170
170
  # Rails
171
171
  # Enable the .js file required by the helpers that use javascript
172
- # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
172
+ # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_limit_selector_js)
173
173
  # See https://ddnexus.github.io/pagy/docs/api/javascript
174
174
 
175
175
  # With the asset pipeline
@@ -1,4 +1,4 @@
1
- window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_items__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"8.6.3",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse((new TextDecoder()).decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})();
1
+ window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_limit__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"9.0.0",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse((new TextDecoder()).decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})();
2
2
 
3
- //# debugId=B9DC02765C7A5B6764756E2164756E21
3
+ //# debugId=69AACBBBCEE7711064756E2164756E21
4
4
  //# sourceMappingURL=pagy.min.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/pagy.ts"],
4
4
  "sourcesContent": [
5
- "type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll<NavElement>(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the items_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"8.6.3\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n"
5
+ "type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll<NavElement>(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the limit_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"9.0.0\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n"
6
6
  ],
7
7
  "mappings": "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",
8
- "debugId": "B9DC02765C7A5B6764756E2164756E21",
8
+ "debugId": "69AACBBBCEE7711064756E2164756E21",
9
9
  "names": []
10
10
  }
data/javascripts/pagy.mjs CHANGED
@@ -38,7 +38,7 @@ const Pagy = (() => {
38
38
  const initSelector = (el, [from, url_token, trimParam]) => {
39
39
  initInput(el, (inputValue) => {
40
40
  const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();
41
- const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);
41
+ const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);
42
42
  return [page, url];
43
43
  }, trimParam);
44
44
  };
@@ -73,7 +73,7 @@ const Pagy = (() => {
73
73
  };
74
74
  const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), "");
75
75
  return {
76
- version: "8.6.3",
76
+ version: "9.0.0",
77
77
  init(arg) {
78
78
  const target = arg instanceof Element ? arg : document;
79
79
  const elements = target.querySelectorAll("[data-pagy]");
data/lib/pagy/b64.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy # :nodoc:
4
+ # Cheap Base64 specialized methods to avoid dependencies
5
+ module B64
6
+ module_function
7
+
8
+ def encode(bin)
9
+ [bin].pack('m0')
10
+ end
11
+
12
+ def decode(str)
13
+ str.unpack1('m0')
14
+ end
15
+
16
+ def urlsafe_encode(bin)
17
+ str = encode(bin)
18
+ str.chomp!('==') or str.chomp!('=')
19
+ str.tr!('+/', '-_')
20
+ str
21
+ end
22
+
23
+ def urlsafe_decode(str)
24
+ if !str.end_with?('=') && str.length % 4 != 0
25
+ str = str.ljust((str.length + 3) & ~3, '=')
26
+ str.tr!('-_', '+/')
27
+ else
28
+ str = str.tr('-_', '+/')
29
+ end
30
+ decode(str)
31
+ end
32
+ end
33
+ end
data/lib/pagy/backend.rb CHANGED
@@ -8,37 +8,41 @@ class Pagy
8
8
  module Backend
9
9
  private
10
10
 
11
- # Return Pagy object and paginated items/results
12
- def pagy(collection, vars = {})
13
- pagy = Pagy.new(pagy_get_vars(collection, vars))
11
+ # Return Pagy object and paginated results
12
+ def pagy(collection, **vars)
13
+ pagy = Pagy.new(**pagy_get_vars(collection, vars))
14
14
  [pagy, pagy_get_items(collection, pagy)]
15
15
  end
16
16
 
17
- # Sub-method called only by #pagy: here for easy customization of variables by overriding
18
- # You may need to override the count call for non AR collections
19
- def pagy_get_vars(collection, vars)
20
- pagy_set_items_from_params(vars) if defined?(ItemsExtra)
21
- vars[:count] ||= pagy_get_count(collection, vars)
22
- vars[:page] ||= pagy_get_page(vars)
23
- vars
24
- end
25
-
26
17
  # Get the count from the collection
27
18
  def pagy_get_count(collection, vars)
28
19
  count_args = vars[:count_args] || DEFAULT[:count_args]
29
20
  (count = collection.count(*count_args)).is_a?(Hash) ? count.size : count
30
21
  end
31
22
 
23
+ # Sub-method called only by #pagy: here for easy customization of fetching by overriding
24
+ # You may need to override this method for collections without offset|limit
25
+ def pagy_get_items(collection, pagy)
26
+ collection.offset(pagy.offset).limit(pagy.limit)
27
+ end
28
+
29
+ # Override for limit extra
30
+ def pagy_get_limit(vars); end
31
+
32
32
  # Get the page integer from the params
33
33
  # Overridable by the jsonapi extra
34
34
  def pagy_get_page(vars)
35
- [params[vars[:page_param] || DEFAULT[:page_param]].to_i, 1].max
35
+ params[vars[:page_param] || DEFAULT[:page_param]]
36
36
  end
37
37
 
38
- # Sub-method called only by #pagy: here for easy customization of record-extraction by overriding
39
- # You may need to override this method for collections without offset|limit
40
- def pagy_get_items(collection, pagy)
41
- collection.offset(pagy.offset).limit(pagy.items)
38
+ # Sub-method called only by #pagy: here for easy customization of variables by overriding
39
+ # You may need to override the count call for non AR collections
40
+ def pagy_get_vars(collection, vars)
41
+ vars.tap do |v|
42
+ v[:count] ||= pagy_get_count(collection, v)
43
+ v[:limit] ||= pagy_get_limit(v)
44
+ v[:page] ||= pagy_get_page(v)
45
+ end
42
46
  end
43
47
  end
44
48
  end
@@ -13,7 +13,7 @@ class Pagy # :nodoc:
13
13
  protected
14
14
 
15
15
  # Setup the calendar variables
16
- def setup_unit_vars
16
+ def assign_unit_vars
17
17
  super
18
18
  @initial = @starting.beginning_of_day
19
19
  @final = @ending.tomorrow.beginning_of_day
@@ -13,7 +13,7 @@ class Pagy # :nodoc:
13
13
  protected
14
14
 
15
15
  # Setup the calendar variables
16
- def setup_unit_vars
16
+ def assign_unit_vars
17
17
  super
18
18
  @initial = @starting.beginning_of_month
19
19
  @final = @ending.next_month.beginning_of_month
@@ -20,7 +20,7 @@ class Pagy # :nodoc:
20
20
  protected
21
21
 
22
22
  # Setup the calendar variables
23
- def setup_unit_vars
23
+ def assign_unit_vars
24
24
  super
25
25
  @initial = @starting.beginning_of_quarter
26
26
  @final = @ending.next_quarter.beginning_of_quarter
@@ -13,18 +13,15 @@ class Pagy # :nodoc:
13
13
  attr_reader :order, :from, :to
14
14
 
15
15
  # Merge and validate the options, do some simple arithmetic and set a few instance variables
16
- def initialize(vars) # rubocop:disable Lint/MissingSuper
16
+ def initialize(**vars) # rubocop:disable Lint/MissingSuper
17
17
  raise InternalError, 'Pagy::Calendar::Unit is a base class; use one of its subclasses' \
18
18
  if instance_of?(Pagy::Calendar::Unit)
19
19
 
20
- vars = self.class::DEFAULT.merge(vars) # subclass specific default
21
- normalize_vars(vars) # general default
22
- setup_vars(page: 1)
23
- setup_unit_vars
24
- raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
25
-
26
- @prev = (@page - 1 unless @page == 1)
27
- @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
20
+ assign_vars({ **Pagy::DEFAULT, **self.class::DEFAULT }, vars)
21
+ assign_and_check(page: 1)
22
+ assign_unit_vars
23
+ check_overflow
24
+ assign_prev_and_next
28
25
  end
29
26
 
30
27
  # The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
@@ -63,7 +60,7 @@ class Pagy # :nodoc:
63
60
  end
64
61
 
65
62
  # Base class method for the setup of the unit variables (subclasses must implement it and call super)
66
- def setup_unit_vars
63
+ def assign_unit_vars
67
64
  raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
68
65
  raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
69
66
  unless %i[asc desc].include?(@order = @vars[:order])
@@ -11,7 +11,7 @@ class Pagy # :nodoc:
11
11
  protected
12
12
 
13
13
  # Setup the calendar variables
14
- def setup_unit_vars
14
+ def assign_unit_vars
15
15
  super
16
16
  @initial = @starting.beginning_of_week
17
17
  @final = @ending.next_week.beginning_of_week
@@ -13,7 +13,7 @@ class Pagy # :nodoc:
13
13
  protected
14
14
 
15
15
  # Setup the calendar variables
16
- def setup_unit_vars
16
+ def assign_unit_vars
17
17
  super
18
18
  @initial = @starting.beginning_of_year
19
19
  @final = @ending.next_year.beginning_of_year
data/lib/pagy/calendar.rb CHANGED
@@ -17,12 +17,12 @@ class Pagy # :nodoc:
17
17
  private
18
18
 
19
19
  # Create a unit subclass instance by using the unit name (internal use)
20
- def create(unit, vars)
20
+ def create(unit, **vars)
21
21
  raise InternalError, "unit must be in #{UNITS.inspect}; got #{unit}" unless UNITS.include?(unit)
22
22
 
23
23
  name = unit.to_s
24
24
  name[0] = name[0].capitalize
25
- Object.const_get("Pagy::Calendar::#{name}").new(vars)
25
+ Object.const_get("Pagy::Calendar::#{name}").new(**vars)
26
26
  end
27
27
 
28
28
  # Return calendar, from, to
@@ -58,7 +58,7 @@ class Pagy # :nodoc:
58
58
  params_to_delete = @units[(index + 1), @units.size].map { |sub| conf[sub][:page_param] } + [@page_param]
59
59
  conf[unit][:params] = lambda { |up| up.except(*params_to_delete.map(&:to_s)) } # rubocop:disable Style/Lambda
60
60
  conf[unit][:period] = object&.send(:active_period) || @period
61
- calendar[unit] = object = Calendar.send(:create, unit, conf[unit])
61
+ calendar[unit] = object = Calendar.send(:create, unit, **conf[unit])
62
62
  end
63
63
  [replace(calendar), object.from, object.to]
64
64
  end
@@ -70,10 +70,10 @@ class Pagy # :nodoc:
70
70
  @units.inject(nil) do |object, unit|
71
71
  conf[unit][:period] = object&.send(:active_period) || @period
72
72
  conf[unit][:page] = page_params[:"#{unit}_#{@page_param}"] \
73
- = Calendar.send(:create, unit, conf[unit]).send(:page_at, time, **opts)
73
+ = Calendar.send(:create, unit, **conf[unit]).send(:page_at, time, **opts)
74
74
  conf[unit][:params] ||= {}
75
75
  conf[unit][:params].merge!(page_params)
76
- Calendar.send(:create, unit, conf[unit])
76
+ Calendar.send(:create, unit, **conf[unit])
77
77
  end
78
78
  end
79
79
  end
@@ -1,32 +1,28 @@
1
1
  # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/countless
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../pagy'
5
-
6
4
  class Pagy # :nodoc:
7
5
  # No need to know the count to paginate
8
6
  class Countless < Pagy
9
7
  # Merge and validate the options, do some simple arithmetic and set a few instance variables
10
- def initialize(vars = {}) # rubocop:disable Lint/MissingSuper
11
- normalize_vars(vars)
12
- setup_vars(page: 1, outset: 0)
13
- setup_items_var
14
- setup_offset_var
8
+ def initialize(**vars) # rubocop:disable Lint/MissingSuper
9
+ assign_vars(DEFAULT, vars)
10
+ assign_and_check(page: 1, outset: 0)
11
+ assign_limit
12
+ assign_offset
15
13
  end
16
14
 
17
15
  # Finalize the instance variables based on the fetched size
18
16
  def finalize(fetched_size)
19
17
  raise OverflowError.new(self, :page, "to be < #{@page}", @page) if fetched_size.zero? && @page > 1
20
18
 
21
- @last = fetched_size > @items ? @page + 1 : @page
22
- @last = vars[:max_pages] if vars[:max_pages] && @last > vars[:max_pages]
23
- raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
24
-
25
- @in = [fetched_size, @items].min
19
+ @last = fetched_size > @limit ? @page + 1 : @page
20
+ @last = @vars[:max_pages] if @vars[:max_pages] && @last > @vars[:max_pages]
21
+ check_overflow
22
+ @in = [fetched_size, @limit].min
26
23
  @from = @in.zero? ? 0 : @offset - @outset + 1
27
24
  @to = @offset - @outset + @in
28
- @prev = (@page - 1 unless @page == 1)
29
- @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
25
+ assign_prev_and_next
30
26
  self
31
27
  end
32
28
  end
@@ -7,19 +7,11 @@ class Pagy # :nodoc:
7
7
  private
8
8
 
9
9
  # Return Pagy object and paginated collection/results
10
- def pagy_arel(collection, vars = {})
11
- pagy = Pagy.new(pagy_arel_get_vars(collection, vars))
10
+ def pagy_arel(collection, **vars)
11
+ pagy = Pagy.new(**pagy_arel_get_vars(collection, vars))
12
12
  [pagy, pagy_get_items(collection, pagy)]
13
13
  end
14
14
 
15
- # Sub-method called only by #pagy_arel: here for easy customization of variables by overriding
16
- def pagy_arel_get_vars(collection, vars)
17
- pagy_set_items_from_params(vars) if defined?(ItemsExtra)
18
- vars[:count] ||= pagy_arel_count(collection)
19
- vars[:page] ||= pagy_get_page(vars)
20
- vars
21
- end
22
-
23
15
  # Count using Arel when grouping
24
16
  def pagy_arel_count(collection)
25
17
  if collection.group_values.empty?
@@ -31,6 +23,12 @@ class Pagy # :nodoc:
31
23
  collection.unscope(:order).limit(1).pluck(sql).first.to_i
32
24
  end
33
25
  end
26
+
27
+ # Sub-method called only by #pagy_arel: here for easy customization of variables by overriding
28
+ def pagy_arel_get_vars(collection, vars)
29
+ vars[:count] ||= pagy_arel_count(collection)
30
+ pagy_get_vars(collection, vars)
31
+ end
34
32
  end
35
33
  Backend.prepend ArelExtra
36
34
  end
@@ -7,17 +7,15 @@ class Pagy # :nodoc:
7
7
  private
8
8
 
9
9
  # Return Pagy object and paginated items
10
- def pagy_array(array, vars = {})
11
- pagy = Pagy.new(pagy_array_get_vars(array, vars))
12
- [pagy, array[pagy.offset, pagy.items]]
10
+ def pagy_array(array, **vars)
11
+ pagy = Pagy.new(**pagy_array_get_vars(array, vars))
12
+ [pagy, array[pagy.offset, pagy.limit]]
13
13
  end
14
14
 
15
15
  # Sub-method called only by #pagy_array: here for easy customization of variables by overriding
16
16
  def pagy_array_get_vars(array, vars)
17
- pagy_set_items_from_params(vars) if defined?(ItemsExtra)
18
17
  vars[:count] ||= array.size
19
- vars[:page] ||= pagy_get_page(vars)
20
- vars
18
+ pagy_get_vars(array, vars)
21
19
  end
22
20
  end
23
21
  Backend.prepend ArrayExtra
@@ -10,7 +10,7 @@ class Pagy # :nodoc:
10
10
  # Pagination for bootstrap: it returns the html with the series of links to the pages
11
11
  def pagy_bootstrap_nav(pagy, id: nil, classes: 'pagination', aria_label: nil, **vars)
12
12
  id = %( id="#{id}") if id
13
- a = pagy_anchor(pagy)
13
+ a = pagy_anchor(pagy, **vars)
14
14
 
15
15
  html = %(<nav#{id} class="pagy-bootstrap nav" #{nav_aria_label(pagy, aria_label:)}><ul class="#{classes}">#{
16
16
  bootstrap_prev_html(pagy, a)})
@@ -34,7 +34,7 @@ class Pagy # :nodoc:
34
34
  def pagy_bootstrap_nav_js(pagy, id: nil, classes: 'pagination', aria_label: nil, **vars)
35
35
  sequels = pagy.sequels(**vars)
36
36
  id = %( id="#{id}") if id
37
- a = pagy_anchor(pagy)
37
+ a = pagy_anchor(pagy, **vars)
38
38
  tokens = { 'before' => %(<ul class="#{classes}">#{bootstrap_prev_html(pagy, a)}),
39
39
  'a' => %(<li class="page-item">#{a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'page-link')}</li>),
40
40
  'current' => %(<li class="page-item active"><a role="link" class="page-link" ) +
@@ -50,9 +50,9 @@ class Pagy # :nodoc:
50
50
  end
51
51
 
52
52
  # Javascript combo pagination for bootstrap: it returns a nav with a data-pagy attribute used by the pagy.js file
53
- def pagy_bootstrap_combo_nav_js(pagy, id: nil, classes: 'pagination', aria_label: nil)
53
+ def pagy_bootstrap_combo_nav_js(pagy, id: nil, classes: 'pagination', aria_label: nil, **vars)
54
54
  id = %( id="#{id}") if id
55
- a = pagy_anchor(pagy)
55
+ a = pagy_anchor(pagy, **vars)
56
56
  pages = pagy.pages
57
57
 
58
58
  page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) <<
@@ -61,7 +61,7 @@ class Pagy # :nodoc:
61
61
 
62
62
  %(<nav#{id} class="pagy-bootstrap combo-nav-js" #{
63
63
  nav_aria_label(pagy, aria_label:)} #{
64
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
64
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN, **vars))
65
65
  }><ul class="#{classes}">#{
66
66
  bootstrap_prev_html(pagy, a)
67
67
  }<li class="page-item pagy-bootstrap"><label class="page-link">#{
@@ -8,9 +8,10 @@ class Pagy # :nodoc:
8
8
  # The resulting code may not look very elegant, but produces the best benchmarks
9
9
  module BulmaExtra
10
10
  # Pagination for bulma: it returns the html with the series of links to the pages
11
- def pagy_bulma_nav(pagy, id: nil, classes: 'pagy-bulma nav pagination is-centered', aria_label: nil, **vars)
11
+ def pagy_bulma_nav(pagy, id: nil, classes: 'pagy-bulma nav pagination is-centered',
12
+ aria_label: nil, **vars)
12
13
  id = %( id="#{id}") if id
13
- a = pagy_anchor(pagy)
14
+ a = pagy_anchor(pagy, **vars)
14
15
 
15
16
  html = %(<nav#{id} class="#{classes}" #{nav_aria_label(pagy, aria_label:)}>)
16
17
  html << bulma_prev_next_html(pagy, a)
@@ -31,10 +32,11 @@ class Pagy # :nodoc:
31
32
  end
32
33
 
33
34
  # Javascript pagination for bulma: it returns a nav with a data-pagy attribute used by the Pagy.nav javascript
34
- def pagy_bulma_nav_js(pagy, id: nil, classes: 'pagy-bulma nav-js pagination is-centered', aria_label: nil, **vars)
35
+ def pagy_bulma_nav_js(pagy, id: nil, classes: 'pagy-bulma nav-js pagination is-centered',
36
+ aria_label: nil, **vars)
35
37
  sequels = pagy.sequels(**vars)
36
38
  id = %( id="#{id}") if id
37
- a = pagy_anchor(pagy)
39
+ a = pagy_anchor(pagy, **vars)
38
40
  tokens = { 'before' => %(#{bulma_prev_next_html(pagy, a)}<ul class="pagination-list">),
39
41
  'a' => %(<li>#{a.(PAGE_TOKEN, LABEL_TOKEN, classes: 'pagination-link')}</li>),
40
42
  'current' => %(<li><a role="link" class="pagination-link is-current" aria-current="page" aria-disabled="true">#{
@@ -49,9 +51,10 @@ class Pagy # :nodoc:
49
51
  end
50
52
 
51
53
  # Javascript combo pagination for bulma: it returns a nav with a data-pagy attribute used by the pagy.js file
52
- def pagy_bulma_combo_nav_js(pagy, id: nil, classes: 'pagy-bulma combo-nav-js pagination is-centered', aria_label: nil)
54
+ def pagy_bulma_combo_nav_js(pagy, id: nil, classes: 'pagy-bulma combo-nav-js pagination is-centered',
55
+ aria_label: nil, **vars)
53
56
  id = %( id="#{id}") if id
54
- a = pagy_anchor(pagy)
57
+ a = pagy_anchor(pagy, **vars)
55
58
  pages = pagy.pages
56
59
 
57
60
  page_input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page") <<
@@ -61,7 +64,7 @@ class Pagy # :nodoc:
61
64
 
62
65
  %(<nav#{id} class="#{classes}" #{
63
66
  nav_aria_label(pagy, aria_label:)} #{
64
- pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))
67
+ pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN, **vars))
65
68
  }>#{
66
69
  bulma_prev_next_html(pagy, a)
67
70
  }<ul class="pagination-list"><li class="pagination-link"><label>#{
@@ -27,7 +27,7 @@ class Pagy # :nodoc:
27
27
  end
28
28
  collection = pagy_calendar_filter(collection, from, to)
29
29
  end
30
- pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
30
+ pagy, results = send(conf[:pagy][:backend] || :pagy, collection, **conf[:pagy]) # use backend: :pagy when omitted
31
31
  [calendar, pagy, results]
32
32
  end
33
33
 
@@ -47,12 +47,11 @@ class Pagy # :nodoc:
47
47
  # Override the pagy_anchor
48
48
  module FrontendOverride
49
49
  # Consider the vars[:count]
50
- def pagy_anchor(pagy)
50
+ def pagy_anchor(pagy, anchor_string: nil)
51
51
  return super unless (counts = pagy.vars[:counts])
52
52
 
53
- a_string = pagy.vars[:anchor_string]
54
- a_string = %( #{a_string}) if a_string
55
- left, right = %(<a#{a_string} href="#{pagy_url_for(pagy, PAGE_TOKEN)}").split(PAGE_TOKEN, 2)
53
+ anchor_string &&= %( #{anchor_string})
54
+ left, right = %(<a#{anchor_string} href="#{pagy_url_for(pagy, PAGE_TOKEN)}").split(PAGE_TOKEN, 2)
56
55
  # lambda used by all the helpers
57
56
  lambda do |page, text = pagy.label_for(page), classes: nil, aria_label: nil|
58
57
  count = counts[page - 1]
@@ -10,27 +10,20 @@ class Pagy # :nodoc:
10
10
  module CountlessExtra
11
11
  private
12
12
 
13
- # Return Pagy object and items
14
- def pagy_countless(collection, vars = {})
15
- pagy = Countless.new(pagy_countless_get_vars(collection, vars))
13
+ # Return Pagy object and records
14
+ def pagy_countless(collection, **vars)
15
+ pagy = Countless.new(**pagy_get_vars(collection, vars))
16
16
  [pagy, pagy_countless_get_items(collection, pagy)]
17
17
  end
18
18
 
19
- # Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
20
- def pagy_countless_get_vars(_collection, vars)
21
- pagy_set_items_from_params(vars) if defined?(ItemsExtra)
22
- vars[:page] ||= pagy_get_page(vars)
23
- vars
24
- end
25
-
26
19
  # Sub-method called only by #pagy_countless: here for easy customization of record-extraction by overriding
27
20
  # You may need to override this method for collections without offset|limit
28
21
  def pagy_countless_get_items(collection, pagy)
29
- return collection.offset(pagy.offset).limit(pagy.items) if pagy.vars[:countless_minimal]
22
+ return collection.offset(pagy.offset).limit(pagy.limit) if pagy.vars[:countless_minimal]
30
23
 
31
- fetched = collection.offset(pagy.offset).limit(pagy.items + 1).to_a # eager load items + 1
24
+ fetched = collection.offset(pagy.offset).limit(pagy.limit + 1).to_a # eager load limit + 1
32
25
  pagy.finalize(fetched.size) # finalize the pagy object
33
- fetched[0, pagy.items] # ignore eventual extra item
26
+ fetched[0, pagy.limit] # ignore eventual extra item
34
27
  end
35
28
  end
36
29
  Backend.prepend CountlessExtra