pagy 9.2.1 → 9.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/apps/demo.ru CHANGED
@@ -19,7 +19,7 @@
19
19
  # URL
20
20
  # http://0.0.0.0:8000
21
21
 
22
- VERSION = '9.2.1'
22
+ VERSION = '9.2.2'
23
23
 
24
24
  # Bundle
25
25
  require 'bundler/inline'
@@ -31,7 +31,6 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
31
31
  gem 'puma'
32
32
  gem 'rouge'
33
33
  gem 'sinatra'
34
- gem 'sinatra-contrib'
35
34
  end
36
35
 
37
36
  # pagy initializer
@@ -52,10 +51,6 @@ require 'sinatra/base'
52
51
 
53
52
  # Sinatra application
54
53
  class PagyDemo < Sinatra::Base
55
- configure do
56
- enable :inline_templates
57
- end
58
-
59
54
  include Pagy::Backend
60
55
 
61
56
  get '/' do
@@ -84,7 +79,7 @@ class PagyDemo < Sinatra::Base
84
79
  send_file Pagy.root.join('stylesheets', params[:file])
85
80
  end
86
81
 
87
- # one route/action per style
82
+ # One route/action per style
88
83
  STYLES.each_key do |style|
89
84
  prefix = STYLES[style][:prefix] || "_#{style}"
90
85
 
@@ -119,6 +114,260 @@ class PagyDemo < Sinatra::Base
119
114
  }</pre></details>)
120
115
  end
121
116
  end
117
+
118
+ # Views
119
+ template :layout do
120
+ <<~'ERB'
121
+ <!DOCTYPE html>
122
+ <html lang="en">
123
+ <head>
124
+ <title>Pagy Demo App</title>
125
+ <script src="/javascripts/pagy.min.js"></script>
126
+ <script>
127
+ window.addEventListener("load", Pagy.init);
128
+ </script>
129
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
130
+ <%= erb :"#{style}_head" if defined?(style) %>
131
+ <style type="text/css">
132
+ @media screen { html, body {
133
+ font-size: 1rem;
134
+ line-height: 1.2s;
135
+ padding: 0;
136
+ margin: 0;
137
+ } }
138
+ body {
139
+ background: white !important;
140
+ margin: 0 !important;
141
+ font-family: sans-serif !important;
142
+ }
143
+ h1, h2 {
144
+ font-size: 1.8rem !important;
145
+ font-weight: 600 !important;
146
+ margin-top: 1rem !important;
147
+ margin-bottom: 0.7rem !important;
148
+ line-height: 1.5 !important;
149
+ color: rgb(90 90 90) !important;
150
+ }
151
+ h2 {
152
+ font-family: monospace;
153
+ font-size: .9rem !important;
154
+ margin-top: 1.6rem !important;
155
+ }
156
+ summary, .notes {
157
+ font-size: .8rem;
158
+ color: gray;
159
+ margin-top: .6rem;
160
+ font-style: italic;
161
+ cursor: pointer;
162
+ }
163
+ .notes {
164
+ font-family: sans-serif;
165
+ font-weight: normal;
166
+ }
167
+ .notes code{
168
+ background-color: #E8E8E8;
169
+ padding: 0 0.3rem;
170
+ font-style: normal;
171
+ border-radius: 3px;
172
+ }
173
+ .description {
174
+ margin: 1rem 0;
175
+ }
176
+ .description a {
177
+ color: blue;
178
+ text-decoration: underline;
179
+ }
180
+ pre, pre code {
181
+ display: block;
182
+ margin-top: .3rem;
183
+ margin-bottom: 1rem;
184
+ font-size: .8rem !important;
185
+ line-height: 1rem !important;
186
+ color: white;
187
+ background-color: rgb(30 30 30);
188
+ padding: 1rem;
189
+ overflow: auto;
190
+ }
191
+ .content {
192
+ padding: 0 1.5rem 2rem !important;
193
+ }
194
+
195
+ #style-menu {
196
+ flex;
197
+ font-family: sans-serif;
198
+ font-size: 1.1rem;
199
+ line-height: 1.5rem;
200
+ white-space: nowrap;
201
+ color: white;
202
+ background-color: gray;
203
+ padding: .2rem 1.5rem;
204
+ }
205
+ #style-menu > :not([hidden]) ~ :not([hidden]) {
206
+ --space-reverse: 0;
207
+ margin-right: calc(0.5rem * var(--space-reverse));
208
+ margin-left: calc(0.5rem * calc(1 - var(--space-reverse)));
209
+ }
210
+ #style-menu a {
211
+ color: inherit;
212
+ text-decoration: none;
213
+ }
214
+ /* Quick demo for overriding the element style attribute of certain pagy helpers
215
+ .pagy input[style] {
216
+ width: 5rem !important;
217
+ }
218
+ */
219
+ </style>
220
+ </head>
221
+ <body>
222
+ <!-- each different class used by each style -->
223
+ <%= style_menu %>
224
+ <div class="content">
225
+ <%= yield %>
226
+ </div>
227
+ </body>
228
+ </html>
229
+ ERB
230
+ end
231
+
232
+ template :pagy_head do
233
+ <<~ERB
234
+ <!-- copy and paste the pagy style in order to edit it -->
235
+ <link rel="stylesheet" href="/stylesheets/pagy.css">
236
+ ERB
237
+ end
238
+
239
+ template :bootstrap_head do
240
+ <<~ERB
241
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
242
+ ERB
243
+ end
244
+
245
+ template :bulma_head do
246
+ <<~ERB
247
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
248
+ ERB
249
+ end
250
+
251
+ template :tailwind_head do
252
+ <<~ERB
253
+ <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script>
254
+ <!-- copy and paste the pagy.tailwind style in order to edit it -->
255
+ <style type="text/tailwindcss">
256
+ <%= Pagy.root.join('stylesheets', 'pagy.tailwind.css').read %>
257
+ </style>
258
+ ERB
259
+ end
260
+
261
+ template :helpers do
262
+ <<~'ERB'
263
+ <h1><%= style %></h1>
264
+ <% extra = STYLES[style][:extra] || "#{style}" %>
265
+ <% css_anchor = STYLES[style][:css_anchor] %>
266
+
267
+ <p class="description">See the <a href="http://ddnexus.github.io/pagy/docs/extras/<%= extra %>" target="blank"><%= extra %> extra</a>
268
+ documentation
269
+ <% if css_anchor %>
270
+ and the <a href="http://ddnexus.github.io/pagy/docs/api/stylesheets/#<%= css_anchor %>" target="blank"><%= css_anchor.gsub('-', '.') %></a>
271
+ <% end %>
272
+ for details</p>
273
+
274
+ <h2>Collection</h2>
275
+ <p id="records">@records: <%= @records.join(',') %></p>
276
+
277
+ <h2>pagy<%= prefix %>_nav <span class="notes">Simple nav <code>size: 5</code></span></h2>
278
+ <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'simple-nav', aria_label: 'Pages simple-nav', size: 5) %>
279
+ <%= highlight(html) %>
280
+
281
+ <h2>pagy<%= prefix %>_nav <span class="notes">Fast nav <code>size: 7</code></span></h2>
282
+ <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'nav', aria_label: 'Pages nav') %>
283
+ <%= highlight(html) %>
284
+
285
+ <h2>pagy<%= prefix %>_nav_js <span class="notes">Fast nav <code>size: 7</code></span></h2>
286
+ <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
287
+ <%= highlight(html) %>
288
+
289
+ <h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive nav <code>steps: {...}</code> (Resize the window to see)</span></h2>
290
+ <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js-responsive',
291
+ aria_label: 'Pages nav_js_responsive',
292
+ steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
293
+ <%= highlight(html) %>
294
+
295
+ <h2>pagy<%= prefix %>_combo_nav_js</h2>
296
+ <%= html = send(:"pagy#{prefix}_combo_nav_js", @pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
297
+ <%= highlight(html) %>
298
+
299
+ <h2>pagy_info</h2>
300
+ <%= html = pagy_info(@pagy, id: 'pagy-info') %>
301
+ <%= highlight(html) %>
302
+
303
+ <% if style.match(/pagy|tailwind/) %>
304
+ <h2>pagy_limit_selector_js</h2>
305
+ <%= html = pagy_limit_selector_js(@pagy, id: 'limit-selector-js') %>
306
+ <%= highlight(html) %>
307
+
308
+ <h2>pagy_prev_a / pagy_next_a</h2>
309
+ <%= html = '<nav class="pagy" id="prev-next" aria-label="Pagy prev-next">' << pagy_prev_a(@pagy) << pagy_next_a(@pagy) << '</nav>' %>
310
+ <%= highlight(html) %>
311
+
312
+ <h2>pagy_prev_link / pagy_next_link <span class="notes">Link not rendered<span></h2>
313
+ <% html = '<head>' << (pagy_prev_link(@pagy)||'') << (pagy_next_link(@pagy)||'') << '</head>' %>
314
+ <%= highlight(html) %>
315
+ <% end %>
316
+ ERB
317
+ end
318
+
319
+ template :template do
320
+ <<~ERB
321
+ <h1>Pagy Template Demo</h1>
322
+
323
+ <p class="description">
324
+ See the <a href="https://ddnexus.github.io/pagy/docs/how-to/#using-your-pagination-templates">
325
+ Custom Templates</a> documentation.
326
+ </p>
327
+ <h2>Collection</h2>
328
+ <p id="records">@records: <%= @records.join(',') %></p>
329
+
330
+ <h2>Rendered ERB template</h2>
331
+
332
+ <%# We don't inline the template here, so we can highlight it more easily %>
333
+ <%= html = ERB.new(TEMPLATE).result(binding) %>
334
+ <%= highlight(TEMPLATE, format: :erb) %>
335
+ <%= highlight(html) %>
336
+ ERB
337
+ end
338
+
339
+ # Easier code highlighting
340
+ TEMPLATE = <<~ERB
341
+ <%# IMPORTANT: replace '<%=' with '<%==' if you run this in rails %>
342
+
343
+ <%# The a variable below is set to a lambda that generates the a tag %>
344
+ <%# Usage: a_tag = a.(page_number, text, classes: nil, aria_label: nil) %>
345
+ <% a = pagy_anchor(pagy) %>
346
+ <nav class="pagy nav" aria-label="Pages">
347
+ <%# Previous page link %>
348
+ <% if pagy.prev %>
349
+ <%= a.(pagy.prev, '&lt;', aria_label: 'Previous') %>
350
+ <% else %>
351
+ <a role="link" aria-disabled="true" aria-label="Previous">&lt;</a>
352
+ <% end %>
353
+ <%# Page links (series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]) %>
354
+ <% pagy.series.each do |item| %>
355
+ <% if item.is_a?(Integer) %>
356
+ <%= a.(item) %>
357
+ <% elsif item.is_a?(String) %>
358
+ <a role="link" aria-disabled="true" aria-current="page" class="current"><%= item %></a>
359
+ <% elsif item == :gap %>
360
+ <a role="link" aria-disabled="true" class="gap">&hellip;</a>
361
+ <% end %>
362
+ <% end %>
363
+ <%# Next page link %>
364
+ <% if pagy.next %>
365
+ <%= a.(pagy.next, '&gt;', aria_label: 'Next') %>
366
+ <% else %>
367
+ <a role="link" aria-disabled="true" aria-label="Next">&lt;</a>
368
+ <% end %>
369
+ </nav>
370
+ ERB
122
371
  end
123
372
 
124
373
  # Cheap pagy formatter for helpers output
@@ -198,240 +447,3 @@ class MockCollection < Array
198
447
  end
199
448
 
200
449
  run PagyDemo
201
-
202
- # We store the template in a constant instead of writing it inline, so we can highlight it more easily
203
- TEMPLATE = <<~ERB
204
- <%# IMPORTANT: use '<%== ... ' instead of '<%= ... ' if you run this in rails %>
205
-
206
- <%# The a variable below is set to a lambda that generates the a tag %>
207
- <%# Usage: a_tag = a.(page_number, text, classes: nil, aria_label: nil) %>
208
- <% a = pagy_anchor(pagy) %>
209
- <nav class="pagy nav" aria-label="Pages">
210
- <%# Previous page link %>
211
- <% if pagy.prev %>
212
- <%= a.(pagy.prev, '&lt;', aria_label: 'Previous') %>
213
- <% else %>
214
- <a role="link" aria-disabled="true" aria-label="Previous">&lt;</a>
215
- <% end %>
216
- <%# Page links (series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]) %>
217
- <% pagy.series.each do |item| %>
218
- <% if item.is_a?(Integer) %>
219
- <%= a.(item) %>
220
- <% elsif item.is_a?(String) %>
221
- <a role="link" aria-disabled="true" aria-current="page" class="current"><%= item %></a>
222
- <% elsif item == :gap %>
223
- <a role="link" aria-disabled="true" class="gap">&hellip;</a>
224
- <% end %>
225
- <% end %>
226
- <%# Next page link %>
227
- <% if pagy.next %>
228
- <%= a.(pagy.next, '&gt;', aria_label: 'Next') %>
229
- <% else %>
230
- <a role="link" aria-disabled="true" aria-label="Next">&lt;</a>
231
- <% end %>
232
- </nav>
233
- ERB
234
-
235
- __END__
236
-
237
- @@ layout
238
- <!DOCTYPE html>
239
- <html lang="en">
240
- <head>
241
- <title>Pagy Demo App</title>
242
- <script src="/javascripts/pagy.min.js"></script>
243
- <script>
244
- window.addEventListener("load", Pagy.init);
245
- </script>
246
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
247
- <%= erb :"#{style}_head" if defined?(style) %>
248
- <style type="text/css">
249
- @media screen { html, body {
250
- font-size: 1rem;
251
- line-height: 1.2s;
252
- padding: 0;
253
- margin: 0;
254
- } }
255
- body {
256
- background: white !important;
257
- margin: 0 !important;
258
- font-family: sans-serif !important;
259
- }
260
- h1, h2 {
261
- font-size: 1.8rem !important;
262
- font-weight: 600 !important;
263
- margin-top: 1rem !important;
264
- margin-bottom: 0.7rem !important;
265
- line-height: 1.5 !important;
266
- color: rgb(90 90 90) !important;
267
- }
268
- h2 {
269
- font-family: monospace;
270
- font-size: .9rem !important;
271
- margin-top: 1.6rem !important;
272
- }
273
- summary, .notes {
274
- font-size: .8rem;
275
- color: gray;
276
- margin-top: .6rem;
277
- font-style: italic;
278
- cursor: pointer;
279
- }
280
- .notes {
281
- font-family: sans-serif;
282
- font-weight: normal;
283
- }
284
- .notes code{
285
- background-color: #E8E8E8;
286
- padding: 0 0.3rem;
287
- font-style: normal;
288
- border-radius: 3px;
289
- }
290
- .description {
291
- margin: 1rem 0;
292
- }
293
- .description a {
294
- color: blue;
295
- text-decoration: underline;
296
- }
297
- pre, pre code {
298
- display: block;
299
- margin-top: .3rem;
300
- margin-bottom: 1rem;
301
- font-size: .8rem !important;
302
- line-height: 1rem !important;
303
- color: white;
304
- background-color: rgb(30 30 30);
305
- padding: 1rem;
306
- overflow: auto;
307
- }
308
- .content {
309
- padding: 0 1.5rem 2rem !important;
310
- }
311
-
312
- #style-menu {
313
- flex;
314
- font-family: sans-serif;
315
- font-size: 1.1rem;
316
- line-height: 1.5rem;
317
- white-space: nowrap;
318
- color: white;
319
- background-color: gray;
320
- padding: .2rem 1.5rem;
321
- }
322
- #style-menu > :not([hidden]) ~ :not([hidden]) {
323
- --space-reverse: 0;
324
- margin-right: calc(0.5rem * var(--space-reverse));
325
- margin-left: calc(0.5rem * calc(1 - var(--space-reverse)));
326
- }
327
- #style-menu a {
328
- color: inherit;
329
- text-decoration: none;
330
- }
331
- /* Quick demo for overriding the element style attribute of certain pagy helpers
332
- .pagy input[style] {
333
- width: 5rem !important;
334
- }
335
- */
336
- </style>
337
- </head>
338
- <body>
339
- <!-- each different class used by each style -->
340
- <%= style_menu %>
341
- <div class="content">
342
- <%= yield %>
343
- </div>
344
- </body>
345
- </html>
346
-
347
-
348
- @@ pagy_head
349
- <!-- copy and paste the pagy style in order to edit it -->
350
- <link rel="stylesheet" href="/stylesheets/pagy.css">
351
-
352
- @@ bootstrap_head
353
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
354
-
355
- @@ bulma_head
356
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
357
-
358
- @@ tailwind_head
359
- <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script>
360
- <!-- copy and paste the pagy.tailwind style in order to edit it -->
361
- <style type="text/tailwindcss">
362
- <%= Pagy.root.join('stylesheets', 'pagy.tailwind.css').read %>
363
- </style>
364
-
365
-
366
- @@ helpers
367
- <h1><%= style %></h1>
368
- <% extra = STYLES[style][:extra] || "#{style}" %>
369
- <% css_anchor = STYLES[style][:css_anchor] %>
370
-
371
- <p class="description">See the <a href="http://ddnexus.github.io/pagy/docs/extras/<%= extra %>" target="blank"><%= extra %> extra</a>
372
- documentation
373
- <% if css_anchor %>
374
- and the <a href="http://ddnexus.github.io/pagy/docs/api/stylesheets/#<%= css_anchor %>" target="blank"><%= css_anchor.gsub('-', '.') %></a>
375
- <% end %>
376
- for details</p>
377
-
378
- <h2>Collection</h2>
379
- <p id="records">@records: <%= @records.join(',') %></p>
380
-
381
- <h2>pagy<%= prefix %>_nav <span class="notes">Simple nav <code>size: 5</code></span></h2>
382
- <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'simple-nav', aria_label: 'Pages simple-nav', size: 5) %>
383
- <%= highlight(html) %>
384
-
385
- <h2>pagy<%= prefix %>_nav <span class="notes">Fast nav <code>size: 7</code></span></h2>
386
- <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'nav', aria_label: 'Pages nav') %>
387
- <%= highlight(html) %>
388
-
389
- <h2>pagy<%= prefix %>_nav_js <span class="notes">Fast nav <code>size: 7</code></span></h2>
390
- <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
391
- <%= highlight(html) %>
392
-
393
- <h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive nav <code>steps: {...}</code> (Resize the window to see)</span></h2>
394
- <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js-responsive',
395
- aria_label: 'Pages nav_js_responsive',
396
- steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
397
- <%= highlight(html) %>
398
-
399
- <h2>pagy<%= prefix %>_combo_nav_js</h2>
400
- <%= html = send(:"pagy#{prefix}_combo_nav_js", @pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
401
- <%= highlight(html) %>
402
-
403
- <h2>pagy_info</h2>
404
- <%= html = pagy_info(@pagy, id: 'pagy-info') %>
405
- <%= highlight(html) %>
406
-
407
- <% if style.match(/pagy|tailwind/) %>
408
- <h2>pagy_limit_selector_js</h2>
409
- <%= html = pagy_limit_selector_js(@pagy, id: 'limit-selector-js') %>
410
- <%= highlight(html) %>
411
-
412
- <h2>pagy_prev_a / pagy_next_a</h2>
413
- <%= html = '<nav class="pagy" id="prev-next" aria-label="Pagy prev-next">' << pagy_prev_a(@pagy) << pagy_next_a(@pagy) << '</nav>' %>
414
- <%= highlight(html) %>
415
-
416
- <h2>pagy_prev_link / pagy_next_link <span class="notes">Link not rendered<span></h2>
417
- <% html = '<head>' << (pagy_prev_link(@pagy)||'') << (pagy_next_link(@pagy)||'') << '</head>' %>
418
- <%= highlight(html) %>
419
- <% end %>
420
-
421
-
422
- @@ template
423
- <h1>Pagy Template Demo</h1>
424
-
425
- <p class="description">
426
- See the <a href="https://ddnexus.github.io/pagy/docs/how-to/#using-your-pagination-templates">
427
- Custom Templates</a> documentation.
428
- </p>
429
- <h2>Collection</h2>
430
- <p id="records">@records: <%= @records.join(',') %></p>
431
-
432
- <h2>Rendered ERB template</h2>
433
-
434
- <%# We don't inline the template here, so we can highlight it more easily %>
435
- <%= html = ERB.new(TEMPLATE).result(binding) %>
436
- <%= highlight(TEMPLATE, format: :erb) %>
437
- <%= highlight(html) %>
data/apps/index.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # PagyApp module
4
+ module PagyApps
5
+ # Return the hash of app name/path
6
+ INDEX = Dir[File.expand_path('./*.ru', __dir__)].to_h { |f| [File.basename(f, '.ru'), f] }.freeze
7
+ end