pagy 9.4.0 → 43.5.5
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/LICENSE.txt +1 -1
- data/apps/calendar.ru +566 -562
- data/apps/demo.ru +246 -182
- data/apps/enable_rails_page_segment.rb +56 -0
- data/apps/index.rb +4 -2
- data/apps/keynav+root_key.ru +316 -0
- data/apps/keynav.ru +255 -0
- data/apps/{keyset_ar.ru → keyset.ru} +33 -42
- data/apps/{keyset_s.ru → keyset_sequel.ru} +32 -40
- data/apps/rails.ru +57 -58
- data/apps/repro.ru +54 -51
- data/bin/pagy +2 -95
- data/config/pagy.rb +33 -207
- data/javascripts/ai_widget.js +90 -0
- data/javascripts/pagy.js +166 -0
- data/javascripts/pagy.min.js +2 -4
- data/javascripts/pagy.mjs +126 -67
- data/javascripts/wand.js +1172 -0
- data/lib/pagy/classes/calendar/calendar.rb +101 -0
- data/lib/pagy/{calendar → classes/calendar}/day.rb +7 -11
- data/lib/pagy/{calendar → classes/calendar}/month.rb +5 -10
- data/lib/pagy/{calendar → classes/calendar}/quarter.rb +10 -15
- data/lib/pagy/classes/calendar/unit.rb +93 -0
- data/lib/pagy/{calendar → classes/calendar}/week.rb +5 -9
- data/lib/pagy/{calendar → classes/calendar}/year.rb +5 -6
- data/lib/pagy/classes/exceptions.rb +26 -0
- data/lib/pagy/classes/keyset/adapters/active_record.rb +50 -0
- data/lib/pagy/classes/keyset/adapters/sequel.rb +62 -0
- data/lib/pagy/classes/keyset/keynav.rb +85 -0
- data/lib/pagy/classes/keyset/keyset.rb +155 -0
- data/lib/pagy/classes/offset/countish.rb +17 -0
- data/lib/pagy/classes/offset/countless.rb +63 -0
- data/lib/pagy/classes/offset/offset.rb +63 -0
- data/lib/pagy/classes/offset/search.rb +34 -0
- data/lib/pagy/classes/request.rb +48 -0
- data/lib/pagy/cli.rb +122 -0
- data/lib/pagy/console.rb +5 -20
- data/lib/pagy/deprecated.rb +84 -0
- data/lib/pagy/modules/abilities/configurable.rb +37 -0
- data/lib/pagy/modules/abilities/countable.rb +23 -0
- data/lib/pagy/modules/abilities/linkable.rb +72 -0
- data/lib/pagy/modules/abilities/rangeable.rb +14 -0
- data/lib/pagy/modules/abilities/shiftable.rb +12 -0
- data/lib/pagy/{b64.rb → modules/b64.rb} +4 -2
- data/lib/pagy/modules/console.rb +33 -0
- data/lib/pagy/modules/i18n/i18n.rb +72 -0
- data/lib/pagy/modules/i18n/p11n/arabic.rb +30 -0
- data/lib/pagy/modules/i18n/p11n/east_slavic.rb +27 -0
- data/lib/pagy/modules/i18n/p11n/one_other.rb +15 -0
- data/lib/pagy/modules/i18n/p11n/one_upto_two_other.rb +15 -0
- data/lib/pagy/modules/i18n/p11n/other.rb +13 -0
- data/lib/pagy/modules/i18n/p11n/polish.rb +27 -0
- data/lib/pagy/modules/i18n/p11n/west_slavic.rb +22 -0
- data/lib/pagy/modules/i18n/p11n.rb +16 -0
- data/lib/pagy/modules/searcher.rb +20 -0
- data/lib/pagy/next.rb +25 -0
- data/lib/pagy/tasks/sync.rb +20 -0
- data/lib/pagy/toolbox/helpers/anchor_tags.rb +19 -0
- data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +28 -0
- data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +19 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +32 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +24 -0
- data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +25 -0
- data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +20 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +31 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +23 -0
- data/lib/pagy/toolbox/helpers/data_hash.rb +29 -0
- data/lib/pagy/toolbox/helpers/headers_hash.rb +30 -0
- data/lib/pagy/toolbox/helpers/info_tag.rb +30 -0
- data/lib/pagy/toolbox/helpers/input_nav_js.rb +22 -0
- data/lib/pagy/toolbox/helpers/limit_tag_js.rb +25 -0
- data/lib/pagy/toolbox/helpers/loaders.rb +58 -0
- data/lib/pagy/toolbox/helpers/page_url.rb +16 -0
- data/lib/pagy/toolbox/helpers/series_nav.rb +30 -0
- data/lib/pagy/toolbox/helpers/series_nav_js.rb +20 -0
- data/lib/pagy/toolbox/helpers/support/a_lambda.rb +36 -0
- data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +19 -0
- data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +10 -0
- data/lib/pagy/toolbox/helpers/support/series.rb +37 -0
- data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +18 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +15 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +38 -0
- data/lib/pagy/toolbox/helpers/urls_hash.rb +12 -0
- data/lib/pagy/toolbox/paginators/calendar.rb +34 -0
- data/lib/pagy/toolbox/paginators/countish.rb +38 -0
- data/lib/pagy/toolbox/paginators/countless.rb +22 -0
- data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +56 -0
- data/lib/pagy/toolbox/paginators/keynav_js.rb +26 -0
- data/lib/pagy/toolbox/paginators/keyset.rb +15 -0
- data/lib/pagy/toolbox/paginators/meilisearch.rb +34 -0
- data/lib/pagy/toolbox/paginators/method.rb +38 -0
- data/lib/pagy/toolbox/paginators/offset.rb +24 -0
- data/lib/pagy/toolbox/paginators/searchkick.rb +34 -0
- data/lib/pagy/toolbox/paginators/typesense_rails.rb +34 -0
- data/lib/pagy.rb +79 -89
- data/locales/ar.yml +9 -6
- data/locales/be.yml +9 -6
- data/locales/bg.yml +9 -6
- data/locales/bs.yml +9 -6
- data/locales/ca.yml +9 -6
- data/locales/ckb.yml +8 -6
- data/locales/cs.yml +9 -6
- data/locales/da.yml +9 -6
- data/locales/de.yml +9 -6
- data/locales/dz.yml +9 -6
- data/locales/en.yml +9 -6
- data/locales/es.yml +9 -6
- data/locales/fr.yml +9 -6
- data/locales/hr.yml +9 -6
- data/locales/hu.yml +24 -0
- data/locales/id.yml +10 -9
- data/locales/it.yml +9 -6
- data/locales/ja.yml +10 -9
- data/locales/km.yml +10 -9
- data/locales/ko.yml +9 -6
- data/locales/nb.yml +9 -6
- data/locales/nl.yml +9 -6
- data/locales/nn.yml +9 -6
- data/locales/pl.yml +9 -6
- data/locales/pt-BR.yml +10 -7
- data/locales/pt.yml +10 -7
- data/locales/ru.yml +9 -6
- data/locales/sk.yml +9 -6
- data/locales/sr.yml +9 -6
- data/locales/sv-SE.yml +9 -6
- data/locales/sv.yml +9 -6
- data/locales/sw.yml +12 -9
- data/locales/ta.yml +9 -6
- data/locales/tr.yml +17 -12
- data/locales/uk.yml +9 -6
- data/locales/vi.yml +9 -6
- data/locales/zh-CN.yml +9 -6
- data/locales/zh-HK.yml +9 -6
- data/locales/zh-TW.yml +9 -6
- data/stylesheets/pagy-tailwind.css +68 -0
- data/stylesheets/pagy.css +64 -27
- metadata +134 -53
- data/javascripts/pagy.min.js.map +0 -10
- data/lib/optimist.rb +0 -1022
- data/lib/pagy/backend.rb +0 -44
- data/lib/pagy/calendar/unit.rb +0 -103
- data/lib/pagy/calendar.rb +0 -84
- data/lib/pagy/countless.rb +0 -38
- data/lib/pagy/exceptions.rb +0 -25
- data/lib/pagy/extras/arel.rb +0 -28
- data/lib/pagy/extras/array.rb +0 -19
- data/lib/pagy/extras/bootstrap.rb +0 -97
- data/lib/pagy/extras/bulma.rb +0 -93
- data/lib/pagy/extras/calendar.rb +0 -79
- data/lib/pagy/extras/countless.rb +0 -32
- data/lib/pagy/extras/elasticsearch_rails.rb +0 -71
- data/lib/pagy/extras/gearbox.rb +0 -55
- data/lib/pagy/extras/headers.rb +0 -54
- data/lib/pagy/extras/i18n.rb +0 -26
- data/lib/pagy/extras/js_tools.rb +0 -70
- data/lib/pagy/extras/jsonapi.rb +0 -88
- data/lib/pagy/extras/keyset.rb +0 -30
- data/lib/pagy/extras/limit.rb +0 -63
- data/lib/pagy/extras/meilisearch.rb +0 -57
- data/lib/pagy/extras/metadata.rb +0 -42
- data/lib/pagy/extras/overflow.rb +0 -81
- data/lib/pagy/extras/pagy.rb +0 -82
- data/lib/pagy/extras/searchkick.rb +0 -59
- data/lib/pagy/extras/size.rb +0 -40
- data/lib/pagy/extras/standalone.rb +0 -60
- data/lib/pagy/extras/trim.rb +0 -29
- data/lib/pagy/frontend.rb +0 -99
- data/lib/pagy/i18n.rb +0 -167
- data/lib/pagy/keyset/active_record.rb +0 -44
- data/lib/pagy/keyset/sequel.rb +0 -57
- data/lib/pagy/keyset.rb +0 -118
- data/lib/pagy/shared_methods.rb +0 -26
- data/lib/pagy/url_helpers.rb +0 -26
- data/stylesheets/pagy.scss +0 -48
- data/stylesheets/pagy.tailwind.css +0 -21
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# DESCRIPTION
|
|
4
|
-
# Showcase the
|
|
4
|
+
# Showcase the Keyset pagination (ActiveRecord example)
|
|
5
5
|
#
|
|
6
6
|
# DOC
|
|
7
|
-
# https://ddnexus.github.io/pagy/playground/#
|
|
7
|
+
# https://ddnexus.github.io/pagy/playground/#keyset-apps
|
|
8
8
|
#
|
|
9
9
|
# BIN HELP
|
|
10
|
-
#
|
|
10
|
+
# pagy -h
|
|
11
11
|
#
|
|
12
12
|
# DEV USAGE
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# pagy clone keyset
|
|
14
|
+
# pagy ./keyset.ru
|
|
15
15
|
#
|
|
16
16
|
# URL
|
|
17
|
-
# http://
|
|
17
|
+
# http://127.0.0.1:8000
|
|
18
18
|
|
|
19
|
-
VERSION = '
|
|
19
|
+
VERSION = '43.5.5'
|
|
20
|
+
|
|
21
|
+
if VERSION != Pagy::VERSION
|
|
22
|
+
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
23
|
+
end
|
|
20
24
|
|
|
21
25
|
# Bundle
|
|
22
26
|
require 'bundler/inline'
|
|
23
|
-
|
|
24
|
-
Bundler.configure
|
|
25
|
-
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
27
|
+
gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do
|
|
26
28
|
source 'https://rubygems.org'
|
|
27
29
|
gem 'activerecord'
|
|
28
30
|
gem 'puma'
|
|
@@ -30,31 +32,26 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
|
30
32
|
gem 'sqlite3'
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
# Pagy initializer
|
|
34
|
-
require 'pagy/extras/limit'
|
|
35
|
-
require 'pagy/extras/keyset'
|
|
36
|
-
require 'pagy/extras/pagy'
|
|
37
|
-
Pagy::DEFAULT[:limit] = 10
|
|
38
|
-
Pagy::DEFAULT.freeze
|
|
39
|
-
|
|
40
35
|
# Sinatra setup
|
|
41
36
|
require 'sinatra/base'
|
|
42
37
|
# Sinatra application
|
|
43
38
|
class PagyKeyset < Sinatra::Base
|
|
44
|
-
include Pagy::
|
|
39
|
+
include Pagy::Method
|
|
45
40
|
|
|
46
41
|
# Root route/action
|
|
47
42
|
get '/' do
|
|
48
43
|
Time.zone = 'UTC'
|
|
49
44
|
|
|
50
|
-
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
51
|
-
@pagy, @pets =
|
|
45
|
+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }.freeze
|
|
46
|
+
@pagy, @pets = pagy(:keyset, Pet.order(@order), limit: 10, max_limit: 100)
|
|
47
|
+
# @pagy, @pets = pagy(:keyset, Pet.order(@order),
|
|
48
|
+
# jsonapi: true, page_key: 'number', limit_key: 'size', # very customized jsonapi
|
|
49
|
+
# limit: 10, max_limit: 100)
|
|
50
|
+
# response.headers.merge!(@pagy.headers_hash)
|
|
52
51
|
erb :main
|
|
53
52
|
end
|
|
54
53
|
|
|
55
54
|
helpers do
|
|
56
|
-
include Pagy::Frontend
|
|
57
|
-
|
|
58
55
|
def order_symbol(dir)
|
|
59
56
|
{ asc: '↗', desc: '↘' }[dir]
|
|
60
57
|
end
|
|
@@ -65,14 +62,13 @@ class PagyKeyset < Sinatra::Base
|
|
|
65
62
|
<<~ERB
|
|
66
63
|
<!DOCTYPE html>
|
|
67
64
|
<html lang="en">
|
|
68
|
-
<html>
|
|
69
65
|
<head>
|
|
70
|
-
|
|
66
|
+
<title>Pagy Keyset App</title>
|
|
71
67
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
72
68
|
<style type="text/css">
|
|
73
69
|
@media screen { html, body {
|
|
74
70
|
font-size: 1rem;
|
|
75
|
-
line-height: 1.
|
|
71
|
+
line-height: 1.2;
|
|
76
72
|
padding: 0;
|
|
77
73
|
margin: 0;
|
|
78
74
|
} }
|
|
@@ -81,11 +77,11 @@ class PagyKeyset < Sinatra::Base
|
|
|
81
77
|
margin: 0 !important;
|
|
82
78
|
font-family: sans-serif !important;
|
|
83
79
|
}
|
|
84
|
-
.content {
|
|
80
|
+
.main-content {
|
|
85
81
|
padding: 1rem 1.5rem 2rem !important;
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
<%= Pagy.
|
|
84
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
89
85
|
</style>
|
|
90
86
|
</head>
|
|
91
87
|
<body>
|
|
@@ -97,10 +93,10 @@ class PagyKeyset < Sinatra::Base
|
|
|
97
93
|
|
|
98
94
|
template :main do
|
|
99
95
|
<<~ERB
|
|
100
|
-
<div class="content">
|
|
96
|
+
<div class="main-content">
|
|
101
97
|
<h1>Pagy Keyset App</h1>
|
|
102
|
-
<p>Self-contained, standalone app usable to easily reproduce any
|
|
103
|
-
|
|
98
|
+
<p>Self-contained, standalone app usable to easily reproduce any Keyset related pagy issue with ActiveRecord sets.</p>
|
|
99
|
+
|
|
104
100
|
<h2>Versions</h2>
|
|
105
101
|
<ul>
|
|
106
102
|
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
@@ -111,12 +107,12 @@ class PagyKeyset < Sinatra::Base
|
|
|
111
107
|
|
|
112
108
|
<h3>Collection</h3>
|
|
113
109
|
<div id="records" class="collection">
|
|
114
|
-
<table border="1"
|
|
110
|
+
<table border="1" style="border-collapse: collapse; border-spacing: 0; padding: 0.2rem;">
|
|
115
111
|
<tr>
|
|
116
|
-
<th>animal <%= order_symbol(@order[:animal]) %></th>
|
|
117
|
-
<th>name <%= order_symbol(@order[:name]) %></th>
|
|
118
|
-
<th>birthdate <%= order_symbol(@order[:birthdate]) %></th>
|
|
119
|
-
<th>id <%= order_symbol(@order[:id]) %></th>
|
|
112
|
+
<th scope="col">animal <%= order_symbol(@order[:animal]) %></th>
|
|
113
|
+
<th scope="col">name <%= order_symbol(@order[:name]) %></th>
|
|
114
|
+
<th scope="col">birthdate <%= order_symbol(@order[:birthdate]) %></th>
|
|
115
|
+
<th scope="col">id <%= order_symbol(@order[:id]) %></th>
|
|
120
116
|
</tr>
|
|
121
117
|
<% @pets.each do |pet| %>
|
|
122
118
|
<tr>
|
|
@@ -128,9 +124,8 @@ class PagyKeyset < Sinatra::Base
|
|
|
128
124
|
<% end %>
|
|
129
125
|
</table>
|
|
130
126
|
</div>
|
|
131
|
-
<p>
|
|
132
127
|
<nav class="pagy" id="next" aria-label="Pagy next">
|
|
133
|
-
<%=
|
|
128
|
+
<%= @pagy.next_tag(text: 'Next page >') %>
|
|
134
129
|
</nav>
|
|
135
130
|
</div>
|
|
136
131
|
ERB
|
|
@@ -146,12 +141,8 @@ require 'active_record'
|
|
|
146
141
|
# Log
|
|
147
142
|
output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
|
|
148
143
|
ActiveRecord::Base.logger = Logger.new(output)
|
|
149
|
-
# SQLite DB files
|
|
150
|
-
dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
|
151
|
-
abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
|
|
152
|
-
unless File.writable?(dir)
|
|
153
144
|
# Connection
|
|
154
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database:
|
|
145
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'file:memdb1?mode=memory&cache=shared')
|
|
155
146
|
# Schema
|
|
156
147
|
ActiveRecord::Schema.define do
|
|
157
148
|
create_table :pets, force: true do |t|
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# DESCRIPTION
|
|
4
|
-
# Showcase the
|
|
4
|
+
# Showcase the Keyset pagination (Sequel example)
|
|
5
5
|
#
|
|
6
6
|
# DOC
|
|
7
|
-
# https://ddnexus.github.io/pagy/playground/#
|
|
7
|
+
# https://ddnexus.github.io/pagy/playground/#keyset-apps
|
|
8
8
|
#
|
|
9
9
|
# BIN HELP
|
|
10
|
-
#
|
|
10
|
+
# pagy -h
|
|
11
11
|
#
|
|
12
12
|
# DEV USAGE
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# pagy clone keyset_sequel
|
|
14
|
+
# pagy ./keyset_sequel.ru
|
|
15
15
|
#
|
|
16
16
|
# URL
|
|
17
|
-
# http://
|
|
17
|
+
# http://127.0.0.1:8000
|
|
18
18
|
|
|
19
|
-
VERSION = '
|
|
19
|
+
VERSION = '43.5.5'
|
|
20
|
+
|
|
21
|
+
if VERSION != Pagy::VERSION
|
|
22
|
+
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
23
|
+
end
|
|
20
24
|
|
|
21
25
|
# Bundle
|
|
22
26
|
require 'bundler/inline'
|
|
23
|
-
|
|
24
|
-
Bundler.configure
|
|
25
|
-
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
27
|
+
gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do
|
|
26
28
|
source 'https://rubygems.org'
|
|
27
29
|
gem 'puma'
|
|
28
30
|
gem 'sequel'
|
|
@@ -30,30 +32,22 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
|
30
32
|
gem 'sqlite3'
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
# Pagy initializer
|
|
34
|
-
require 'pagy/extras/limit'
|
|
35
|
-
require 'pagy/extras/keyset'
|
|
36
|
-
require 'pagy/extras/pagy'
|
|
37
|
-
Pagy::DEFAULT[:limit] = 10
|
|
38
|
-
Pagy::DEFAULT.freeze
|
|
39
|
-
|
|
40
35
|
# Sinatra setup
|
|
41
36
|
require 'sinatra/base'
|
|
42
37
|
require 'logger'
|
|
43
38
|
# Sinatra application
|
|
44
|
-
class
|
|
45
|
-
include Pagy::
|
|
39
|
+
class PagyKeysetSequel < Sinatra::Base
|
|
40
|
+
include Pagy::Method
|
|
46
41
|
|
|
47
42
|
# Root route/action
|
|
48
43
|
get '/' do
|
|
49
|
-
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
50
|
-
@pagy, @pets =
|
|
44
|
+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }.freeze
|
|
45
|
+
@pagy, @pets = pagy(:keyset, Pet.order(:animal, :name, Sequel.desc(:birthdate), :id),
|
|
46
|
+
limit: 10, max_limit: 100)
|
|
51
47
|
erb :main
|
|
52
48
|
end
|
|
53
49
|
|
|
54
50
|
helpers do
|
|
55
|
-
include Pagy::Frontend
|
|
56
|
-
|
|
57
51
|
def order_symbol(dir)
|
|
58
52
|
{ asc: '↗', desc: '↘' }[dir]
|
|
59
53
|
end
|
|
@@ -64,14 +58,13 @@ class PagyKeyset < Sinatra::Base
|
|
|
64
58
|
<<~ERB
|
|
65
59
|
<!DOCTYPE html>
|
|
66
60
|
<html lang="en">
|
|
67
|
-
<html>
|
|
68
61
|
<head>
|
|
69
|
-
|
|
62
|
+
<title>Pagy Keyset App</title>
|
|
70
63
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
71
64
|
<style type="text/css">
|
|
72
65
|
@media screen { html, body {
|
|
73
66
|
font-size: 1rem;
|
|
74
|
-
line-height: 1.
|
|
67
|
+
line-height: 1.2;
|
|
75
68
|
padding: 0;
|
|
76
69
|
margin: 0;
|
|
77
70
|
} }
|
|
@@ -80,11 +73,11 @@ class PagyKeyset < Sinatra::Base
|
|
|
80
73
|
margin: 0 !important;
|
|
81
74
|
font-family: sans-serif !important;
|
|
82
75
|
}
|
|
83
|
-
.content {
|
|
76
|
+
.main-content {
|
|
84
77
|
padding: 1rem 1.5rem 2rem !important;
|
|
85
78
|
}
|
|
86
79
|
|
|
87
|
-
<%= Pagy.
|
|
80
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
88
81
|
</style>
|
|
89
82
|
</head>
|
|
90
83
|
<body>
|
|
@@ -96,10 +89,10 @@ class PagyKeyset < Sinatra::Base
|
|
|
96
89
|
|
|
97
90
|
template :main do
|
|
98
91
|
<<~ERB
|
|
99
|
-
<div class="content">
|
|
92
|
+
<div class="main-content">
|
|
100
93
|
<h1>Pagy Keyset App</h1>
|
|
101
|
-
<p>Self-contained, standalone app usable to easily reproduce any
|
|
102
|
-
|
|
94
|
+
<p>Self-contained, standalone app usable to easily reproduce any Keyset related pagy issue with Sequel sets.</p>
|
|
95
|
+
|
|
103
96
|
<h2>Versions</h2>
|
|
104
97
|
<ul>
|
|
105
98
|
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
@@ -127,9 +120,8 @@ class PagyKeyset < Sinatra::Base
|
|
|
127
120
|
<% end %>
|
|
128
121
|
</table>
|
|
129
122
|
</div>
|
|
130
|
-
<p>
|
|
131
123
|
<nav class="pagy" id="next" aria-label="Pagy next">
|
|
132
|
-
<%=
|
|
124
|
+
<%= @pagy.next_tag(text: 'Next page >') %>
|
|
133
125
|
</nav>
|
|
134
126
|
</div>
|
|
135
127
|
ERB
|
|
@@ -139,14 +131,14 @@ end
|
|
|
139
131
|
# Sequel setup
|
|
140
132
|
require 'sequel'
|
|
141
133
|
Sequel.default_timezone = :utc
|
|
142
|
-
# SQLite DB files
|
|
143
|
-
dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
|
144
|
-
abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
|
|
145
|
-
unless File.writable?(dir)
|
|
146
134
|
# Connection
|
|
147
135
|
output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
# Use 'sqlite' adapter (Sequel uses 'sqlite', AR uses 'sqlite3')
|
|
137
|
+
# Use the same shared memory URI string for the database
|
|
138
|
+
DB = Sequel.connect(adapter: 'sqlite',
|
|
139
|
+
database: 'file:memdb1?mode=memory&cache=shared',
|
|
140
|
+
max_connections: 10,
|
|
141
|
+
loggers: [Logger.new(output)])
|
|
150
142
|
# Schema
|
|
151
143
|
DB.create_table! :pets do
|
|
152
144
|
primary_key :id
|
|
@@ -217,4 +209,4 @@ data.each_line(chomp: true) do |pet|
|
|
|
217
209
|
dataset.insert(name:, animal:, birthdate:)
|
|
218
210
|
end
|
|
219
211
|
|
|
220
|
-
run
|
|
212
|
+
run PagyKeysetSequel
|
data/apps/rails.ru
CHANGED
|
@@ -4,25 +4,27 @@
|
|
|
4
4
|
# Reproduce rails related issues
|
|
5
5
|
#
|
|
6
6
|
# DOC
|
|
7
|
-
# https://ddnexus.github.io/pagy/playground/#
|
|
7
|
+
# https://ddnexus.github.io/pagy/playground/#rails-app
|
|
8
8
|
#
|
|
9
9
|
# BIN HELP
|
|
10
|
-
#
|
|
10
|
+
# pagy -h
|
|
11
11
|
#
|
|
12
12
|
# DEV USAGE
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# pagy clone rails
|
|
14
|
+
# pagy ./rails.ru
|
|
15
15
|
#
|
|
16
16
|
# URL
|
|
17
|
-
# http://
|
|
17
|
+
# http://127.0.0.1:8000
|
|
18
18
|
|
|
19
|
-
VERSION = '
|
|
19
|
+
VERSION = '43.5.5'
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
if VERSION != Pagy::VERSION
|
|
22
|
+
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Bundle
|
|
22
26
|
require 'bundler/inline'
|
|
23
|
-
|
|
24
|
-
Bundler.configure
|
|
25
|
-
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
27
|
+
gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do
|
|
26
28
|
source 'https://rubygems.org'
|
|
27
29
|
gem 'oj'
|
|
28
30
|
gem 'puma'
|
|
@@ -45,31 +47,19 @@ class PagyRails < Rails::Application # :nodoc:
|
|
|
45
47
|
config.logger = Logger.new(OUTPUT)
|
|
46
48
|
Rails.logger = config.logger
|
|
47
49
|
|
|
50
|
+
# Pagy initializer
|
|
51
|
+
# require Pagy::ROOT.join('apps/enable_rails_page_segment.rb') # Uncomment to test the enable_rails_page_segment.rb override
|
|
52
|
+
|
|
48
53
|
routes.draw do
|
|
49
54
|
root to: 'comments#index'
|
|
55
|
+
# get '/comments(/:page)', to: 'comments#index' # Uncomment to test the enable_rails_page_segment.rb override
|
|
50
56
|
get '/javascripts/:file', to: 'pagy#javascripts', file: /.*/
|
|
51
57
|
end
|
|
52
58
|
end
|
|
53
59
|
|
|
54
|
-
# AR config
|
|
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/overflow'
|
|
65
|
-
require 'pagy/extras/headers'
|
|
66
|
-
Pagy::DEFAULT[:limit] = 10
|
|
67
|
-
Pagy::DEFAULT[:overflow] = :empty_page
|
|
68
|
-
Pagy::DEFAULT.freeze
|
|
69
|
-
|
|
70
60
|
# Activerecord initializer
|
|
71
61
|
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
|
72
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database:
|
|
62
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'file:memdb1?mode=memory&cache=shared')
|
|
73
63
|
ActiveRecord::Schema.define do
|
|
74
64
|
create_table :posts, force: true do |t|
|
|
75
65
|
t.string :title
|
|
@@ -84,11 +74,15 @@ end
|
|
|
84
74
|
# Models
|
|
85
75
|
class Post < ActiveRecord::Base # :nodoc:
|
|
86
76
|
has_many :comments
|
|
87
|
-
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# :nodoc:
|
|
88
80
|
|
|
89
81
|
class Comment < ActiveRecord::Base # :nodoc:
|
|
90
82
|
belongs_to :post
|
|
91
|
-
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# :nodoc:
|
|
92
86
|
|
|
93
87
|
# Unused model, useful to test overriding conflicts
|
|
94
88
|
module Calendar
|
|
@@ -102,31 +96,27 @@ Post.all.each_with_index do |post, pi|
|
|
|
102
96
|
2.times { |ci| Comment.create(post:, body: "Comment #{ci + 1} to Post #{pi + 1}") }
|
|
103
97
|
end
|
|
104
98
|
|
|
105
|
-
# Helpers
|
|
106
|
-
module CommentsHelper
|
|
107
|
-
include Pagy::Frontend
|
|
108
|
-
end
|
|
109
|
-
|
|
110
99
|
# Controllers
|
|
111
100
|
class CommentsController < ActionController::Base # :nodoc:
|
|
112
101
|
include Rails.application.routes.url_helpers
|
|
113
|
-
include Pagy::
|
|
102
|
+
include Pagy::Method
|
|
114
103
|
|
|
115
104
|
def index
|
|
116
|
-
@pagy, @comments = pagy(Comment.all)
|
|
117
|
-
|
|
105
|
+
@pagy, @comments = pagy(:offset, Comment.all, limit: 10, max_limit: 100)
|
|
106
|
+
# Reload the page in the network tab of the Chrome Inspector to check
|
|
107
|
+
# response.headers.merge!(@pagy.headers_hash)
|
|
118
108
|
render inline: TEMPLATE
|
|
119
109
|
end
|
|
120
110
|
end
|
|
121
111
|
|
|
122
|
-
# You don't need this in real rails apps (see https://ddnexus.github.io/pagy/
|
|
112
|
+
# You don't need this in real rails apps (see https://ddnexus.github.io/pagy/resources/javascripts)
|
|
123
113
|
class PagyController < ActionController::Base
|
|
124
114
|
def javascripts
|
|
125
115
|
format = params[:file].split('.').last
|
|
126
116
|
if format == 'js'
|
|
127
|
-
render js: Pagy.
|
|
117
|
+
render js: Pagy::ROOT.join('javascripts', params[:file]).read
|
|
128
118
|
elsif format == 'map'
|
|
129
|
-
render json: Pagy.
|
|
119
|
+
render json: Pagy::ROOT.join('javascripts', params[:file]).read
|
|
130
120
|
end
|
|
131
121
|
end
|
|
132
122
|
end
|
|
@@ -136,10 +126,9 @@ run PagyRails
|
|
|
136
126
|
TEMPLATE = <<~ERB
|
|
137
127
|
<!DOCTYPE html>
|
|
138
128
|
<html lang="en">
|
|
139
|
-
<html>
|
|
140
129
|
<head>
|
|
141
|
-
|
|
142
|
-
<script src="/javascripts/pagy.
|
|
130
|
+
<title>Pagy Rails App</title>
|
|
131
|
+
<script src="/javascripts/pagy.js"></script>
|
|
143
132
|
<script>
|
|
144
133
|
window.addEventListener("load", Pagy.init);
|
|
145
134
|
</script>
|
|
@@ -147,7 +136,7 @@ TEMPLATE = <<~ERB
|
|
|
147
136
|
<style type="text/css">
|
|
148
137
|
@media screen { html, body {
|
|
149
138
|
font-size: 1rem;
|
|
150
|
-
line-height: 1.
|
|
139
|
+
line-height: 1.2;
|
|
151
140
|
padding: 0;
|
|
152
141
|
margin: 0;
|
|
153
142
|
} }
|
|
@@ -156,9 +145,15 @@ TEMPLATE = <<~ERB
|
|
|
156
145
|
margin: 0 !important;
|
|
157
146
|
font-family: sans-serif !important;
|
|
158
147
|
}
|
|
159
|
-
.content {
|
|
148
|
+
.main-content {
|
|
160
149
|
padding: 1rem 1.5rem 2rem !important;
|
|
161
150
|
}
|
|
151
|
+
.pagy, .pagy-bootstrap, .pagy-bulma {
|
|
152
|
+
padding: .5em;
|
|
153
|
+
margin: .3em 0;
|
|
154
|
+
width: fit-content;
|
|
155
|
+
box-shadow: 5px 5px 10px 0px rgba(0,0,0,0.2);
|
|
156
|
+
}
|
|
162
157
|
|
|
163
158
|
/* Quick demo for overriding the element style attribute of certain pagy helpers
|
|
164
159
|
.pagy input[style] {
|
|
@@ -170,16 +165,16 @@ TEMPLATE = <<~ERB
|
|
|
170
165
|
If you want to customize the style,
|
|
171
166
|
please replace the line below with the actual file content
|
|
172
167
|
*/
|
|
173
|
-
<%== Pagy.
|
|
168
|
+
<%== Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
174
169
|
</style>
|
|
175
170
|
</head>
|
|
176
171
|
|
|
177
172
|
<body>
|
|
178
173
|
|
|
179
|
-
<div class="content">
|
|
174
|
+
<div class="main-content">
|
|
180
175
|
<h1>Pagy Rails App</h1>
|
|
181
176
|
<p> Self-contained, standalone Rails app usable to easily reproduce any rails related pagy issue.</p>
|
|
182
|
-
|
|
177
|
+
|
|
183
178
|
<h2>Versions</h2>
|
|
184
179
|
<ul>
|
|
185
180
|
<li>Ruby: <%== RUBY_VERSION %></li>
|
|
@@ -194,22 +189,26 @@ TEMPLATE = <<~ERB
|
|
|
194
189
|
<p style="margin: 0;"><%= comment.body %></p>
|
|
195
190
|
<% end %>
|
|
196
191
|
</div>
|
|
192
|
+
|
|
197
193
|
<hr>
|
|
198
194
|
|
|
199
|
-
<h4
|
|
200
|
-
<%==
|
|
195
|
+
<h4>@pagy.series_nav</h4>
|
|
196
|
+
<%== @pagy.series_nav(id: 'series-nav',
|
|
197
|
+
aria_label: 'Pages nav') %>
|
|
201
198
|
|
|
202
|
-
<h4
|
|
203
|
-
<%==
|
|
199
|
+
<h4>@pagy.series_nav_js</h4>
|
|
200
|
+
<%== @pagy.series_nav_js(id: 'series-nav-js',
|
|
201
|
+
aria_label: 'Pages nav_js') %>
|
|
204
202
|
|
|
205
|
-
<h4
|
|
206
|
-
<%==
|
|
203
|
+
<h4>@pagy.input_nav_js</h4>
|
|
204
|
+
<%== @pagy.input_nav_js(id: 'input-nav-js',
|
|
205
|
+
aria_label: 'Pages input_nav_js') %>
|
|
207
206
|
|
|
208
|
-
<h4
|
|
209
|
-
<%==
|
|
207
|
+
<h4>@pagy.limit_tag_js</h4>
|
|
208
|
+
<%== @pagy.limit_tag_js(id: 'limit-tag-js') %>
|
|
210
209
|
|
|
211
|
-
<h4
|
|
212
|
-
<%==
|
|
210
|
+
<h4>@pagy.info_tag</h4>
|
|
211
|
+
<%== @pagy.info_tag(id: 'pagy-info') %>
|
|
213
212
|
</div>
|
|
214
213
|
|
|
215
214
|
</body>
|