pagy 9.2.0 → 9.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2085cf1f7f8e3b016a9d2b40ec9cf3720014b8bb2ab2b1070466129b0c18f3bb
4
- data.tar.gz: a3e93e7018900837ed4258eef202e7e66f930fa8d105139c342d62a4ee2b51c6
3
+ metadata.gz: 50fce56f851465e19e07eb834ac69359abec701000cb23900d043bba62d3f0a3
4
+ data.tar.gz: e3207beec177cdecafc4c23b74181ad09ea76d8ce16d74eb96b1104cc0f07ff2
5
5
  SHA512:
6
- metadata.gz: 729555f087c358546243b556dd09e48b33287add79edff83931439b010baa8dea896912714b6156dc56d059238369f96907acd403ba73be0bf36a020dbb1a67f
7
- data.tar.gz: e3253f968ac68d8bcccf8e8ce060f42ee4071737615ac99c29c59c2b2f60c779bb3396facf938e45b0de2ed687365b94e142961ef4f2d7a3f43a66c675f8d2a9
6
+ metadata.gz: a2c87364b765b31846788a0b3ed5234bc3096d58cccf407b36a107dc906c964aa41328984b82c2c399e91165f0ac13bab12a3954398c47f8eedc2cf67f5f9774
7
+ data.tar.gz: 1e5a7a0b030d0e8e9a88fa438cfd9b4987d93d7a2cc1dffd81e6736cb0a80d5d1f5d4c7cfbb3390cfbfd9e44aa6fc7036a7e470543d8cd1d830bf42812fb64c8
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 = '9.2.0'
19
+ VERSION = '9.3.1'
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,32 +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 week_start default is :sunday, while rails and pagy default to :monday
68
- Groupdate.week_start = :monday
69
-
70
- # Activerecord initializer
71
- ActiveRecord::Base.logger = Logger.new(OUTPUT)
72
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/calendar.sqlite3")
73
- ActiveRecord::Schema.define do
74
- create_table :events, force: true do |t|
75
- t.string :title
76
- t.timestamp :time
77
- end
78
- end
79
-
80
- # Models
81
- class Event < ActiveRecord::Base
82
- end
83
-
84
- # Helpers
85
- module EventsHelper
86
- include Pagy::Frontend
87
- end
88
-
89
- # Controllers
90
- class EventsController < ActionController::Base
91
- include Rails.application.routes.url_helpers
40
+ # Sinatra setup
41
+ require 'sinatra/base'
42
+ # Sinatra application
43
+ class PagyCalendar < Sinatra::Base
92
44
  include Pagy::Backend
93
45
 
94
46
  # This method must be implemented by the application.
@@ -117,7 +69,8 @@ class EventsController < ActionController::Base
117
69
  unless params[:skip_counts] == 'true'
118
70
  end
119
71
 
120
- def index
72
+ # Root route/action
73
+ get '/' do
121
74
  # Groupdate does not support time zones with SQLite.
122
75
  # 'UTC' does not work on certain machines config (pulling the actual local time zone utc_offset)
123
76
  # so for this demo we use a different zone with utc_offset 0
@@ -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