pagy 9.4.0 → 43.2.0
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 +548 -552
- data/apps/demo.ru +224 -181
- data/apps/index.rb +3 -1
- data/apps/keynav+root_key.ru +321 -0
- data/apps/keynav.ru +260 -0
- data/apps/{keyset_ar.ru → keyset.ru} +26 -32
- data/apps/{keyset_s.ru → keyset_sequel.ru} +23 -29
- data/apps/rails.ru +51 -48
- data/apps/repro.ru +51 -47
- data/bin/pagy +20 -21
- data/config/pagy.rb +35 -207
- data/javascripts/ai_widget.js +90 -0
- data/javascripts/pagy.js +153 -0
- data/javascripts/pagy.js.map +10 -0
- data/javascripts/pagy.min.js +2 -4
- data/javascripts/pagy.mjs +113 -63
- data/javascripts/wand.js +1172 -0
- data/lib/pagy/classes/calendar/calendar.rb +96 -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 +25 -0
- data/lib/pagy/classes/keyset/active_record.rb +11 -0
- data/lib/pagy/classes/keyset/adapters/active_record.rb +50 -0
- data/lib/pagy/classes/keyset/adapters/sequel.rb +63 -0
- data/lib/pagy/classes/keyset/keynav/active_record.rb +13 -0
- data/lib/pagy/classes/keyset/keynav/sequel.rb +13 -0
- data/lib/pagy/classes/keyset/keynav.rb +79 -0
- data/lib/pagy/classes/keyset/keyset.rb +126 -0
- data/lib/pagy/classes/keyset/sequel.rb +11 -0
- data/lib/pagy/classes/offset/countish.rb +17 -0
- data/lib/pagy/classes/offset/countless.rb +61 -0
- data/lib/pagy/classes/offset/offset.rb +56 -0
- data/lib/pagy/classes/offset/search.rb +32 -0
- data/lib/pagy/classes/request.rb +36 -0
- data/lib/pagy/console.rb +3 -20
- data/lib/pagy/modules/abilities/configurable.rb +36 -0
- data/lib/pagy/modules/abilities/countable.rb +23 -0
- data/lib/pagy/modules/abilities/linkable.rb +60 -0
- data/lib/pagy/modules/abilities/rangeable.rb +16 -0
- data/lib/pagy/modules/abilities/shiftable.rb +12 -0
- data/lib/pagy/{b64.rb → modules/b64.rb} +3 -7
- data/lib/pagy/modules/console.rb +24 -0
- data/lib/pagy/modules/i18n/i18n.rb +48 -0
- data/lib/pagy/modules/i18n/p11n/arabic.rb +29 -0
- data/lib/pagy/modules/i18n/p11n/east_slavic.rb +26 -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 +26 -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 +17 -0
- data/lib/pagy/toolbox/helpers/anchor_tags.rb +25 -0
- data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +24 -0
- data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +18 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +29 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +21 -0
- data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +21 -0
- data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +19 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +28 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +20 -0
- data/lib/pagy/toolbox/helpers/data_hash.rb +27 -0
- data/lib/pagy/toolbox/helpers/headers_hash.rb +29 -0
- data/lib/pagy/toolbox/helpers/info_tag.rb +26 -0
- data/lib/pagy/toolbox/helpers/input_nav_js.rb +18 -0
- data/lib/pagy/toolbox/helpers/limit_tag_js.rb +23 -0
- data/lib/pagy/toolbox/helpers/loader.rb +33 -0
- data/lib/pagy/toolbox/helpers/page_url.rb +18 -0
- data/lib/pagy/toolbox/helpers/series_nav.rb +28 -0
- data/lib/pagy/toolbox/helpers/series_nav_js.rb +18 -0
- data/lib/pagy/toolbox/helpers/support/a_lambda.rb +35 -0
- data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +15 -0
- data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +12 -0
- data/lib/pagy/toolbox/helpers/support/series.rb +38 -0
- data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +20 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +17 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +37 -0
- data/lib/pagy/toolbox/helpers/urls_hash.rb +13 -0
- data/lib/pagy/toolbox/paginators/calendar.rb +29 -0
- data/lib/pagy/toolbox/paginators/countish.rb +37 -0
- data/lib/pagy/toolbox/paginators/countless.rb +20 -0
- data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +50 -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 +31 -0
- data/lib/pagy/toolbox/paginators/method.rb +35 -0
- data/lib/pagy/toolbox/paginators/offset.rb +18 -0
- data/lib/pagy/toolbox/paginators/searchkick.rb +31 -0
- data/lib/pagy.rb +59 -97
- 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/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 +64 -0
- data/stylesheets/pagy.css +63 -27
- metadata +118 -52
- data/javascripts/pagy.min.js.map +0 -10
- 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.2.0'
|
|
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,23 @@ 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
45
|
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
51
|
-
@pagy, @pets =
|
|
46
|
+
@pagy, @pets = pagy(:keyset, Pet.order(@order), limit: 10, client_max_limit: 100)
|
|
47
|
+
# response.headers.merge!(@pagy.headers_hash)
|
|
52
48
|
erb :main
|
|
53
49
|
end
|
|
54
50
|
|
|
55
51
|
helpers do
|
|
56
|
-
include Pagy::Frontend
|
|
57
|
-
|
|
58
52
|
def order_symbol(dir)
|
|
59
53
|
{ asc: '↗', desc: '↘' }[dir]
|
|
60
54
|
end
|
|
@@ -81,11 +75,11 @@ class PagyKeyset < Sinatra::Base
|
|
|
81
75
|
margin: 0 !important;
|
|
82
76
|
font-family: sans-serif !important;
|
|
83
77
|
}
|
|
84
|
-
.content {
|
|
78
|
+
.main-content {
|
|
85
79
|
padding: 1rem 1.5rem 2rem !important;
|
|
86
80
|
}
|
|
87
81
|
|
|
88
|
-
<%= Pagy.
|
|
82
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
89
83
|
</style>
|
|
90
84
|
</head>
|
|
91
85
|
<body>
|
|
@@ -97,10 +91,10 @@ class PagyKeyset < Sinatra::Base
|
|
|
97
91
|
|
|
98
92
|
template :main do
|
|
99
93
|
<<~ERB
|
|
100
|
-
<div class="content">
|
|
94
|
+
<div class="main-content">
|
|
101
95
|
<h1>Pagy Keyset App</h1>
|
|
102
|
-
<p>Self-contained, standalone app usable to easily reproduce any
|
|
103
|
-
|
|
96
|
+
<p>Self-contained, standalone app usable to easily reproduce any Keyset related pagy issue with ActiveRecord sets.</p>
|
|
97
|
+
|
|
104
98
|
<h2>Versions</h2>
|
|
105
99
|
<ul>
|
|
106
100
|
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
@@ -111,12 +105,12 @@ class PagyKeyset < Sinatra::Base
|
|
|
111
105
|
|
|
112
106
|
<h3>Collection</h3>
|
|
113
107
|
<div id="records" class="collection">
|
|
114
|
-
<table border="1"
|
|
108
|
+
<table border="1" style="border-collapse: collapse; border-spacing: 0; padding: 0.2rem;">
|
|
115
109
|
<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>
|
|
110
|
+
<th scope="col">animal <%= order_symbol(@order[:animal]) %></th>
|
|
111
|
+
<th scope="col">name <%= order_symbol(@order[:name]) %></th>
|
|
112
|
+
<th scope="col">birthdate <%= order_symbol(@order[:birthdate]) %></th>
|
|
113
|
+
<th scope="col">id <%= order_symbol(@order[:id]) %></th>
|
|
120
114
|
</tr>
|
|
121
115
|
<% @pets.each do |pet| %>
|
|
122
116
|
<tr>
|
|
@@ -130,7 +124,7 @@ class PagyKeyset < Sinatra::Base
|
|
|
130
124
|
</div>
|
|
131
125
|
<p>
|
|
132
126
|
<nav class="pagy" id="next" aria-label="Pagy next">
|
|
133
|
-
<%=
|
|
127
|
+
<%= @pagy.next_tag(text: 'Next page >') %>
|
|
134
128
|
</nav>
|
|
135
129
|
</div>
|
|
136
130
|
ERB
|
|
@@ -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.2.0'
|
|
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
44
|
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
50
|
-
@pagy, @pets =
|
|
45
|
+
@pagy, @pets = pagy(:keyset, Pet.order(:animal, :name, Sequel.desc(:birthdate), :id),
|
|
46
|
+
limit: 10, client_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
|
|
@@ -80,11 +74,11 @@ class PagyKeyset < Sinatra::Base
|
|
|
80
74
|
margin: 0 !important;
|
|
81
75
|
font-family: sans-serif !important;
|
|
82
76
|
}
|
|
83
|
-
.content {
|
|
77
|
+
.main-content {
|
|
84
78
|
padding: 1rem 1.5rem 2rem !important;
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
<%= Pagy.
|
|
81
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
88
82
|
</style>
|
|
89
83
|
</head>
|
|
90
84
|
<body>
|
|
@@ -96,10 +90,10 @@ class PagyKeyset < Sinatra::Base
|
|
|
96
90
|
|
|
97
91
|
template :main do
|
|
98
92
|
<<~ERB
|
|
99
|
-
<div class="content">
|
|
93
|
+
<div class="main-content">
|
|
100
94
|
<h1>Pagy Keyset App</h1>
|
|
101
|
-
<p>Self-contained, standalone app usable to easily reproduce any
|
|
102
|
-
|
|
95
|
+
<p>Self-contained, standalone app usable to easily reproduce any Keyset related pagy issue with Sequel sets.</p>
|
|
96
|
+
|
|
103
97
|
<h2>Versions</h2>
|
|
104
98
|
<ul>
|
|
105
99
|
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
@@ -129,7 +123,7 @@ class PagyKeyset < Sinatra::Base
|
|
|
129
123
|
</div>
|
|
130
124
|
<p>
|
|
131
125
|
<nav class="pagy" id="next" aria-label="Pagy next">
|
|
132
|
-
<%=
|
|
126
|
+
<%= @pagy.next_tag(text: 'Next page >') %>
|
|
133
127
|
</nav>
|
|
134
128
|
</div>
|
|
135
129
|
ERB
|
|
@@ -217,4 +211,4 @@ data.each_line(chomp: true) do |pet|
|
|
|
217
211
|
dataset.insert(name:, animal:, birthdate:)
|
|
218
212
|
end
|
|
219
213
|
|
|
220
|
-
run
|
|
214
|
+
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.2.0'
|
|
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'
|
|
@@ -52,21 +54,12 @@ class PagyRails < Rails::Application # :nodoc:
|
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
# AR config
|
|
55
|
-
dir = Rails.env.development? ? '.' : Dir.pwd
|
|
57
|
+
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
|
56
58
|
unless File.writable?(dir)
|
|
57
59
|
warn "ERROR: directory #{dir.inspect} is not writable (the pagy-rails-app needs to create DB files)"
|
|
58
60
|
exit 1
|
|
59
61
|
end
|
|
60
62
|
|
|
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
63
|
# Activerecord initializer
|
|
71
64
|
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
|
72
65
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-rails.sqlite3")
|
|
@@ -84,11 +77,15 @@ end
|
|
|
84
77
|
# Models
|
|
85
78
|
class Post < ActiveRecord::Base # :nodoc:
|
|
86
79
|
has_many :comments
|
|
87
|
-
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# :nodoc:
|
|
88
83
|
|
|
89
84
|
class Comment < ActiveRecord::Base # :nodoc:
|
|
90
85
|
belongs_to :post
|
|
91
|
-
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# :nodoc:
|
|
92
89
|
|
|
93
90
|
# Unused model, useful to test overriding conflicts
|
|
94
91
|
module Calendar
|
|
@@ -102,31 +99,27 @@ Post.all.each_with_index do |post, pi|
|
|
|
102
99
|
2.times { |ci| Comment.create(post:, body: "Comment #{ci + 1} to Post #{pi + 1}") }
|
|
103
100
|
end
|
|
104
101
|
|
|
105
|
-
# Helpers
|
|
106
|
-
module CommentsHelper
|
|
107
|
-
include Pagy::Frontend
|
|
108
|
-
end
|
|
109
|
-
|
|
110
102
|
# Controllers
|
|
111
103
|
class CommentsController < ActionController::Base # :nodoc:
|
|
112
104
|
include Rails.application.routes.url_helpers
|
|
113
|
-
include Pagy::
|
|
105
|
+
include Pagy::Method
|
|
114
106
|
|
|
115
107
|
def index
|
|
116
|
-
@pagy, @comments = pagy(Comment.all)
|
|
117
|
-
|
|
108
|
+
@pagy, @comments = pagy(:offset, Comment.all, limit: 10, client_max_limit: 100)
|
|
109
|
+
# Reload the page in the network tab of the Chrome Inspector to check
|
|
110
|
+
# response.headers.merge!(@pagy.headers_hash)
|
|
118
111
|
render inline: TEMPLATE
|
|
119
112
|
end
|
|
120
113
|
end
|
|
121
114
|
|
|
122
|
-
# You don't need this in real rails apps (see https://ddnexus.github.io/pagy/
|
|
115
|
+
# You don't need this in real rails apps (see https://ddnexus.github.io/pagy/resources/javascripts)
|
|
123
116
|
class PagyController < ActionController::Base
|
|
124
117
|
def javascripts
|
|
125
118
|
format = params[:file].split('.').last
|
|
126
119
|
if format == 'js'
|
|
127
|
-
render js: Pagy.
|
|
120
|
+
render js: Pagy::ROOT.join('javascripts', params[:file]).read
|
|
128
121
|
elsif format == 'map'
|
|
129
|
-
render json: Pagy.
|
|
122
|
+
render json: Pagy::ROOT.join('javascripts', params[:file]).read
|
|
130
123
|
end
|
|
131
124
|
end
|
|
132
125
|
end
|
|
@@ -139,7 +132,7 @@ TEMPLATE = <<~ERB
|
|
|
139
132
|
<html>
|
|
140
133
|
<head>
|
|
141
134
|
<title>Pagy Rails App</title>
|
|
142
|
-
<script src="/javascripts/pagy.
|
|
135
|
+
<script src="/javascripts/pagy.js"></script>
|
|
143
136
|
<script>
|
|
144
137
|
window.addEventListener("load", Pagy.init);
|
|
145
138
|
</script>
|
|
@@ -156,9 +149,15 @@ TEMPLATE = <<~ERB
|
|
|
156
149
|
margin: 0 !important;
|
|
157
150
|
font-family: sans-serif !important;
|
|
158
151
|
}
|
|
159
|
-
.content {
|
|
152
|
+
.main-content {
|
|
160
153
|
padding: 1rem 1.5rem 2rem !important;
|
|
161
154
|
}
|
|
155
|
+
.pagy, .pagy-bootstrap, .pagy-bulma {
|
|
156
|
+
padding: .5em;
|
|
157
|
+
margin: .3em 0;
|
|
158
|
+
width: fit-content;
|
|
159
|
+
box-shadow: 5px 5px 10px 0px rgba(0,0,0,0.2);
|
|
160
|
+
}
|
|
162
161
|
|
|
163
162
|
/* Quick demo for overriding the element style attribute of certain pagy helpers
|
|
164
163
|
.pagy input[style] {
|
|
@@ -170,16 +169,16 @@ TEMPLATE = <<~ERB
|
|
|
170
169
|
If you want to customize the style,
|
|
171
170
|
please replace the line below with the actual file content
|
|
172
171
|
*/
|
|
173
|
-
<%== Pagy.
|
|
172
|
+
<%== Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
174
173
|
</style>
|
|
175
174
|
</head>
|
|
176
175
|
|
|
177
176
|
<body>
|
|
178
177
|
|
|
179
|
-
<div class="content">
|
|
178
|
+
<div class="main-content">
|
|
180
179
|
<h1>Pagy Rails App</h1>
|
|
181
180
|
<p> Self-contained, standalone Rails app usable to easily reproduce any rails related pagy issue.</p>
|
|
182
|
-
|
|
181
|
+
|
|
183
182
|
<h2>Versions</h2>
|
|
184
183
|
<ul>
|
|
185
184
|
<li>Ruby: <%== RUBY_VERSION %></li>
|
|
@@ -194,22 +193,26 @@ TEMPLATE = <<~ERB
|
|
|
194
193
|
<p style="margin: 0;"><%= comment.body %></p>
|
|
195
194
|
<% end %>
|
|
196
195
|
</div>
|
|
196
|
+
|
|
197
197
|
<hr>
|
|
198
198
|
|
|
199
|
-
<h4
|
|
200
|
-
<%==
|
|
199
|
+
<h4>@pagy.series_nav</h4>
|
|
200
|
+
<%== @pagy.series_nav(id: 'series-nav',
|
|
201
|
+
aria_label: 'Pages nav') %>
|
|
201
202
|
|
|
202
|
-
<h4
|
|
203
|
-
<%==
|
|
203
|
+
<h4>@pagy.series_nav_js</h4>
|
|
204
|
+
<%== @pagy.series_nav_js(id: 'series-nav-js',
|
|
205
|
+
aria_label: 'Pages nav_js') %>
|
|
204
206
|
|
|
205
|
-
<h4
|
|
206
|
-
<%==
|
|
207
|
+
<h4>@pagy.input_nav_js</h4>
|
|
208
|
+
<%== @pagy.input_nav_js(id: 'input-nav-js',
|
|
209
|
+
aria_label: 'Pages input_nav_js') %>
|
|
207
210
|
|
|
208
|
-
<h4
|
|
209
|
-
<%==
|
|
211
|
+
<h4>@pagy.limit_tag_js</h4>
|
|
212
|
+
<%== @pagy.limit_tag_js(id: 'limit-tag-js') %>
|
|
210
213
|
|
|
211
|
-
<h4
|
|
212
|
-
<%==
|
|
214
|
+
<h4>@pagy.info_tag</h4>
|
|
215
|
+
<%== @pagy.info_tag(id: 'pagy-info') %>
|
|
213
216
|
</div>
|
|
214
217
|
|
|
215
218
|
</body>
|
data/apps/repro.ru
CHANGED
|
@@ -4,44 +4,43 @@
|
|
|
4
4
|
# Reproduce generic/simple issues
|
|
5
5
|
#
|
|
6
6
|
# DOC
|
|
7
|
-
# https://ddnexus.github.io/pagy/playground/#
|
|
7
|
+
# https://ddnexus.github.io/pagy/playground/#repro-app
|
|
8
8
|
#
|
|
9
9
|
# BIN HELP
|
|
10
|
-
#
|
|
10
|
+
# pagy -h
|
|
11
11
|
#
|
|
12
12
|
# DEV USAGE
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# pagy clone repro
|
|
14
|
+
# pagy ./repro.ru
|
|
15
15
|
#
|
|
16
16
|
# URL
|
|
17
|
-
# http://
|
|
17
|
+
# http://127.0.0.1:8000
|
|
18
18
|
|
|
19
|
-
VERSION = '
|
|
19
|
+
VERSION = '43.2.0'
|
|
20
|
+
|
|
21
|
+
if VERSION != Pagy::VERSION
|
|
22
|
+
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
23
|
+
end
|
|
24
|
+
run_from_repo = Pagy::ROOT.join('pagy.gemspec').exist?
|
|
20
25
|
|
|
21
26
|
# Bundle
|
|
22
27
|
require 'bundler/inline'
|
|
23
|
-
|
|
24
|
-
Bundler.configure
|
|
25
|
-
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
28
|
+
gemfile(!run_from_repo) do
|
|
26
29
|
source 'https://rubygems.org'
|
|
27
30
|
gem 'oj'
|
|
28
31
|
gem 'puma'
|
|
29
32
|
gem 'sinatra'
|
|
30
33
|
end
|
|
31
34
|
|
|
32
|
-
# Edit this section adding
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
require 'pagy/extras/limit'
|
|
36
|
-
require 'pagy/extras/overflow'
|
|
37
|
-
Pagy::DEFAULT[:overflow] = :empty_page
|
|
38
|
-
Pagy::DEFAULT.freeze
|
|
35
|
+
# Edit this section adding the legacy as needed
|
|
36
|
+
# Pagy initializer
|
|
37
|
+
Pagy.options[:client_max_limit] = 100
|
|
39
38
|
|
|
40
39
|
# Sinatra setup
|
|
41
40
|
require 'sinatra/base'
|
|
42
41
|
# Sinatra application
|
|
43
42
|
class PagyRepro < Sinatra::Base
|
|
44
|
-
include Pagy::
|
|
43
|
+
include Pagy::Method
|
|
45
44
|
|
|
46
45
|
get('/javascripts/:file') do
|
|
47
46
|
format = params[:file].split('.').last
|
|
@@ -50,21 +49,21 @@ class PagyRepro < Sinatra::Base
|
|
|
50
49
|
elsif format == 'map'
|
|
51
50
|
content_type 'application/json'
|
|
52
51
|
end
|
|
53
|
-
send_file Pagy.
|
|
52
|
+
send_file Pagy::ROOT.join('javascripts', params[:file])
|
|
54
53
|
end
|
|
55
54
|
|
|
56
55
|
# Edit this action as needed
|
|
57
56
|
get '/' do
|
|
58
57
|
collection = MockCollection.new
|
|
59
|
-
@pagy, @records = pagy(collection)
|
|
58
|
+
@pagy, @records = pagy(collection) # simplest form
|
|
59
|
+
# @pagy, @records = pagy(:offset, collection, limit: 7, client_max_limit: 30)
|
|
60
|
+
# @pagy, @records = pagy(:countish, collection, ttl: 20)
|
|
61
|
+
# @pagy, @records = pagy(:countless, collection)
|
|
62
|
+
# @pagy, @records = pagy(Array(1..1000))
|
|
63
|
+
# response.headers.merge!(@pagy.headers_hash)
|
|
60
64
|
erb :main
|
|
61
65
|
end
|
|
62
66
|
|
|
63
|
-
# Edit this section adding your own helpers as needed
|
|
64
|
-
helpers do
|
|
65
|
-
include Pagy::Frontend
|
|
66
|
-
end
|
|
67
|
-
|
|
68
67
|
# Views
|
|
69
68
|
template :layout do
|
|
70
69
|
<<~ERB
|
|
@@ -73,7 +72,7 @@ class PagyRepro < Sinatra::Base
|
|
|
73
72
|
<html>
|
|
74
73
|
<head>
|
|
75
74
|
<title>Pagy Repro App</title>
|
|
76
|
-
<script src="javascripts/pagy.
|
|
75
|
+
<script src="javascripts/pagy.js"></script>
|
|
77
76
|
<script>
|
|
78
77
|
window.addEventListener("load", Pagy.init);
|
|
79
78
|
</script>
|
|
@@ -90,10 +89,15 @@ class PagyRepro < Sinatra::Base
|
|
|
90
89
|
margin: 0 !important;
|
|
91
90
|
font-family: sans-serif !important;
|
|
92
91
|
}
|
|
93
|
-
.content {
|
|
92
|
+
.main-content {
|
|
94
93
|
padding: 1rem 1.5rem 2rem !important;
|
|
95
94
|
}
|
|
96
|
-
|
|
95
|
+
.pagy, .pagy-bootstrap, .pagy-bulma {
|
|
96
|
+
padding: .5em;
|
|
97
|
+
margin: .3em 0;
|
|
98
|
+
width: fit-content;
|
|
99
|
+
box-shadow: 5px 5px 10px 0px rgba(0,0,0,0.2);
|
|
100
|
+
}
|
|
97
101
|
/* Quick demo for overriding the element style attribute of certain pagy helpers
|
|
98
102
|
.pagy input[style] {
|
|
99
103
|
width: 5rem !important;
|
|
@@ -104,7 +108,7 @@ class PagyRepro < Sinatra::Base
|
|
|
104
108
|
If you want to customize the style,
|
|
105
109
|
please replace the line below with the actual file content
|
|
106
110
|
*/
|
|
107
|
-
<%= Pagy.
|
|
111
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
108
112
|
</style>
|
|
109
113
|
</head>
|
|
110
114
|
<body>
|
|
@@ -116,10 +120,10 @@ class PagyRepro < Sinatra::Base
|
|
|
116
120
|
|
|
117
121
|
template :main do
|
|
118
122
|
<<~ERB
|
|
119
|
-
<div class="content">
|
|
123
|
+
<div class="main-content">
|
|
120
124
|
<h1>Pagy Repro App</h1>
|
|
121
125
|
<p> Self-contained, standalone app usable to easily reproduce any pagy issue.</p>
|
|
122
|
-
|
|
126
|
+
|
|
123
127
|
<h2>Versions</h4>
|
|
124
128
|
<ul>
|
|
125
129
|
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
@@ -133,31 +137,31 @@ class PagyRepro < Sinatra::Base
|
|
|
133
137
|
|
|
134
138
|
<hr>
|
|
135
139
|
|
|
136
|
-
<h4
|
|
137
|
-
<%=
|
|
138
|
-
|
|
139
|
-
<h4>pagy_nav_js</h4>
|
|
140
|
-
<%= pagy_nav_js(@pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
|
|
140
|
+
<h4>@pagy.series_nav</h4>
|
|
141
|
+
<%= @pagy.series_nav(id: 'series-nav',
|
|
142
|
+
aria_label: 'Pages nav') %>
|
|
141
143
|
|
|
142
|
-
<h4
|
|
143
|
-
<%=
|
|
144
|
-
|
|
144
|
+
<h4>@pagy.series_nav_js (responsive)</h4>
|
|
145
|
+
<%= @pagy.series_nav_js(id: 'series-nav-js-responsive',
|
|
146
|
+
aria_label: 'Pages nav_js_responsove',
|
|
147
|
+
steps: { 0 => 5, 500 => 7, 600 => 9, 700 => 11 }) %>
|
|
145
148
|
|
|
146
|
-
<h4
|
|
147
|
-
<%=
|
|
149
|
+
<h4>@pagy.input_nav_js</h4>
|
|
150
|
+
<%= @pagy.input_nav_js(id: 'input-nav-js',
|
|
151
|
+
aria_label: 'Pages input_nav_js') %>
|
|
148
152
|
|
|
149
|
-
<h4
|
|
150
|
-
<%=
|
|
153
|
+
<h4>@pagy.limit_tag_js</h4>
|
|
154
|
+
<%= @pagy.limit_tag_js(id: 'limit-tag-js') %>
|
|
151
155
|
|
|
152
|
-
<h4
|
|
153
|
-
<%=
|
|
156
|
+
<h4>@pagy.info_tag</h4>
|
|
157
|
+
<%= @pagy.info_tag(id: 'pagy-info') %>
|
|
154
158
|
</div>
|
|
155
159
|
ERB
|
|
156
160
|
end
|
|
157
161
|
end
|
|
158
162
|
|
|
159
163
|
# Simple array-based collection that acts as a standard DB collection.
|
|
160
|
-
# Use it as a simple way to get a collection that acts as
|
|
164
|
+
# Use it as a simple way to get a collection that acts as an AR scope, but without any DB
|
|
161
165
|
# or create an ActiveRecord class or anything else that you need instead
|
|
162
166
|
class MockCollection < Array
|
|
163
167
|
def initialize(arr = Array(1..1000))
|
|
@@ -166,12 +170,12 @@ class MockCollection < Array
|
|
|
166
170
|
end
|
|
167
171
|
|
|
168
172
|
def offset(value)
|
|
169
|
-
@collection = self[value..]
|
|
173
|
+
@collection = self[value..] || []
|
|
170
174
|
self
|
|
171
175
|
end
|
|
172
176
|
|
|
173
177
|
def limit(value)
|
|
174
|
-
@collection[0, value]
|
|
178
|
+
@collection.empty? ? [] : @collection[0, value]
|
|
175
179
|
end
|
|
176
180
|
|
|
177
181
|
def count(*)
|