pagy 9.3.3 → 43.0.0.rc1

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.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/apps/calendar.ru +547 -551
  4. data/apps/demo.ru +221 -178
  5. data/apps/index.rb +3 -1
  6. data/apps/keynav.ru +258 -0
  7. data/apps/{keyset_ar.ru → keyset.ru} +27 -32
  8. data/apps/{keyset_s.ru → keyset_sequel.ru} +24 -29
  9. data/apps/rails.ru +51 -48
  10. data/apps/repro.ru +46 -43
  11. data/bin/pagy +22 -23
  12. data/config/pagy.rb +35 -207
  13. data/javascripts/ai_widget.js +76 -0
  14. data/javascripts/pagy.js +151 -0
  15. data/javascripts/pagy.js.map +10 -0
  16. data/javascripts/pagy.min.js +1 -4
  17. data/javascripts/pagy.mjs +111 -63
  18. data/javascripts/wand.js +1166 -0
  19. data/lib/pagy/classes/calendar/calendar.rb +98 -0
  20. data/lib/pagy/{calendar → classes/calendar}/day.rb +7 -11
  21. data/lib/pagy/{calendar → classes/calendar}/month.rb +5 -10
  22. data/lib/pagy/{calendar → classes/calendar}/quarter.rb +10 -15
  23. data/lib/pagy/classes/calendar/unit.rb +92 -0
  24. data/lib/pagy/{calendar → classes/calendar}/week.rb +5 -9
  25. data/lib/pagy/{calendar → classes/calendar}/year.rb +5 -6
  26. data/lib/pagy/classes/exceptions.rb +33 -0
  27. data/lib/pagy/classes/keyset/active_record.rb +11 -0
  28. data/lib/pagy/classes/keyset/adapters/active_record.rb +50 -0
  29. data/lib/pagy/classes/keyset/adapters/sequel.rb +63 -0
  30. data/lib/pagy/classes/keyset/keynav/active_record.rb +13 -0
  31. data/lib/pagy/classes/keyset/keynav/sequel.rb +13 -0
  32. data/lib/pagy/classes/keyset/keynav.rb +77 -0
  33. data/lib/pagy/classes/keyset/keyset.rb +126 -0
  34. data/lib/pagy/classes/keyset/sequel.rb +11 -0
  35. data/lib/pagy/classes/offset/countless.rb +56 -0
  36. data/lib/pagy/classes/offset/offset.rb +54 -0
  37. data/lib/pagy/classes/offset/search.rb +38 -0
  38. data/lib/pagy/classes/request.rb +36 -0
  39. data/lib/pagy/modules/abilities/configurable.rb +36 -0
  40. data/lib/pagy/modules/abilities/linkable.rb +59 -0
  41. data/lib/pagy/modules/abilities/rangeable.rb +15 -0
  42. data/lib/pagy/modules/abilities/shiftable.rb +12 -0
  43. data/lib/pagy/{b64.rb → modules/b64.rb} +3 -7
  44. data/lib/pagy/modules/console.rb +38 -0
  45. data/lib/pagy/modules/i18n/i18n.rb +48 -0
  46. data/lib/pagy/modules/i18n/p11n/arabic.rb +29 -0
  47. data/lib/pagy/modules/i18n/p11n/east_slavic.rb +26 -0
  48. data/lib/pagy/modules/i18n/p11n/one_other.rb +15 -0
  49. data/lib/pagy/modules/i18n/p11n/one_upto_two_other.rb +15 -0
  50. data/lib/pagy/modules/i18n/p11n/other.rb +13 -0
  51. data/lib/pagy/modules/i18n/p11n/polish.rb +26 -0
  52. data/lib/pagy/modules/i18n/p11n/west_slavic.rb +22 -0
  53. data/lib/pagy/modules/i18n/p11n.rb +16 -0
  54. data/lib/pagy/modules/searcher.rb +20 -0
  55. data/lib/pagy/toolbox/helpers/anchor_tags.rb +25 -0
  56. data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +24 -0
  57. data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +18 -0
  58. data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +29 -0
  59. data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +21 -0
  60. data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +21 -0
  61. data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +19 -0
  62. data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +28 -0
  63. data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +20 -0
  64. data/lib/pagy/toolbox/helpers/data_hash.rb +26 -0
  65. data/lib/pagy/toolbox/helpers/headers_hash.rb +20 -0
  66. data/lib/pagy/toolbox/helpers/info_tag.rb +26 -0
  67. data/lib/pagy/toolbox/helpers/input_nav_js.rb +19 -0
  68. data/lib/pagy/toolbox/helpers/limit_tag_js.rb +23 -0
  69. data/lib/pagy/toolbox/helpers/loader.rb +33 -0
  70. data/lib/pagy/toolbox/helpers/page_url.rb +23 -0
  71. data/lib/pagy/toolbox/helpers/series_nav.rb +29 -0
  72. data/lib/pagy/toolbox/helpers/series_nav_js.rb +19 -0
  73. data/lib/pagy/toolbox/helpers/support/a_lambda.rb +34 -0
  74. data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +15 -0
  75. data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +12 -0
  76. data/lib/pagy/toolbox/helpers/support/series.rb +38 -0
  77. data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +20 -0
  78. data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +17 -0
  79. data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +36 -0
  80. data/lib/pagy/toolbox/helpers/urls_hash.rb +13 -0
  81. data/lib/pagy/toolbox/paginators/calendar.rb +30 -0
  82. data/lib/pagy/toolbox/paginators/countless.rb +25 -0
  83. data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +32 -0
  84. data/lib/pagy/toolbox/paginators/keynav_js.rb +29 -0
  85. data/lib/pagy/toolbox/paginators/keyset.rb +18 -0
  86. data/lib/pagy/toolbox/paginators/meilisearch.rb +32 -0
  87. data/lib/pagy/toolbox/paginators/method.rb +26 -0
  88. data/lib/pagy/toolbox/paginators/offset.rb +33 -0
  89. data/lib/pagy/toolbox/paginators/searchkick.rb +32 -0
  90. data/lib/pagy.rb +59 -97
  91. data/locales/ar.yml +9 -6
  92. data/locales/be.yml +9 -6
  93. data/locales/bg.yml +9 -6
  94. data/locales/bs.yml +9 -6
  95. data/locales/ca.yml +9 -6
  96. data/locales/ckb.yml +8 -6
  97. data/locales/cs.yml +9 -6
  98. data/locales/da.yml +9 -6
  99. data/locales/de.yml +9 -6
  100. data/locales/dz.yml +9 -6
  101. data/locales/en.yml +9 -6
  102. data/locales/es.yml +9 -6
  103. data/locales/fr.yml +9 -6
  104. data/locales/hr.yml +9 -6
  105. data/locales/id.yml +9 -6
  106. data/locales/it.yml +9 -6
  107. data/locales/ja.yml +9 -6
  108. data/locales/km.yml +9 -6
  109. data/locales/ko.yml +9 -6
  110. data/locales/nb.yml +9 -6
  111. data/locales/nl.yml +9 -6
  112. data/locales/nn.yml +9 -6
  113. data/locales/pl.yml +9 -6
  114. data/locales/pt-BR.yml +10 -7
  115. data/locales/pt.yml +10 -7
  116. data/locales/ru.yml +9 -6
  117. data/locales/sr.yml +9 -6
  118. data/locales/sv-SE.yml +9 -6
  119. data/locales/sv.yml +9 -6
  120. data/locales/sw.yml +12 -9
  121. data/locales/ta.yml +12 -9
  122. data/locales/tr.yml +9 -6
  123. data/locales/uk.yml +9 -6
  124. data/locales/vi.yml +9 -6
  125. data/locales/zh-CN.yml +9 -6
  126. data/locales/zh-HK.yml +9 -6
  127. data/locales/zh-TW.yml +9 -6
  128. data/stylesheets/pagy-tailwind.css +64 -0
  129. data/stylesheets/pagy.css +63 -27
  130. metadata +114 -56
  131. data/javascripts/pagy.min.js.map +0 -10
  132. data/lib/pagy/backend.rb +0 -44
  133. data/lib/pagy/calendar/unit.rb +0 -103
  134. data/lib/pagy/calendar.rb +0 -84
  135. data/lib/pagy/console.rb +0 -23
  136. data/lib/pagy/countless.rb +0 -38
  137. data/lib/pagy/exceptions.rb +0 -25
  138. data/lib/pagy/extras/arel.rb +0 -28
  139. data/lib/pagy/extras/array.rb +0 -19
  140. data/lib/pagy/extras/bootstrap.rb +0 -97
  141. data/lib/pagy/extras/bulma.rb +0 -93
  142. data/lib/pagy/extras/calendar.rb +0 -79
  143. data/lib/pagy/extras/countless.rb +0 -32
  144. data/lib/pagy/extras/elasticsearch_rails.rb +0 -71
  145. data/lib/pagy/extras/gearbox.rb +0 -55
  146. data/lib/pagy/extras/headers.rb +0 -54
  147. data/lib/pagy/extras/i18n.rb +0 -26
  148. data/lib/pagy/extras/js_tools.rb +0 -70
  149. data/lib/pagy/extras/jsonapi.rb +0 -86
  150. data/lib/pagy/extras/keyset.rb +0 -30
  151. data/lib/pagy/extras/limit.rb +0 -63
  152. data/lib/pagy/extras/meilisearch.rb +0 -57
  153. data/lib/pagy/extras/metadata.rb +0 -42
  154. data/lib/pagy/extras/overflow.rb +0 -81
  155. data/lib/pagy/extras/pagy.rb +0 -82
  156. data/lib/pagy/extras/searchkick.rb +0 -59
  157. data/lib/pagy/extras/size.rb +0 -40
  158. data/lib/pagy/extras/standalone.rb +0 -60
  159. data/lib/pagy/extras/trim.rb +0 -29
  160. data/lib/pagy/frontend.rb +0 -99
  161. data/lib/pagy/i18n.rb +0 -166
  162. data/lib/pagy/keyset/active_record.rb +0 -38
  163. data/lib/pagy/keyset/sequel.rb +0 -51
  164. data/lib/pagy/keyset.rb +0 -118
  165. data/lib/pagy/shared_methods.rb +0 -26
  166. data/lib/pagy/url_helpers.rb +0 -26
  167. data/stylesheets/pagy.scss +0 -48
  168. data/stylesheets/pagy.tailwind.css +0 -21
data/apps/demo.ru CHANGED
@@ -4,28 +4,30 @@
4
4
  # Showcase all the helpers and styles
5
5
  #
6
6
  # DOC
7
- # https://ddnexus.github.io/pagy/playground/#3-demo-app
7
+ # https://ddnexus.github.io/pagy/playground/#demo-app
8
8
  #
9
9
  # BIN HELP
10
- # bundle exec pagy -h
10
+ # pagy -h
11
11
  #
12
12
  # DEMO USAGE
13
- # bundle exec pagy demo
13
+ # pagy demo
14
14
  #
15
15
  # DEV USAGE
16
- # bundle exec pagy clone demo
17
- # bundle exec pagy ./demo.ru
16
+ # pagy clone demo
17
+ # pagy ./demo.ru
18
18
  #
19
19
  # URL
20
- # http://0.0.0.0:8000
20
+ # http://127.0.0.1:8000
21
21
 
22
- VERSION = '9.3.3'
22
+ VERSION = '43.0.0.rc1'
23
+
24
+ if VERSION != Pagy::VERSION
25
+ Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
26
+ end
23
27
 
24
28
  # Bundle
25
29
  require 'bundler/inline'
26
- require 'bundler'
27
- Bundler.configure
28
- gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
30
+ gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do
29
31
  source 'https://rubygems.org'
30
32
  gem 'oj'
31
33
  gem 'puma'
@@ -34,36 +36,26 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
34
36
  end
35
37
 
36
38
  # pagy initializer
37
- STYLES = { pagy: { extra: 'pagy', prefix: '', css_anchor: 'pagy-scss' },
38
- bootstrap: {},
39
- bulma: {},
40
- tailwind: { extra: 'pagy', prefix: '', css_anchor: 'pagy-tailwind-css' } }.freeze
41
-
42
- STYLES.each_key do |style|
43
- require "pagy/extras/#{STYLES[style][:extra] || style}"
44
- end
45
- require 'pagy/extras/limit'
46
- require 'pagy/extras/trim'
47
- Pagy::DEFAULT[:trim_extra] = false # opt-in trim
39
+ SECTIONS = { pagy: { css_anchor: 'pagy-css' },
40
+ tailwind: { css_anchor: 'pagy-tailwind-css' },
41
+ bootstrap: { style: :bootstrap, classes: 'pagination pagination-sm' },
42
+ bulma: { style: :bulma, classes: 'pagination is-small' },
43
+ template: { css_anchor: 'pagy-css', template: :template } }.freeze
48
44
 
49
45
  # Sinatra setup
50
46
  require 'sinatra/base'
51
47
 
48
+ # Pagy init
49
+ Pagy.options[:client_max_limit] = 100
50
+
52
51
  # Sinatra application
53
52
  class PagyDemo < Sinatra::Base
54
- include Pagy::Backend
53
+ include Pagy::Method
55
54
 
56
55
  get '/' do
57
56
  redirect '/pagy'
58
57
  end
59
58
 
60
- get '/template' do
61
- collection = MockCollection.new
62
- @pagy, @records = pagy(collection, trim_extra: params['trim'])
63
-
64
- erb :template, locals: { pagy: @pagy, style: 'pagy' }
65
- end
66
-
67
59
  get('/javascripts/:file') do
68
60
  format = params[:file].split('.').last
69
61
  if format == 'js'
@@ -71,34 +63,63 @@ class PagyDemo < Sinatra::Base
71
63
  elsif format == 'map'
72
64
  content_type 'application/json'
73
65
  end
74
- send_file Pagy.root.join('javascripts', params[:file])
66
+ send_file Pagy::ROOT.join('javascripts', params[:file])
75
67
  end
76
68
 
77
69
  get('/stylesheets/:file') do
78
70
  content_type 'text/css'
79
- send_file Pagy.root.join('stylesheets', params[:file])
71
+ send_file Pagy::ROOT.join('stylesheets', params[:file])
80
72
  end
81
73
 
82
74
  # One route/action per style
83
- STYLES.each_key do |style|
84
- prefix = STYLES[style][:prefix] || "_#{style}"
85
-
86
- get("/#{style}/?:trim?") do
87
- collection = MockCollection.new
88
- @pagy, @records = pagy(collection, trim_extra: params['trim'])
89
-
90
- erb :helpers, locals: { style:, prefix: }
75
+ SECTIONS.each do |section, value|
76
+ get("/#{section}") do
77
+ collection = MockCollection.new
78
+ @pagy, @records = pagy(:offset, collection)
79
+ erb value[:template] || :page,
80
+ locals: { section:,
81
+ pagy: @pagy,
82
+ style: value[:style],
83
+ classes: value[:classes],
84
+ css_anchor: value[:css_anchor] }
91
85
  end
92
86
  end
93
87
 
94
- helpers do
95
- include Pagy::Frontend
88
+ PAGY_LIKE_HEAD =
89
+ %(#{Pagy.dev_tools if ENV['CY_TEST'] != 'true'}
90
+ <style>
91
+ /* black/white backdrop color based on --B */
92
+ .pagy { background-color: hsl(0 0 calc(100 * var(--B))) !important; }
93
+ </style>).freeze
96
94
 
95
+ helpers do
97
96
  def style_menu
98
97
  html = +%(<div id="style-menu"> )
99
- STYLES.each_key { |style| html << %(<a href="/#{style}">#{style}</a>) }
100
- html << %(<a href="/template">template</a>)
98
+ SECTIONS.each_key do |section|
99
+ name = section.to_s
100
+ name[0] = name[0].capitalize
101
+ html << %(<a href="/#{section}">#{name}</a>)
102
+ end
101
103
  html << %(</div>)
104
+ html
105
+ end
106
+
107
+ def head_for(section)
108
+ case section
109
+ when :pagy, :template
110
+ %(#{PAGY_LIKE_HEAD}
111
+ <link rel="stylesheet" href="/stylesheets/pagy.css">)
112
+ when :tailwind
113
+ %(#{PAGY_LIKE_HEAD}
114
+ <script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script>
115
+ <style type="text/tailwindcss">
116
+ #{Pagy::ROOT.join('stylesheets/pagy-tailwind.css').read}
117
+ </style>)
118
+ when :bootstrap
119
+ %(<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">)
120
+ when :bulma
121
+ %(<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">)
122
+ end
102
123
  end
103
124
 
104
125
  def highlight(html, format: :html)
@@ -110,35 +131,53 @@ class PagyDemo < Sinatra::Base
110
131
  formatter = Rouge::Formatters::HTMLInline.new('monokai.sublime')
111
132
  summary = { html: 'Served HTML (pretty formatted)', erb: 'ERB Template' }
112
133
  %(<details><summary>#{summary[format]}</summary><pre>\n#{
113
- formatter.format(lexer.lex(html))
134
+ formatter.format(lexer.lex(html))
114
135
  }</pre></details>)
115
136
  end
116
137
  end
117
138
 
118
139
  # Views
119
140
  template :layout do
120
- <<~'ERB'
141
+ <<~HTML
121
142
  <!DOCTYPE html>
122
143
  <html lang="en">
123
144
  <head>
124
145
  <title>Pagy Demo App</title>
125
- <script src="/javascripts/pagy.min.js"></script>
126
- <script>
127
- window.addEventListener("load", Pagy.init);
128
- </script>
129
146
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
130
- <%= erb :"#{style}_head" if defined?(style) %>
131
- <style type="text/css">
147
+ <%= head_for(section) %>
148
+ <script src="/javascripts/pagy.js"></script>
149
+ <script>window.addEventListener("load", Pagy.init);</script>
150
+ <link rel="preconnect" href="https://fonts.googleapis.com">
151
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
152
+ <link href="https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,opsz,wght@0,6..12,200..1000;1,6..12,200..1000&display=swap" rel="stylesheet">
153
+ <style>
132
154
  @media screen { html, body {
133
155
  font-size: 1rem;
134
- line-height: 1.2s;
156
+ line-height: 1.2;
135
157
  padding: 0;
136
158
  margin: 0;
137
159
  } }
160
+ *,
161
+ *::before,
162
+ *::after {
163
+ box-sizing: border-box;
164
+ }
165
+ html {
166
+ background-color: transparent !important; /* Fix for Bulma */
167
+ }
138
168
  body {
139
- background: white !important;
140
169
  margin: 0 !important;
141
- font-family: sans-serif !important;
170
+ font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif !important;
171
+ color: #303030 !important;
172
+ background-color: #f5f5f5 !important;
173
+ }
174
+ svg {
175
+ position: fixed;
176
+ top: 0;
177
+ left: 0;
178
+ width: 100vw;
179
+ height: 100vh;
180
+ z-index: -10;
142
181
  }
143
182
  h1, h2 {
144
183
  font-size: 1.8rem !important;
@@ -146,16 +185,22 @@ class PagyDemo < Sinatra::Base
146
185
  margin-top: 1rem !important;
147
186
  margin-bottom: 0.7rem !important;
148
187
  line-height: 1.5 !important;
149
- color: rgb(90 90 90) !important;
188
+ color: #303030 !important;
150
189
  }
151
190
  h2 {
152
191
  font-family: monospace;
153
192
  font-size: .9rem !important;
154
193
  margin-top: 1.6rem !important;
155
194
  }
195
+ hr {
196
+ height: 0;
197
+ color: inherit;
198
+ border-top-width: 1px;
199
+ border-top-color: gray;
200
+ margin: 8px 0 !important;
201
+ }
156
202
  summary, .notes {
157
203
  font-size: .8rem;
158
- color: gray;
159
204
  margin-top: .6rem;
160
205
  font-style: italic;
161
206
  cursor: pointer;
@@ -165,7 +210,7 @@ class PagyDemo < Sinatra::Base
165
210
  font-weight: normal;
166
211
  }
167
212
  .notes code{
168
- background-color: #E8E8E8;
213
+ background-color: rgba(255, 255, 255, .6);
169
214
  padding: 0 0.3rem;
170
215
  font-style: normal;
171
216
  border-radius: 3px;
@@ -178,7 +223,7 @@ class PagyDemo < Sinatra::Base
178
223
  text-decoration: underline;
179
224
  }
180
225
  pre, pre code {
181
- display: block;
226
+ display: inline-block;
182
227
  margin-top: .3rem;
183
228
  margin-bottom: 1rem;
184
229
  font-size: .8rem !important;
@@ -186,12 +231,13 @@ class PagyDemo < Sinatra::Base
186
231
  color: white;
187
232
  background-color: rgb(30 30 30);
188
233
  padding: 1rem;
189
- overflow: auto;
234
+ overflow-x: auto;
235
+ max-width: 100%;
236
+ white-space: pre;
190
237
  }
191
- .content {
238
+ .main-content {
192
239
  padding: 0 1.5rem 2rem !important;
193
240
  }
194
-
195
241
  #style-menu {
196
242
  flex;
197
243
  font-family: sans-serif;
@@ -199,7 +245,7 @@ class PagyDemo < Sinatra::Base
199
245
  line-height: 1.5rem;
200
246
  white-space: nowrap;
201
247
  color: white;
202
- background-color: gray;
248
+ background-color: rgba(0,0,0,.65);
203
249
  padding: .2rem 1.5rem;
204
250
  }
205
251
  #style-menu > :not([hidden]) ~ :not([hidden]) {
@@ -211,158 +257,155 @@ class PagyDemo < Sinatra::Base
211
257
  color: inherit;
212
258
  text-decoration: none;
213
259
  }
214
- /* Quick demo for overriding the element style attribute of certain pagy helpers
215
- .pagy input[style] {
216
- width: 5rem !important;
260
+ .pagy, .pagy-bootstrap, .pagy-bulma {
261
+ background-color: white;
262
+ padding: 1.5em;
263
+ margin: .3em 0;
264
+ width: fit-content;
265
+ box-shadow: 8px 8px 18px 0px rgba(0,0,0,0.25);
266
+ }
267
+ span.pagy {
268
+ display: block;
269
+ }
270
+ .pagy-bootstrap .pagination {
271
+ margin: 0;
272
+ }
273
+ /* Demo app custom style */
274
+ .pagy {
275
+ --B: 1;
276
+ --H: 109;
277
+ --S: 40;
278
+ --L: 70;
279
+ --spacing: 0.125rem;
280
+ --padding: 0.75rem;
281
+ --rounding: 0.8125rem;
282
+ --border-width: 0.03125rem;
283
+ --font-size: 0.875rem;
284
+ --font-weight: 450;
285
+ --line-height: 1.75;
217
286
  }
218
- */
219
287
  </style>
220
288
  </head>
221
289
  <body>
290
+ <svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
291
+ <filter id="noiseFilter">
292
+ <feTurbulence type="fractalNoise" baseFrequency="0.6" numOctaves="100" stitchTiles="stitch" />
293
+ <feColorMatrix type="matrix" values="0.5 0 0 0 0, 0.5 0 0 0 0, 0.5 0 0 0 0, 0 0 0 0.5 0" />
294
+ </filter>
295
+ <rect width="100%" height="100%" filter="url(#noiseFilter)" fill="rgb(255, 255, 255)" />
296
+ </svg>
222
297
  <!-- each different class used by each style -->
223
298
  <%= style_menu %>
224
- <div class="content">
299
+ <div class="main-content">
225
300
  <%= yield %>
226
301
  </div>
227
302
  </body>
228
303
  </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
304
+ HTML
249
305
  end
250
306
 
251
- template :tailwind_head do
307
+ template :page do
252
308
  <<~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
309
+ <h1><%= title = section.to_s; title[0] = title[0].capitalize; title %></h1>
260
310
 
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
311
  <% 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) %>
312
+ <p>Check the <u><i><b><a href="http://ddnexus.github.io/pagy/resources/stylesheets/#<%= css_anchor %>" target="blank"><%= css_anchor.gsub('-', '.') %></a></b></u></i>
313
+ for details.</p>
315
314
  <% end %>
315
+ </p>
316
+ <div id="main-container">
317
+ <div id="content">
318
+ <hr id="top-hr">
319
+ <h2>@records</h2>
320
+ <p id="records"><%= @records.join(',') %></p>
321
+
322
+ <h2>@pagy.series_nav<br/>
323
+ <span class="notes">Series nav <code>{slots: 7}</code></span>
324
+ </h2>
325
+ <%= html = @pagy.series_nav(style, classes:,
326
+ id: 'series-nav',
327
+ aria_label: 'Pages series_nav') %>
328
+ <%= highlight(html) %>
329
+
330
+ <h2>@pagy.series_nav_js<br/>
331
+ <span class="notes">Responsive nav: <code>{steps: {0 => 5, 500 => 7, 600 => 9, 700 => 11}}</code><br/>
332
+ (Resize the window to see)
333
+ </span>
334
+ </h2>
335
+ <%= html = @pagy.series_nav_js(style, classes:,
336
+ id: 'series-nav-js-responsive',
337
+ aria_label: 'Pages series_nav_js_responsive',
338
+ steps: { 0 => 5, 500 => 7, 600 => 9, 700 => 11 }) %>
339
+ <%= highlight(html) %>
340
+
341
+ <h2>@pagy.input_nav_js</h2>
342
+ <%= html = @pagy.input_nav_js(style, classes:,
343
+ id: 'input-nav-js',
344
+ aria_label: 'Pages inpup_nav_js') %>
345
+ <%= highlight(html) %>
346
+
347
+ <h2>@pagy.limit_tag_js</h2>
348
+ <%= html = @pagy.limit_tag_js(id: 'limit-tag-js') %>
349
+ <%= highlight(html) %>
350
+
351
+ <h2>@pagy.info_tag</h2>
352
+ <%= html = @pagy.info_tag(id: 'pagy-info') %>
353
+ <%= highlight(html) %>
354
+ </div>
355
+ </div>
316
356
  ERB
317
357
  end
318
358
 
319
359
  template :template do
320
- <<~ERB
321
- <h1>Pagy Template Demo</h1>
360
+ <<~ERB
361
+ <h1>Pagy Template Demo</h1>
322
362
 
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>
363
+ <p class="description">
364
+ See the <a href="https://ddnexus.github.io/pagy/docs/how-to/#using-your-pagination-templates">
365
+ Custom Templates</a> documentation.
366
+ </p>
329
367
 
330
- <h2>Rendered ERB template</h2>
368
+ <h2>Collection</h2>
369
+ <p id="records">@records: <%= @records.join(',') %></p>
331
370
 
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
371
+ <h2>Rendered ERB template</h2>
372
+
373
+ <div class="backdrop">
374
+ <%# We don't inline the template here, so we can highlight it more easily %>
375
+ <%= html = ERB.new(TEMPLATE).result(binding) %>
376
+ </div>
377
+ <%= highlight(TEMPLATE, format: :erb) %>
378
+ <%= highlight(html) %>
379
+ ERB
380
+ end
338
381
 
339
382
  # Easier code highlighting
340
383
  TEMPLATE = <<~ERB
341
384
  <%# IMPORTANT: replace '<%=' with '<%==' if you run this in rails %>
342
385
 
343
386
  <%# 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">
387
+ <%# Usage: anchor_tag = a_lambda.(page_number, text, classes: nil, aria_label: nil) %>
388
+ <% a_lambda = @pagy.send(:a_lambda) %>
389
+ <nav class="pagy series-nav" aria-label="Pages">
347
390
  <%# Previous page link %>
348
- <% if pagy.prev %>
349
- <%= a.(pagy.prev, '&lt;', aria_label: 'Previous') %>
391
+ <% if pagy.previous %>
392
+ <%= a_lambda.(pagy.previous, '&lt;', aria_label: 'Previous') %>
350
393
  <% else %>
351
394
  <a role="link" aria-disabled="true" aria-label="Previous">&lt;</a>
352
395
  <% end %>
353
396
  <%# Page links (series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]) %>
354
- <% pagy.series.each do |item| %>
397
+ <% pagy.send(:series).each do |item| %>
355
398
  <% if item.is_a?(Integer) %>
356
- <%= a.(item) %>
399
+ <%= a_lambda.(item) %>
357
400
  <% elsif item.is_a?(String) %>
358
- <a role="link" aria-disabled="true" aria-current="page" class="current"><%= item %></a>
401
+ <a role="link" aria-disabled="true" aria-current="page"><%= item %></a>
359
402
  <% elsif item == :gap %>
360
- <a role="link" aria-disabled="true" class="gap">&hellip;</a>
403
+ <a role="separator" aria-disabled="true">&hellip;</a>
361
404
  <% end %>
362
405
  <% end %>
363
406
  <%# Next page link %>
364
407
  <% if pagy.next %>
365
- <%= a.(pagy.next, '&gt;', aria_label: 'Next') %>
408
+ <%= a_lambda.(pagy.next, '&gt;', aria_label: 'Next') %>
366
409
  <% else %>
367
410
  <a role="link" aria-disabled="true" aria-label="Next">&lt;</a>
368
411
  <% end %>
@@ -402,15 +445,15 @@ class Formatter
402
445
  push.(tag)
403
446
  elsif (match = input.match(PAIRED))
404
447
  tag_start, name, block, tag_end, rest = match.captures
405
- ## Handle incomplete same-tag nesting
448
+ # Handle incomplete same-tag nesting
406
449
  while block.scan(/<#{name}.*?>/).size > block.scan(tag_end).size
407
450
  more, rest = rest.split(tag_end, 2)
408
- block << tag_end << more
451
+ block << (tag_end + more)
409
452
  end
410
453
  if (match = tag_start.match(DATA_PAGY))
411
454
  search, data = match.captures
412
- formatted = data.scan(/.{1,76}/).join("\n")
413
- replace = %(\n#{INDENT * (level + 1)}data-pagy="#{formatted}")
455
+ formatted = data.scan(/.{1,76}/).join("\n")
456
+ replace = %(\n#{INDENT * (level + 1)}data-pagy="#{formatted}")
414
457
  tag_start.sub!(search, replace)
415
458
  end
416
459
  if block.match(WRAPPER)
@@ -418,7 +461,7 @@ class Formatter
418
461
  process(block, level + 1)
419
462
  push.(tag_end)
420
463
  else
421
- push.(tag_start << block << tag_end)
464
+ push.(tag_start << (block + tag_end))
422
465
  end
423
466
  end
424
467
  process(rest, level) if rest
data/apps/index.rb CHANGED
@@ -3,5 +3,7 @@
3
3
  # PagyApp module
4
4
  module PagyApps
5
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
6
+ INDEX = Dir[File.expand_path('./*.ru', __dir__)].to_h do |f|
7
+ [File.basename(f, '.ru'), f]
8
+ end.freeze
7
9
  end