pagy 8.6.3 → 9.3.4

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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/apps/calendar.ru +119 -127
  4. data/apps/demo.ru +274 -260
  5. data/apps/index.rb +7 -0
  6. data/apps/keyset_ar.ru +227 -0
  7. data/apps/keyset_s.ru +219 -0
  8. data/apps/rails.ru +25 -20
  9. data/apps/repro.ru +108 -103
  10. data/bin/pagy +18 -20
  11. data/config/pagy.rb +19 -15
  12. data/javascripts/pagy.min.js +2 -2
  13. data/javascripts/pagy.min.js.map +3 -3
  14. data/javascripts/pagy.mjs +2 -2
  15. data/lib/pagy/b64.rb +33 -0
  16. data/lib/pagy/backend.rb +20 -20
  17. data/lib/pagy/calendar/day.rb +2 -2
  18. data/lib/pagy/calendar/month.rb +2 -2
  19. data/lib/pagy/calendar/quarter.rb +2 -2
  20. data/lib/pagy/calendar/unit.rb +7 -10
  21. data/lib/pagy/calendar/week.rb +2 -2
  22. data/lib/pagy/calendar/year.rb +2 -2
  23. data/lib/pagy/calendar.rb +15 -13
  24. data/lib/pagy/countless.rb +10 -14
  25. data/lib/pagy/extras/arel.rb +3 -11
  26. data/lib/pagy/extras/array.rb +5 -10
  27. data/lib/pagy/extras/bootstrap.rb +5 -5
  28. data/lib/pagy/extras/bulma.rb +10 -7
  29. data/lib/pagy/extras/calendar.rb +13 -17
  30. data/lib/pagy/extras/countless.rb +8 -13
  31. data/lib/pagy/extras/elasticsearch_rails.rb +16 -25
  32. data/lib/pagy/extras/gearbox.rb +18 -18
  33. data/lib/pagy/extras/headers.rb +25 -24
  34. data/lib/pagy/extras/i18n.rb +1 -1
  35. data/lib/pagy/extras/js_tools.rb +6 -6
  36. data/lib/pagy/extras/jsonapi.rb +30 -21
  37. data/lib/pagy/extras/keyset.rb +30 -0
  38. data/lib/pagy/extras/limit.rb +63 -0
  39. data/lib/pagy/extras/meilisearch.rb +9 -17
  40. data/lib/pagy/extras/metadata.rb +3 -3
  41. data/lib/pagy/extras/overflow.rb +9 -9
  42. data/lib/pagy/extras/pagy.rb +16 -16
  43. data/lib/pagy/extras/searchkick.rb +9 -17
  44. data/lib/pagy/extras/size.rb +1 -1
  45. data/lib/pagy/extras/standalone.rb +6 -6
  46. data/lib/pagy/extras/trim.rb +3 -3
  47. data/lib/pagy/frontend.rb +32 -33
  48. data/lib/pagy/i18n.rb +3 -2
  49. data/lib/pagy/keyset/active_record.rb +38 -0
  50. data/lib/pagy/keyset/sequel.rb +51 -0
  51. data/lib/pagy/keyset.rb +118 -0
  52. data/lib/pagy/shared_methods.rb +26 -0
  53. data/lib/pagy/url_helpers.rb +5 -5
  54. data/lib/pagy.rb +53 -67
  55. data/locales/ar.yml +1 -1
  56. data/locales/be.yml +1 -1
  57. data/locales/bg.yml +1 -1
  58. data/locales/bs.yml +1 -1
  59. data/locales/ca.yml +1 -1
  60. data/locales/ckb.yml +1 -1
  61. data/locales/cs.yml +1 -1
  62. data/locales/da.yml +1 -1
  63. data/locales/de.yml +1 -1
  64. data/locales/dz.yml +17 -0
  65. data/locales/en.yml +1 -1
  66. data/locales/es.yml +1 -1
  67. data/locales/fr.yml +1 -1
  68. data/locales/hr.yml +1 -1
  69. data/locales/id.yml +1 -1
  70. data/locales/it.yml +1 -1
  71. data/locales/ja.yml +1 -1
  72. data/locales/km.yml +1 -1
  73. data/locales/ko.yml +1 -1
  74. data/locales/nb.yml +1 -1
  75. data/locales/nl.yml +1 -1
  76. data/locales/nn.yml +1 -1
  77. data/locales/pl.yml +1 -1
  78. data/locales/pt-BR.yml +1 -1
  79. data/locales/pt.yml +1 -1
  80. data/locales/ru.yml +1 -1
  81. data/locales/sr.yml +1 -1
  82. data/locales/sv-SE.yml +1 -1
  83. data/locales/sv.yml +1 -1
  84. data/locales/sw.yml +3 -1
  85. data/locales/ta.yml +3 -1
  86. data/locales/tr.yml +1 -1
  87. data/locales/uk.yml +1 -1
  88. data/locales/vi.yml +1 -1
  89. data/locales/zh-CN.yml +7 -9
  90. data/locales/zh-HK.yml +7 -9
  91. data/locales/zh-TW.yml +7 -9
  92. metadata +14 -27
  93. data/apps/tmp/calendar.sqlite3 +0 -0
  94. data/apps/tmp/calendar.sqlite3-shm +0 -0
  95. data/apps/tmp/calendar.sqlite3-wal +0 -0
  96. data/apps/tmp/local_secret.txt +0 -1
  97. data/apps/tmp/pagy-keyset.sqlite3 +0 -0
  98. data/apps/tmp/pagy-keyset.sqlite3-shm +0 -0
  99. data/apps/tmp/pagy-keyset.sqlite3-wal +0 -0
  100. data/javascripts/pagy-module.js +0 -100
  101. data/javascripts/pagy.js +0 -4
  102. data/lib/pagy/extras/foundation.rb +0 -95
  103. data/lib/pagy/extras/items.rb +0 -64
  104. data/lib/pagy/extras/materialize.rb +0 -100
  105. data/lib/pagy/extras/semantic.rb +0 -94
  106. data/lib/pagy/extras/uikit.rb +0 -98
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2504119986405246907631188b14c4e366eb2247f7fdecdd6a14f187dbe56674
4
- data.tar.gz: 9a355076182f3446c64279c7e158f9d826963c472e2e9b17e497cb863bdcadcf
3
+ metadata.gz: 9d2835c37aa941ceeee1a7ab05ca98e78e6f259a5ad96582dcf06a5fc7f9ed1b
4
+ data.tar.gz: 2697b8be5d353ffadca19d4c02d132fba5f355b89183c3f8fb0584ed4ea71c78
5
5
  SHA512:
6
- metadata.gz: 30b2e50c83d38b52d186c8f53615b6fe8491fd22ace660f351cca2993ed98c25ab3a8b61117e57c5f3b465f28daba3ef2efe0cf0332c0e2cc4a09d8986cfc217
7
- data.tar.gz: 01cf06ebc92ce69ccc50252d259057d14b56b0149e9e982dbd52e8e1bd1fb889a7319dcf497df5c3c2d3b388372e5444520054eda76cbefbe908d7debb20f73e
6
+ metadata.gz: 6f6b9e70680ddb584a52b9bb6f8fcdabc3b9715fce006ea3be3a2a708817f7ccb87ad5b70749deb1c4682fc89413609ad359a896a889fc88506ae94669710d14
7
+ data.tar.gz: 00c132f27373a3b0e517aa1bd42976c6276d6144540b4be153251302a83b572737a65172beb41dfc10b1a1876af99d18812577326c0b3c50a6c51c317ecf0233
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017-2024 Domizio Demichelis
3
+ Copyright (c) 2017-2025 Domizio Demichelis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/apps/calendar.ru CHANGED
@@ -1,61 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Interactive showcase for the pagy calendar extra (https://ddnexus.github.io/pagy/docs/extras/calendar)
4
-
3
+ # DESCRIPTION
4
+ # Showcase the calendar; reproduce related issues
5
+ #
6
+ # DOC
7
+ # https://ddnexus.github.io/pagy/playground/#5-calendar-app
8
+ #
9
+ # BIN HELP
10
+ # bundle exec pagy -h
11
+ #
5
12
  # DEV USAGE
6
- # pagy clone calendar
7
- # pagy ./calendar.ru
8
-
13
+ # bundle exec pagy clone calendar
14
+ # bundle exec pagy ./calendar.ru
15
+ #
9
16
  # URL
10
17
  # http://0.0.0.0:8000
11
18
 
12
- # HELP
13
- # pagy -h
14
-
15
- # DOC
16
- # https://ddnexus.github.io/pagy/playground/#5-calendar-app
17
-
18
- VERSION = '8.6.3'
19
+ VERSION = '9.3.4'
19
20
 
20
- # Gemfile
21
+ # Bundle
21
22
  require 'bundler/inline'
22
23
  require 'bundler'
23
24
  Bundler.configure
24
25
  gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
25
26
  source 'https://rubygems.org'
27
+ gem 'activerecord'
28
+ gem 'activesupport'
26
29
  gem 'groupdate'
27
30
  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 Calendar < 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: 'events#index'
51
- end
52
- end
53
-
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 calendar-app needs to create DB files)"
58
- exit 1
31
+ gem 'sinatra'
32
+ gem 'sqlite3'
59
33
  end
60
34
 
61
35
  # Pagy initializer
@@ -63,34 +37,10 @@ require 'pagy/extras/calendar'
63
37
  require 'pagy/extras/bootstrap'
64
38
  Pagy::DEFAULT.freeze
65
39
 
66
- # Groupdate initializer (https://github.com/ankane/groupdate)
67
- # Groupdate does not support the time zone with sqlite, so for this demo we can live with UTC
68
- Groupdate.time_zone = false
69
- # Groupdate week_start default is :sunday, while rails and pagy default to :monday
70
- Groupdate.week_start = :monday
71
-
72
- # Activerecord initializer
73
- ActiveRecord::Base.logger = Logger.new(OUTPUT)
74
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/calendar.sqlite3")
75
- ActiveRecord::Schema.define do
76
- create_table :events, force: true do |t|
77
- t.string :title
78
- t.timestamp :time
79
- end
80
- end
81
-
82
- # Models
83
- class Event < ActiveRecord::Base
84
- end
85
-
86
- # Helpers
87
- module EventsHelper
88
- include Pagy::Frontend
89
- end
90
-
91
- # Controllers
92
- class EventsController < ActionController::Base
93
- include Rails.application.routes.url_helpers
40
+ # Sinatra setup
41
+ require 'sinatra/base'
42
+ # Sinatra application
43
+ class PagyCalendar < Sinatra::Base
94
44
  include Pagy::Backend
95
45
 
96
46
  # This method must be implemented by the application.
@@ -119,9 +69,12 @@ class EventsController < ActionController::Base
119
69
  unless params[:skip_counts] == 'true'
120
70
  end
121
71
 
122
- def index
123
- # We need UTC to work with the limitation of groupdate with sqlite
124
- Time.zone = 'UTC'
72
+ # Root route/action
73
+ get '/' do
74
+ # Groupdate does not support time zones with SQLite.
75
+ # 'UTC' does not work on certain machines config (pulling the actual local time zone utc_offset)
76
+ # so for this demo we use a different zone with utc_offset 0
77
+ Time.zone = 'GMT'
125
78
  # Default calendar
126
79
  # The conf Hash defines the pagy objects variables keyed by calendar unit and the final pagy standard object
127
80
  # The :skip is an optional and arbitrarily named param that skips the calendar pagination and uses only the pagy
@@ -133,55 +86,66 @@ class EventsController < ActionController::Base
133
86
  month: {},
134
87
  day: {},
135
88
  active: !params[:skip])
136
- render inline: TEMPLATE
89
+ erb :main
137
90
  end
138
- end
139
91
 
140
- TEMPLATE = <<~ERB
141
- <!DOCTYPE html>
142
- <html lang="en">
143
- <html>
144
- <head>
145
- <title>Pagy Calendar App</title>
146
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
147
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
148
- integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
149
-
150
- <style type="text/css">
151
- @media screen { html, body {
152
- font-size: .8rem;
153
- line-height: 1.1s;
154
- padding: 0;
155
- margin: 0;
156
- } }
157
- body {
158
- background-color: #f7f7f7;
159
- color: #51585F;"
160
- font-family: sans-serif;
161
- }
162
- .content {
163
- padding: 1rem 1.5rem 2rem;
164
- }
165
- /* added with the pagy counts feature */
166
- a.empty-page {
167
- color: #888888;
168
- }
169
- </style>
170
- </head>
171
-
172
- <body>
92
+ helpers do
93
+ include Pagy::Frontend
94
+ end
173
95
 
96
+ # Views
97
+ template :layout do
98
+ <<~ERB
99
+ <!DOCTYPE html>
100
+ <html lang="en">
101
+ <html>
102
+ <head>
103
+ <title>Pagy Calendar App</title>
104
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
105
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
106
+ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
107
+
108
+ <style type="text/css">
109
+ @media screen { html, body {
110
+ font-size: .8rem;
111
+ line-height: 1.1s;
112
+ padding: 0;
113
+ margin: 0;
114
+ } }
115
+ body {
116
+ background-color: #f7f7f7;
117
+ color: #51585F;"
118
+ font-family: sans-serif;
119
+ }
120
+ .content {
121
+ padding: 1rem 1.5rem 2rem;
122
+ }
123
+ /* added with the pagy counts feature */
124
+ a.empty-page {
125
+ color: #888888;
126
+ }
127
+ </style>
128
+ </head>
129
+
130
+ <body>
131
+ <%= yield %>
132
+ </body>
133
+ </html>
134
+ ERB
135
+ end
136
+ template :main do
137
+ <<~ERB
174
138
  <div class="container">
175
139
  <h1>Pagy Calendar App</h1>
176
- <p>Self-contained, standalone Rails app implementing nested calendar pagination for year, month, day units.</p>
140
+ <p>Self-contained, standalone app implementing nested calendar pagination for year, month, day units.</p>
177
141
  <p>See the <a href="https://ddnexus.github.io/pagy/docs/extras/calendar">Pagy Calendar Extra</a> for details.</p>
178
142
  <p>Please, report the following versions in any new issue.</p>
179
143
  <h2>Versions</h2>
180
144
  <ul>
181
- <li>Ruby: <%== RUBY_VERSION %></li>
182
- <li>Rack: <%== Rack::RELEASE %></li>
183
- <li>Rails: <%== Rails.version %></li>
184
- <li>Pagy: <%== Pagy::VERSION %></li>
145
+ <li>Ruby: <%= RUBY_VERSION %></li>
146
+ <li>Rack: <%= Rack::RELEASE %></li>
147
+ <li>Sinatra: <%= Sinatra::VERSION %></li>
148
+ <li>Pagy: <%= Pagy::VERSION %></li>
185
149
  </ul>
186
150
  <hr>
187
151
 
@@ -200,14 +164,14 @@ TEMPLATE = <<~ERB
200
164
  <!-- calendar filtering navs -->
201
165
  <% if @calendar %>
202
166
  <p>Showtime: <%= @calendar.showtime %></p>
203
- <%== pagy_bootstrap_nav(@calendar[:year], id: "year-nav", aria_label: "Years") %> <!-- year nav -->
204
- <%== pagy_bootstrap_nav(@calendar[:month], id: "month-nav", aria_label: "Months") %> <!-- month nav -->
205
- <%== pagy_bootstrap_nav(@calendar[:day], id: "day-nav", aria_label: "Days") %> <!-- day nav -->
167
+ <%= pagy_bootstrap_nav(@calendar[:year], id: "year-nav", aria_label: "Years") %> <!-- year nav -->
168
+ <%= pagy_bootstrap_nav(@calendar[:month], id: "month-nav", aria_label: "Months") %> <!-- month nav -->
169
+ <%= pagy_bootstrap_nav(@calendar[:day], id: "day-nav", aria_label: "Days") %> <!-- day nav -->
206
170
  <% end %>
207
171
 
208
172
  <!-- page info extended for the calendar unit -->
209
173
  <div class="alert alert-primary" role="alert">
210
- <%== pagy_info(@pagy, id: 'pagy-info') %>
174
+ <%= pagy_info(@pagy, id: 'pagy-info') %>
211
175
  <% if @calendar %>
212
176
  for <b><%= @calendar.showtime.strftime('%Y-%m-%d') %></b>
213
177
  <% end %>
@@ -221,13 +185,41 @@ TEMPLATE = <<~ERB
221
185
  </div>
222
186
 
223
187
  <!-- standard pagination of the selected month -->
224
- <p><%== pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
188
+ <p><%= pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
225
189
  </div>
226
- </body>
227
- </html>
228
- ERB
190
+ ERB
191
+ end
192
+ end
193
+
194
+ # ActiveRecord setup
195
+ require 'active_record'
196
+ # Log
197
+ output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
198
+ ActiveRecord::Base.logger = Logger.new(output)
199
+ # SQLite DB files
200
+ dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
201
+ abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
202
+ unless File.writable?(dir)
203
+ # Connection
204
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-calendar.sqlite3")
205
+
206
+ # Groupdate initializer (https://github.com/ankane/groupdate)
207
+ # Groupdate week_start default is :sunday, while rails and pagy default to :monday
208
+ Groupdate.week_start = :monday
209
+ ActiveSupport.to_time_preserves_timezone = :zone # Fix ActiveSupport deprecation
210
+
211
+ ActiveRecord::Schema.define do
212
+ create_table :events, force: true do |t|
213
+ t.string :title
214
+ t.timestamp :time
215
+ end
216
+ end
217
+
218
+ # Models
219
+ class Event < ActiveRecord::Base; end
229
220
 
230
- TIMES = <<~TIMES
221
+ # Event times
222
+ data = <<~DATA
231
223
  2021-10-21 13:18:23 +0000
232
224
  2021-10-21 23:14:50 +0000
233
225
  2021-10-23 01:06:02 +0000
@@ -733,13 +725,13 @@ TIMES = <<~TIMES
733
725
  2023-11-12 04:22:50 +0000
734
726
  2023-11-12 08:38:58 +0000
735
727
  2023-11-13 15:43:40 +0000
736
- TIMES
728
+ DATA
737
729
 
738
730
  # DB seed
739
731
  events = []
740
- TIMES.each_line(chomp: true).with_index do |time, i|
732
+ data.each_line(chomp: true).with_index do |time, i|
741
733
  events << { title: "Event ##{i + 1}", time: }
742
734
  end
743
735
  Event.insert_all(events)
744
736
 
745
- run Calendar
737
+ run PagyCalendar