pagy 8.4.0 → 9.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/apps/calendar.ru +682 -2137
- data/apps/demo.ru +17 -13
- data/apps/keyset_ar.ru +236 -0
- data/apps/keyset_s.ru +238 -0
- data/apps/rails.ru +25 -15
- data/apps/repro.ru +17 -14
- data/bin/pagy +17 -12
- data/config/pagy.rb +37 -34
- data/javascripts/pagy.min.js +4 -0
- data/javascripts/pagy.min.js.map +10 -0
- data/javascripts/pagy.mjs +100 -0
- data/lib/optimist.rb +1 -1
- data/lib/pagy/b64.rb +33 -0
- data/lib/pagy/backend.rb +19 -19
- data/lib/pagy/calendar/day.rb +4 -3
- data/lib/pagy/calendar/month.rb +4 -3
- data/lib/pagy/calendar/quarter.rb +4 -3
- data/lib/pagy/calendar/unit.rb +103 -0
- data/lib/pagy/calendar/week.rb +3 -3
- data/lib/pagy/calendar/year.rb +4 -3
- data/lib/pagy/calendar.rb +54 -97
- data/lib/pagy/countless.rb +15 -16
- data/lib/pagy/extras/arel.rb +3 -11
- data/lib/pagy/extras/array.rb +5 -10
- data/lib/pagy/extras/bootstrap.rb +5 -5
- data/lib/pagy/extras/bulma.rb +10 -7
- data/lib/pagy/extras/calendar.rb +34 -5
- data/lib/pagy/extras/countless.rb +8 -13
- data/lib/pagy/extras/elasticsearch_rails.rb +16 -25
- data/lib/pagy/extras/gearbox.rb +26 -26
- data/lib/pagy/extras/headers.rb +25 -24
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/js_tools.rb +10 -10
- data/lib/pagy/extras/jsonapi.rb +26 -19
- data/lib/pagy/extras/keyset.rb +30 -0
- data/lib/pagy/extras/limit.rb +63 -0
- data/lib/pagy/extras/meilisearch.rb +9 -17
- data/lib/pagy/extras/metadata.rb +6 -2
- data/lib/pagy/extras/overflow.rb +11 -10
- data/lib/pagy/extras/pagy.rb +16 -16
- data/lib/pagy/extras/searchkick.rb +9 -17
- data/lib/pagy/extras/size.rb +40 -0
- data/lib/pagy/extras/standalone.rb +6 -6
- data/lib/pagy/extras/trim.rb +3 -3
- data/lib/pagy/frontend.rb +37 -35
- data/lib/pagy/i18n.rb +2 -2
- data/lib/pagy/keyset/active_record.rb +38 -0
- data/lib/pagy/keyset/sequel.rb +51 -0
- data/lib/pagy/keyset.rb +98 -0
- data/lib/pagy/shared_methods.rb +27 -0
- data/lib/pagy/url_helpers.rb +5 -5
- data/lib/pagy.rb +70 -94
- data/locales/ar.yml +9 -10
- data/locales/be.yml +2 -2
- data/locales/bg.yml +2 -2
- data/locales/bs.yml +2 -2
- data/locales/ca.yml +5 -7
- data/locales/ckb.yml +2 -2
- data/locales/cs.yml +2 -2
- data/locales/da.yml +2 -2
- data/locales/de.yml +2 -2
- data/locales/en.yml +2 -2
- data/locales/es.yml +2 -2
- data/locales/fr.yml +2 -2
- data/locales/hr.yml +2 -2
- data/locales/id.yml +2 -2
- data/locales/it.yml +2 -2
- data/locales/ja.yml +2 -2
- data/locales/km.yml +2 -2
- data/locales/ko.yml +2 -2
- data/locales/nb.yml +2 -2
- data/locales/nl.yml +2 -2
- data/locales/nn.yml +2 -2
- data/locales/pl.yml +2 -2
- data/locales/pt-BR.yml +2 -2
- data/locales/pt.yml +2 -2
- data/locales/ru.yml +2 -2
- data/locales/sr.yml +2 -2
- data/locales/sv-SE.yml +2 -2
- data/locales/sv.yml +2 -2
- data/locales/sw.yml +2 -2
- data/locales/ta.yml +2 -2
- data/locales/tr.yml +2 -2
- data/locales/uk.yml +2 -2
- data/locales/vi.yml +2 -2
- data/locales/zh-CN.yml +2 -2
- data/locales/zh-HK.yml +2 -2
- data/locales/zh-TW.yml +2 -2
- metadata +19 -19
- data/javascripts/pagy-dev.js +0 -114
- data/javascripts/pagy-module.js +0 -113
- data/javascripts/pagy.js +0 -1
- data/lib/pagy/calendar/helper.rb +0 -65
- data/lib/pagy/extras/foundation.rb +0 -95
- data/lib/pagy/extras/items.rb +0 -64
- data/lib/pagy/extras/materialize.rb +0 -100
- data/lib/pagy/extras/semantic.rb +0 -94
- data/lib/pagy/extras/uikit.rb +0 -98
- /data/javascripts/{pagy-module.d.ts → pagy.d.ts} +0 -0
data/apps/demo.ru
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# DOC
|
19
19
|
# https://ddnexus.github.io/pagy/playground/#3-demo-app
|
20
20
|
|
21
|
-
VERSION = '
|
21
|
+
VERSION = '9.0.9'
|
22
22
|
|
23
23
|
require 'bundler/inline'
|
24
24
|
require 'bundler'
|
@@ -41,10 +41,9 @@ STYLES = { pagy: { extra: 'pagy', prefix: '', css_anchor: 'pagy-scss' },
|
|
41
41
|
STYLES.each_key do |style|
|
42
42
|
require "pagy/extras/#{STYLES[style][:extra] || style}"
|
43
43
|
end
|
44
|
-
require 'pagy/extras/
|
44
|
+
require 'pagy/extras/limit'
|
45
45
|
require 'pagy/extras/trim'
|
46
46
|
Pagy::DEFAULT[:trim_extra] = false # opt-in trim
|
47
|
-
Pagy::DEFAULT[:size] = [1, 4, 4, 1] # old size default
|
48
47
|
|
49
48
|
# sinatra setup
|
50
49
|
require 'sinatra/base'
|
@@ -69,7 +68,12 @@ class PagyDemo < Sinatra::Base
|
|
69
68
|
end
|
70
69
|
|
71
70
|
get('/javascripts/:file') do
|
72
|
-
|
71
|
+
format = params[:file].split('.').last
|
72
|
+
if format == 'js'
|
73
|
+
content_type 'application/javascript'
|
74
|
+
elsif format == 'map'
|
75
|
+
content_type 'application/json'
|
76
|
+
end
|
73
77
|
send_file Pagy.root.join('javascripts', params[:file])
|
74
78
|
end
|
75
79
|
|
@@ -233,7 +237,7 @@ __END__
|
|
233
237
|
<html lang="en">
|
234
238
|
<head>
|
235
239
|
<title>Pagy Demo App</title>
|
236
|
-
<script src="
|
240
|
+
<script src="/javascripts/pagy.min.js"></script>
|
237
241
|
<script>
|
238
242
|
window.addEventListener("load", Pagy.init);
|
239
243
|
</script>
|
@@ -242,7 +246,7 @@ __END__
|
|
242
246
|
<style type="text/css">
|
243
247
|
@media screen { html, body {
|
244
248
|
font-size: 1rem;
|
245
|
-
line-
|
249
|
+
line-height: 1.2s;
|
246
250
|
padding: 0;
|
247
251
|
margin: 0;
|
248
252
|
} }
|
@@ -293,7 +297,7 @@ __END__
|
|
293
297
|
margin-top: .3rem;
|
294
298
|
margin-bottom: 1rem;
|
295
299
|
font-size: .8rem !important;
|
296
|
-
line-
|
300
|
+
line-height: 1rem !important;
|
297
301
|
color: white;
|
298
302
|
background-color: rgb(30 30 30);
|
299
303
|
padding: 1rem;
|
@@ -376,18 +380,18 @@ for details</p>
|
|
376
380
|
<%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'simple-nav', aria_label: 'Pages simple-nav', size: 5) %>
|
377
381
|
<%= highlight(html) %>
|
378
382
|
|
379
|
-
<h2>pagy<%= prefix %>_nav <span class="notes">
|
383
|
+
<h2>pagy<%= prefix %>_nav <span class="notes">Fast nav <code>size: 7</code></span></h2>
|
380
384
|
<%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'nav', aria_label: 'Pages nav') %>
|
381
385
|
<%= highlight(html) %>
|
382
386
|
|
383
|
-
<h2>pagy<%= prefix %>_nav_js <span class="notes">
|
387
|
+
<h2>pagy<%= prefix %>_nav_js <span class="notes">Fast nav <code>size: 7</code></span></h2>
|
384
388
|
<%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
|
385
389
|
<%= highlight(html) %>
|
386
390
|
|
387
|
-
<h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive <code>steps: {...}</code> (Resize the window to see)</span></h2>
|
391
|
+
<h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive nav <code>steps: {...}</code> (Resize the window to see)</span></h2>
|
388
392
|
<%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js-responsive',
|
389
393
|
aria_label: 'Pages nav_js_responsive',
|
390
|
-
steps: { 0 =>
|
394
|
+
steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
|
391
395
|
<%= highlight(html) %>
|
392
396
|
|
393
397
|
<h2>pagy<%= prefix %>_combo_nav_js</h2>
|
@@ -399,8 +403,8 @@ for details</p>
|
|
399
403
|
<%= highlight(html) %>
|
400
404
|
|
401
405
|
<% if style.match(/pagy|tailwind/) %>
|
402
|
-
<h2>
|
403
|
-
<%= html =
|
406
|
+
<h2>pagy_limit_selector_js</h2>
|
407
|
+
<%= html = pagy_limit_selector_js(@pagy, id: 'limit-selector-js') %>
|
404
408
|
<%= highlight(html) %>
|
405
409
|
|
406
410
|
<h2>pagy_prev_a / pagy_next_a</h2>
|
data/apps/keyset_ar.ru
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Starting point to reproduce keyset related pagy issues
|
4
|
+
|
5
|
+
# DEV USAGE
|
6
|
+
# pagy clone rails
|
7
|
+
# pagy ./keyset.ru
|
8
|
+
|
9
|
+
# URL
|
10
|
+
# http://0.0.0.0:8000
|
11
|
+
|
12
|
+
# HELP
|
13
|
+
# pagy -h
|
14
|
+
|
15
|
+
# DOC
|
16
|
+
# https://ddnexus.github.io/pagy/playground/#5-keyset-app
|
17
|
+
|
18
|
+
VERSION = '8.6.2'
|
19
|
+
|
20
|
+
# Gemfile
|
21
|
+
require 'bundler/inline'
|
22
|
+
require 'bundler'
|
23
|
+
Bundler.configure
|
24
|
+
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
25
|
+
source 'https://rubygems.org'
|
26
|
+
gem 'oj'
|
27
|
+
gem 'puma'
|
28
|
+
gem 'rails'
|
29
|
+
# activerecord/sqlite3_adapter.rb probably useless) constraint !!!
|
30
|
+
# https://github.com/rails/rails/blame/v7.1.3.4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
|
31
|
+
gem 'sqlite3', '~> 1.4.0'
|
32
|
+
end
|
33
|
+
|
34
|
+
# require 'rails/all' # too much stuff
|
35
|
+
require 'action_controller/railtie'
|
36
|
+
require 'active_record'
|
37
|
+
|
38
|
+
OUTPUT = Rails.env.showcase? ? IO::NULL : $stdout
|
39
|
+
|
40
|
+
# Rails config
|
41
|
+
class PagyKeyset < Rails::Application # :nodoc:
|
42
|
+
config.root = __dir__
|
43
|
+
config.session_store :cookie_store, key: 'cookie_store_key'
|
44
|
+
Rails.application.credentials.secret_key_base = 'absolute_secret'
|
45
|
+
|
46
|
+
config.logger = Logger.new(OUTPUT)
|
47
|
+
Rails.logger = config.logger
|
48
|
+
|
49
|
+
routes.draw do
|
50
|
+
root to: 'pets#index'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
55
|
+
unless File.writable?(dir)
|
56
|
+
warn "ERROR: directory #{dir.inspect} is not writable (the pagy-rails-app needs to create DB files)"
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
# Pagy initializer
|
61
|
+
require 'pagy/extras/pagy'
|
62
|
+
require 'pagy/extras/limit'
|
63
|
+
require 'pagy/extras/keyset'
|
64
|
+
Pagy::DEFAULT[:limit] = 10
|
65
|
+
Pagy::DEFAULT.freeze
|
66
|
+
|
67
|
+
PETS = <<~PETS
|
68
|
+
Luna | dog | 2018-03-10
|
69
|
+
Coco | cat | 2019-05-15
|
70
|
+
Dodo | dog | 2020-06-25
|
71
|
+
Wiki | bird | 2018-03-12
|
72
|
+
Baby | rabbit | 2020-01-13
|
73
|
+
Neki | horse | 2021-07-20
|
74
|
+
Tino | donkey | 2019-06-18
|
75
|
+
Plot | cat | 2022-09-21
|
76
|
+
Riki | cat | 2018-09-14
|
77
|
+
Susi | horse | 2018-10-26
|
78
|
+
Coco | pig | 2020-08-29
|
79
|
+
Momo | bird | 2023-08-25
|
80
|
+
Lili | cat | 2021-07-22
|
81
|
+
Beli | pig | 2020-07-26
|
82
|
+
Rocky | bird | 2022-08-19
|
83
|
+
Vyvy | dog | 2018-05-16
|
84
|
+
Susi | horse | 2024-01-25
|
85
|
+
Ella | cat | 2020-02-20
|
86
|
+
Rocky | dog | 2019-09-19
|
87
|
+
Juni | rabbit | 2020-08-24
|
88
|
+
Coco | bird | 2021-03-17
|
89
|
+
Susi | dog | 2021-07-28
|
90
|
+
Luna | horse | 2023-05-14
|
91
|
+
Gigi | pig | 2022-05-19
|
92
|
+
Coco | cat | 2020-02-20
|
93
|
+
Nino | donkey | 2019-06-17
|
94
|
+
Luna | cat | 2022-02-09
|
95
|
+
Popi | dog | 2020-09-26
|
96
|
+
Lili | pig | 2022-06-18
|
97
|
+
Mina | horse | 2021-04-21
|
98
|
+
Susi | rabbit | 2023-05-18
|
99
|
+
Toni | donkey | 2018-06-22
|
100
|
+
Rocky | horse | 2019-09-28
|
101
|
+
Lili | cat | 2019-03-18
|
102
|
+
Roby | cat | 2022-06-19
|
103
|
+
Anto | horse | 2022-08-18
|
104
|
+
Susi | pig | 2021-04-21
|
105
|
+
Boly | bird | 2020-03-29
|
106
|
+
Sky | cat | 2023-07-19
|
107
|
+
Lili | dog | 2020-01-28
|
108
|
+
Fami | snake | 2023-04-27
|
109
|
+
Lopi | pig | 2019-06-19
|
110
|
+
Rocky | snake | 2022-03-13
|
111
|
+
Denis | dog | 2022-06-19
|
112
|
+
Maca | cat | 2022-06-19
|
113
|
+
Luna | dog | 2022-08-15
|
114
|
+
Jeme | horse | 2019-08-08
|
115
|
+
Sary | bird | 2023-04-29
|
116
|
+
Rocky | bird | 2023-05-14
|
117
|
+
Coco | dog | 2023-05-27
|
118
|
+
PETS
|
119
|
+
|
120
|
+
# Activerecord initializer
|
121
|
+
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
122
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-keyset-ar.sqlite3")
|
123
|
+
ActiveRecord::Schema.define do
|
124
|
+
create_table :pets, force: true do |t|
|
125
|
+
t.string :animal
|
126
|
+
t.string :name
|
127
|
+
t.date :birthdate
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Models
|
132
|
+
class Pet < ActiveRecord::Base
|
133
|
+
end
|
134
|
+
|
135
|
+
# DB seed
|
136
|
+
pets = []
|
137
|
+
PETS.each_line(chomp: true) do |pet|
|
138
|
+
name, animal, birthdate = pet.split('|').map(&:strip)
|
139
|
+
pets << { name:, animal:, birthdate: }
|
140
|
+
end
|
141
|
+
Pet.insert_all(pets)
|
142
|
+
|
143
|
+
# Helpers
|
144
|
+
module PetsHelper
|
145
|
+
include Pagy::Frontend
|
146
|
+
|
147
|
+
def order_symbol(dir)
|
148
|
+
{ asc: '↗', desc: '↘' }[dir]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Controllers
|
153
|
+
class PetsController < ActionController::Base # :nodoc:
|
154
|
+
include Rails.application.routes.url_helpers
|
155
|
+
include Pagy::Backend
|
156
|
+
|
157
|
+
def index
|
158
|
+
Time.zone = 'UTC'
|
159
|
+
|
160
|
+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
161
|
+
@pagy, @pets = pagy_keyset(Pet.order(@order))
|
162
|
+
render inline: TEMPLATE
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
TEMPLATE = <<~ERB
|
167
|
+
<!DOCTYPE html>
|
168
|
+
<html lang="en">
|
169
|
+
<html>
|
170
|
+
<head>
|
171
|
+
<title>Pagy Keyset App</title>
|
172
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
173
|
+
<style type="text/css">
|
174
|
+
@media screen { html, body {
|
175
|
+
font-size: 1rem;
|
176
|
+
line-height: 1.2s;
|
177
|
+
padding: 0;
|
178
|
+
margin: 0;
|
179
|
+
} }
|
180
|
+
body {
|
181
|
+
background: white !important;
|
182
|
+
margin: 0 !important;
|
183
|
+
font-family: sans-serif !important;
|
184
|
+
}
|
185
|
+
.content {
|
186
|
+
padding: 1rem 1.5rem 2rem !important;
|
187
|
+
}
|
188
|
+
|
189
|
+
<%== Pagy.root.join('stylesheets', 'pagy.css').read %>
|
190
|
+
</style>
|
191
|
+
</head>
|
192
|
+
|
193
|
+
<body>
|
194
|
+
|
195
|
+
<div class="content">
|
196
|
+
<h1>Pagy Keyset App</h1>
|
197
|
+
<p>Self-contained, standalone Rails app usable to easily reproduce any keyset related pagy issue with ActiveRecord sets.</p>
|
198
|
+
<p>Please, report the following versions in any new issue.</p>
|
199
|
+
<h2>Versions</h2>
|
200
|
+
<ul>
|
201
|
+
<li>Ruby: <%== RUBY_VERSION %></li>
|
202
|
+
<li>Rack: <%== Rack::RELEASE %></li>
|
203
|
+
<li>Rails: <%== Rails.version %></li>
|
204
|
+
<li>Pagy: <%== Pagy::VERSION %></li>
|
205
|
+
</ul>
|
206
|
+
|
207
|
+
<h3>Collection</h3>
|
208
|
+
<div id="records" class="collection">
|
209
|
+
<table border="1" cellspacing="0" cellpadding="3">
|
210
|
+
<tr>
|
211
|
+
<th>animal <%== order_symbol(@order[:animal]) %></th>
|
212
|
+
<th>name <%== order_symbol(@order[:name]) %></th>
|
213
|
+
<th>birthdate <%== order_symbol(@order[:birthdate]) %></th>
|
214
|
+
<th>id <%== order_symbol(@order[:id]) %></th>
|
215
|
+
</tr>
|
216
|
+
<% @pets.each do |pet| %>
|
217
|
+
<tr>
|
218
|
+
<td><%= pet.animal %></td>
|
219
|
+
<td><%= pet.name %></td>
|
220
|
+
<td><%= pet.birthdate %></td>
|
221
|
+
<td><%= pet.id %></td>
|
222
|
+
</tr>
|
223
|
+
<% end %>
|
224
|
+
</table>
|
225
|
+
</div>
|
226
|
+
<p>
|
227
|
+
<nav class="pagy" id="next" aria-label="Pagy next">
|
228
|
+
<%== pagy_next_a(@pagy, text: 'Next page >') %>
|
229
|
+
</nav>
|
230
|
+
</div>
|
231
|
+
|
232
|
+
</body>
|
233
|
+
</html>
|
234
|
+
ERB
|
235
|
+
|
236
|
+
run PagyKeyset
|
data/apps/keyset_s.ru
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Starting point to reproduce keyset related pagy issues
|
4
|
+
|
5
|
+
# DEV USAGE
|
6
|
+
# pagy clone rails
|
7
|
+
# pagy ./keyset.ru
|
8
|
+
|
9
|
+
# URL
|
10
|
+
# http://0.0.0.0:8000
|
11
|
+
|
12
|
+
# HELP
|
13
|
+
# pagy -h
|
14
|
+
|
15
|
+
# DOC
|
16
|
+
# https://ddnexus.github.io/pagy/playground/#5-keyset-app
|
17
|
+
|
18
|
+
VERSION = '8.6.2'
|
19
|
+
|
20
|
+
# Gemfile
|
21
|
+
require 'bundler/inline'
|
22
|
+
require 'bundler'
|
23
|
+
Bundler.configure
|
24
|
+
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
25
|
+
source 'https://rubygems.org'
|
26
|
+
gem 'oj'
|
27
|
+
gem 'puma'
|
28
|
+
gem 'rails'
|
29
|
+
# activerecord/sqlite3_adapter.rb probably useless) constraint !!!
|
30
|
+
# https://github.com/rails/rails/blame/v7.1.3.4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
|
31
|
+
gem 'sqlite3', '~> 1.4.0'
|
32
|
+
gem 'sequel'
|
33
|
+
end
|
34
|
+
|
35
|
+
# require 'rails/all' # too much stuff
|
36
|
+
require 'action_controller/railtie'
|
37
|
+
require 'sequel'
|
38
|
+
|
39
|
+
OUTPUT = Rails.env.showcase? ? IO::NULL : $stdout
|
40
|
+
|
41
|
+
# Rails config
|
42
|
+
class PagyKeyset < Rails::Application # :nodoc:
|
43
|
+
config.root = __dir__
|
44
|
+
config.session_store :cookie_store, key: 'cookie_store_key'
|
45
|
+
Rails.application.credentials.secret_key_base = 'absolute_secret'
|
46
|
+
|
47
|
+
config.logger = Logger.new(OUTPUT)
|
48
|
+
Rails.logger = config.logger
|
49
|
+
|
50
|
+
routes.draw do
|
51
|
+
root to: 'pets#index'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
56
|
+
unless File.writable?(dir)
|
57
|
+
warn "ERROR: directory #{dir.inspect} is not writable (the pagy-rails-app needs to create DB files)"
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
# Pagy initializer
|
62
|
+
require 'pagy/extras/pagy'
|
63
|
+
require 'pagy/extras/limit'
|
64
|
+
require 'pagy/extras/keyset'
|
65
|
+
Pagy::DEFAULT[:limit] = 10
|
66
|
+
Pagy::DEFAULT.freeze
|
67
|
+
|
68
|
+
PETS = <<~PETS
|
69
|
+
Luna | dog | 2018-03-10
|
70
|
+
Coco | cat | 2019-05-15
|
71
|
+
Dodo | dog | 2020-06-25
|
72
|
+
Wiki | bird | 2018-03-12
|
73
|
+
Baby | rabbit | 2020-01-13
|
74
|
+
Neki | horse | 2021-07-20
|
75
|
+
Tino | donkey | 2019-06-18
|
76
|
+
Plot | cat | 2022-09-21
|
77
|
+
Riki | cat | 2018-09-14
|
78
|
+
Susi | horse | 2018-10-26
|
79
|
+
Coco | pig | 2020-08-29
|
80
|
+
Momo | bird | 2023-08-25
|
81
|
+
Lili | cat | 2021-07-22
|
82
|
+
Beli | pig | 2020-07-26
|
83
|
+
Rocky | bird | 2022-08-19
|
84
|
+
Vyvy | dog | 2018-05-16
|
85
|
+
Susi | horse | 2024-01-25
|
86
|
+
Ella | cat | 2020-02-20
|
87
|
+
Rocky | dog | 2019-09-19
|
88
|
+
Juni | rabbit | 2020-08-24
|
89
|
+
Coco | bird | 2021-03-17
|
90
|
+
Susi | dog | 2021-07-28
|
91
|
+
Luna | horse | 2023-05-14
|
92
|
+
Gigi | pig | 2022-05-19
|
93
|
+
Coco | cat | 2020-02-20
|
94
|
+
Nino | donkey | 2019-06-17
|
95
|
+
Luna | cat | 2022-02-09
|
96
|
+
Popi | dog | 2020-09-26
|
97
|
+
Lili | pig | 2022-06-18
|
98
|
+
Mina | horse | 2021-04-21
|
99
|
+
Susi | rabbit | 2023-05-18
|
100
|
+
Toni | donkey | 2018-06-22
|
101
|
+
Rocky | horse | 2019-09-28
|
102
|
+
Lili | cat | 2019-03-18
|
103
|
+
Roby | cat | 2022-06-19
|
104
|
+
Anto | horse | 2022-08-18
|
105
|
+
Susi | pig | 2021-04-21
|
106
|
+
Boly | bird | 2020-03-29
|
107
|
+
Sky | cat | 2023-07-19
|
108
|
+
Lili | dog | 2020-01-28
|
109
|
+
Fami | snake | 2023-04-27
|
110
|
+
Lopi | pig | 2019-06-19
|
111
|
+
Rocky | snake | 2022-03-13
|
112
|
+
Denis | dog | 2022-06-19
|
113
|
+
Maca | cat | 2022-06-19
|
114
|
+
Luna | dog | 2022-08-15
|
115
|
+
Jeme | horse | 2019-08-08
|
116
|
+
Sary | bird | 2023-04-29
|
117
|
+
Rocky | bird | 2023-05-14
|
118
|
+
Coco | dog | 2023-05-27
|
119
|
+
PETS
|
120
|
+
|
121
|
+
Sequel.default_timezone = :utc
|
122
|
+
|
123
|
+
## Sequel initializer
|
124
|
+
DB = Sequel.connect(adapter: 'sqlite', user: 'root', password: 'password', host: 'localhost', port: '3306',
|
125
|
+
database: "#{dir}/tmp/pagy-keyset-s.sqlite3", max_connections: 10, loggers: [Logger.new(OUTPUT)])
|
126
|
+
|
127
|
+
DB.create_table! :pets do
|
128
|
+
primary_key :id
|
129
|
+
String :animal, unique: false, null: false
|
130
|
+
String :name, unique: false, null: false
|
131
|
+
Date :birthdate, unique: false, null: false
|
132
|
+
end
|
133
|
+
|
134
|
+
dataset = DB[:pets]
|
135
|
+
|
136
|
+
PETS.each_line(chomp: true) do |pet|
|
137
|
+
name, animal, birthdate = pet.split('|').map(&:strip)
|
138
|
+
dataset.insert(name:, animal:, birthdate:)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Models
|
142
|
+
class Pet < Sequel::Model
|
143
|
+
end
|
144
|
+
|
145
|
+
# Helpers
|
146
|
+
module PetsHelper
|
147
|
+
include Pagy::Frontend
|
148
|
+
|
149
|
+
def order_symbol(dir)
|
150
|
+
{ asc: '↗', desc: '↘' }[dir]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Controllers
|
155
|
+
class PetsController < ActionController::Base # :nodoc:
|
156
|
+
include Rails.application.routes.url_helpers
|
157
|
+
include Pagy::Backend
|
158
|
+
|
159
|
+
def index
|
160
|
+
Time.zone = 'UTC'
|
161
|
+
|
162
|
+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
163
|
+
@pagy, @pets = pagy_keyset(Pet.order(:animal, :name, Sequel.desc(:birthdate), :id))
|
164
|
+
render inline: TEMPLATE
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
TEMPLATE = <<~ERB
|
169
|
+
<!DOCTYPE html>
|
170
|
+
<html lang="en">
|
171
|
+
<html>
|
172
|
+
<head>
|
173
|
+
<title>Pagy Keyset App</title>
|
174
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
175
|
+
<style type="text/css">
|
176
|
+
@media screen { html, body {
|
177
|
+
font-size: 1rem;
|
178
|
+
line-height: 1.2s;
|
179
|
+
padding: 0;
|
180
|
+
margin: 0;
|
181
|
+
} }
|
182
|
+
body {
|
183
|
+
background: white !important;
|
184
|
+
margin: 0 !important;
|
185
|
+
font-family: sans-serif !important;
|
186
|
+
}
|
187
|
+
.content {
|
188
|
+
padding: 1rem 1.5rem 2rem !important;
|
189
|
+
}
|
190
|
+
|
191
|
+
<%== Pagy.root.join('stylesheets', 'pagy.css').read %>
|
192
|
+
</style>
|
193
|
+
</head>
|
194
|
+
|
195
|
+
<body>
|
196
|
+
|
197
|
+
<div class="content">
|
198
|
+
<h1>Pagy Keyset App</h1>
|
199
|
+
<p>Self-contained, standalone Rails app usable to easily reproduce any keyset related pagy issue with Sequel sets.</p>
|
200
|
+
<p>Please, report the following versions in any new issue.</p>
|
201
|
+
<h2>Versions</h2>
|
202
|
+
<ul>
|
203
|
+
<li>Ruby: <%== RUBY_VERSION %></li>
|
204
|
+
<li>Rack: <%== Rack::RELEASE %></li>
|
205
|
+
<li>Rails: <%== Rails.version %></li>
|
206
|
+
<li>Pagy: <%== Pagy::VERSION %></li>
|
207
|
+
</ul>
|
208
|
+
|
209
|
+
<h3>Collection</h3>
|
210
|
+
<div id="records" class="collection">
|
211
|
+
<table border="1" cellspacing="0" cellpadding="3">
|
212
|
+
<tr>
|
213
|
+
<th>animal <%== order_symbol(@order[:animal]) %></th>
|
214
|
+
<th>name <%== order_symbol(@order[:name]) %></th>
|
215
|
+
<th>birthdate <%== order_symbol(@order[:birthdate]) %></th>
|
216
|
+
<th>id <%== order_symbol(@order[:id]) %></th>
|
217
|
+
</tr>
|
218
|
+
<% @pets.each do |pet| %>
|
219
|
+
<tr>
|
220
|
+
<td><%= pet.animal %></td>
|
221
|
+
<td><%= pet.name %></td>
|
222
|
+
<td><%= pet.birthdate %></td>
|
223
|
+
<td><%= pet.id %></td>
|
224
|
+
</tr>
|
225
|
+
<% end %>
|
226
|
+
</table>
|
227
|
+
</div>
|
228
|
+
<p>
|
229
|
+
<nav class="pagy" id="next" aria-label="Pagy next">
|
230
|
+
<%== pagy_next_a(@pagy, text: 'Next page >') %>
|
231
|
+
</nav>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</body>
|
235
|
+
</html>
|
236
|
+
ERB
|
237
|
+
|
238
|
+
run PagyKeyset
|
data/apps/rails.ru
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# DOC
|
16
16
|
# https://ddnexus.github.io/pagy/playground/#2-rails-app
|
17
17
|
|
18
|
-
VERSION = '
|
18
|
+
VERSION = '9.0.9'
|
19
19
|
|
20
20
|
# Gemfile
|
21
21
|
require 'bundler/inline'
|
@@ -26,6 +26,8 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
26
26
|
gem 'oj'
|
27
27
|
gem 'puma'
|
28
28
|
gem 'rails'
|
29
|
+
# activerecord/sqlite3_adapter.rb probably useless) constraint !!!
|
30
|
+
# https://github.com/rails/rails/blame/v7.1.3.4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
|
29
31
|
gem 'sqlite3', '~> 1.4.0'
|
30
32
|
end
|
31
33
|
|
@@ -46,7 +48,7 @@ class PagyRails < Rails::Application # :nodoc:
|
|
46
48
|
|
47
49
|
routes.draw do
|
48
50
|
root to: 'comments#index'
|
49
|
-
get '/
|
51
|
+
get '/javascripts/:file', to: 'pagy#javascripts', file: /.*/
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -59,13 +61,15 @@ end
|
|
59
61
|
|
60
62
|
# Pagy initializer
|
61
63
|
require 'pagy/extras/pagy'
|
62
|
-
require 'pagy/extras/
|
64
|
+
require 'pagy/extras/limit'
|
63
65
|
require 'pagy/extras/overflow'
|
64
|
-
|
65
|
-
Pagy::DEFAULT[:
|
66
|
+
require 'pagy/extras/headers'
|
67
|
+
Pagy::DEFAULT[:limit] = 10
|
66
68
|
Pagy::DEFAULT[:overflow] = :empty_page
|
67
69
|
Pagy::DEFAULT.freeze
|
68
70
|
|
71
|
+
# Activerecord initializer
|
72
|
+
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
69
73
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-rails.sqlite3")
|
70
74
|
ActiveRecord::Schema.define do
|
71
75
|
create_table :posts, force: true do |t|
|
@@ -87,6 +91,10 @@ class Comment < ActiveRecord::Base # :nodoc:
|
|
87
91
|
belongs_to :post
|
88
92
|
end # :nodoc:
|
89
93
|
|
94
|
+
# Unused model, useful to test overriding conflicts
|
95
|
+
module Calendar
|
96
|
+
end
|
97
|
+
|
90
98
|
# DB seed
|
91
99
|
1.upto(11) do |pi|
|
92
100
|
Post.create(title: "Post #{pi + 1}")
|
@@ -95,9 +103,6 @@ Post.all.each_with_index do |post, pi|
|
|
95
103
|
2.times { |ci| Comment.create(post:, body: "Comment #{ci + 1} to Post #{pi + 1}") }
|
96
104
|
end
|
97
105
|
|
98
|
-
# Down here to avoid logging the DB seed above at each restart
|
99
|
-
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
100
|
-
|
101
106
|
# Helpers
|
102
107
|
module CommentsHelper
|
103
108
|
include Pagy::Frontend
|
@@ -110,15 +115,20 @@ class CommentsController < ActionController::Base # :nodoc:
|
|
110
115
|
|
111
116
|
def index
|
112
117
|
@pagy, @comments = pagy(Comment.all)
|
118
|
+
pagy_headers_merge(@pagy)
|
113
119
|
render inline: TEMPLATE
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
117
123
|
# You don't need this in real rails apps (see https://ddnexus.github.io/pagy/docs/api/javascript/setup/#2-configure)
|
118
124
|
class PagyController < ActionController::Base
|
119
|
-
def
|
120
|
-
|
121
|
-
|
125
|
+
def javascripts
|
126
|
+
format = params[:file].split('.').last
|
127
|
+
if format == 'js'
|
128
|
+
render js: Pagy.root.join('javascripts', params[:file]).read
|
129
|
+
elsif format == 'map'
|
130
|
+
render json: Pagy.root.join('javascripts', params[:file]).read
|
131
|
+
end
|
122
132
|
end
|
123
133
|
end
|
124
134
|
|
@@ -130,7 +140,7 @@ TEMPLATE = <<~ERB
|
|
130
140
|
<html>
|
131
141
|
<head>
|
132
142
|
<title>Pagy Rails App</title>
|
133
|
-
<script src="/
|
143
|
+
<script src="/javascripts/pagy.min.js"></script>
|
134
144
|
<script>
|
135
145
|
window.addEventListener("load", Pagy.init);
|
136
146
|
</script>
|
@@ -138,7 +148,7 @@ TEMPLATE = <<~ERB
|
|
138
148
|
<style type="text/css">
|
139
149
|
@media screen { html, body {
|
140
150
|
font-size: 1rem;
|
141
|
-
line-
|
151
|
+
line-height: 1.2s;
|
142
152
|
padding: 0;
|
143
153
|
margin: 0;
|
144
154
|
} }
|
@@ -196,8 +206,8 @@ TEMPLATE = <<~ERB
|
|
196
206
|
<h4>pagy_combo_nav_js</h4>
|
197
207
|
<%== pagy_combo_nav_js(@pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
|
198
208
|
|
199
|
-
<h4>
|
200
|
-
<%==
|
209
|
+
<h4>pagy_limit_selector_js</h4>
|
210
|
+
<%== pagy_limit_selector_js(@pagy, id: 'limit-selector-js') %>
|
201
211
|
|
202
212
|
<h4>pagy_info</h4>
|
203
213
|
<%== pagy_info(@pagy, id: 'pagy-info') %>
|