pagy 9.2.1 → 9.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apps/calendar.ru +98 -102
- data/apps/demo.ru +256 -244
- data/apps/index.rb +7 -0
- data/apps/keyset_ar.ru +81 -84
- data/apps/keyset_s.ru +81 -84
- data/apps/rails.ru +1 -1
- data/apps/repro.ru +93 -91
- data/bin/pagy +3 -3
- data/config/pagy.rb +1 -1
- data/javascripts/pagy.min.js +2 -2
- data/javascripts/pagy.min.js.map +2 -2
- data/javascripts/pagy.mjs +1 -1
- data/lib/pagy.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c767f9cbbcde7d836efe488eb879a31cff990c48098b96b7937242244f3408
|
4
|
+
data.tar.gz: 62f865e4dd30b12e4cf47d6163898c993ba0b7fca667cb15f3e62f638d9e5202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e6af2bbc778fca1f8739613361e0a44a93e1f1ca83ea047a6249e9bd2f66345e2197b7f29abada6938f2d6a4237808917456c8e6696c6a6e786effb7c4f337b
|
7
|
+
data.tar.gz: 065d081600304146b728c39f789375bf3900932069a1305859fb4c80d4b832a6776f40309299ea5b9e1e0335fe21998de3935fc8e4957d08bb85c07304f1d3b6
|
data/apps/calendar.ru
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# URL
|
17
17
|
# http://0.0.0.0:8000
|
18
18
|
|
19
|
-
VERSION = '9.2.
|
19
|
+
VERSION = '9.2.2'
|
20
20
|
|
21
21
|
# Bundle
|
22
22
|
require 'bundler/inline'
|
@@ -24,67 +24,23 @@ require 'bundler'
|
|
24
24
|
Bundler.configure
|
25
25
|
gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
26
26
|
source 'https://rubygems.org'
|
27
|
+
gem 'activerecord'
|
28
|
+
gem 'activesupport'
|
27
29
|
gem 'groupdate'
|
28
30
|
gem 'puma'
|
29
|
-
gem '
|
31
|
+
gem 'sinatra'
|
30
32
|
gem 'sqlite3'
|
31
33
|
end
|
32
34
|
|
33
|
-
# require 'rails/all' # too much stuff
|
34
|
-
require 'action_controller/railtie'
|
35
|
-
require 'active_record'
|
36
|
-
|
37
|
-
OUTPUT = Rails.env.showcase? ? IO::NULL : $stdout
|
38
|
-
|
39
|
-
# Rails config
|
40
|
-
class Calendar < Rails::Application # :nodoc:
|
41
|
-
config.root = __dir__
|
42
|
-
config.session_store :cookie_store, key: 'cookie_store_key'
|
43
|
-
Rails.application.credentials.secret_key_base = 'absolute_secret'
|
44
|
-
|
45
|
-
config.logger = Logger.new(OUTPUT)
|
46
|
-
Rails.logger = config.logger
|
47
|
-
|
48
|
-
routes.draw do
|
49
|
-
root to: 'events#index'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# AR config
|
54
|
-
dir = Rails.env.development? ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
55
|
-
abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
|
56
|
-
unless File.writable?(dir)
|
57
|
-
|
58
35
|
# Pagy initializer
|
59
36
|
require 'pagy/extras/calendar'
|
60
37
|
require 'pagy/extras/bootstrap'
|
61
38
|
Pagy::DEFAULT.freeze
|
62
39
|
|
63
|
-
#
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# Activerecord initializer
|
68
|
-
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
69
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/calendar.sqlite3")
|
70
|
-
ActiveRecord::Schema.define do
|
71
|
-
create_table :events, force: true do |t|
|
72
|
-
t.string :title
|
73
|
-
t.timestamp :time
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Models
|
78
|
-
class Event < ActiveRecord::Base; end
|
79
|
-
|
80
|
-
# Helpers
|
81
|
-
module EventsHelper
|
82
|
-
include Pagy::Frontend
|
83
|
-
end
|
84
|
-
|
85
|
-
# Controllers
|
86
|
-
class EventsController < ActionController::Base
|
87
|
-
include Rails.application.routes.url_helpers
|
40
|
+
# Sinatra setup
|
41
|
+
require 'sinatra/base'
|
42
|
+
# Sinatra application
|
43
|
+
class PagyCalendar < Sinatra::Base
|
88
44
|
include Pagy::Backend
|
89
45
|
|
90
46
|
# This method must be implemented by the application.
|
@@ -113,7 +69,8 @@ class EventsController < ActionController::Base
|
|
113
69
|
unless params[:skip_counts] == 'true'
|
114
70
|
end
|
115
71
|
|
116
|
-
|
72
|
+
# Root route/action
|
73
|
+
get '/' do
|
117
74
|
# Groupdate does not support time zones with SQLite.
|
118
75
|
# 'UTC' does not work on certain machines config (pulling the actual local time zone utc_offset)
|
119
76
|
# so for this demo we use a different zone with utc_offset 0
|
@@ -129,44 +86,55 @@ class EventsController < ActionController::Base
|
|
129
86
|
month: {},
|
130
87
|
day: {},
|
131
88
|
active: !params[:skip])
|
132
|
-
|
89
|
+
erb :main
|
133
90
|
end
|
134
|
-
end
|
135
91
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
<html>
|
140
|
-
<head>
|
141
|
-
<title>Pagy Calendar App</title>
|
142
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
143
|
-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
|
144
|
-
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
92
|
+
helpers do
|
93
|
+
include Pagy::Frontend
|
94
|
+
end
|
145
95
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
.content {
|
159
|
-
padding: 1rem 1.5rem 2rem;
|
160
|
-
}
|
161
|
-
/* added with the pagy counts feature */
|
162
|
-
a.empty-page {
|
163
|
-
color: #888888;
|
164
|
-
}
|
165
|
-
</style>
|
166
|
-
</head>
|
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">
|
167
107
|
|
168
|
-
|
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>
|
169
129
|
|
130
|
+
<body>
|
131
|
+
<%= yield %>
|
132
|
+
</body>
|
133
|
+
</html>
|
134
|
+
ERB
|
135
|
+
end
|
136
|
+
template :main do
|
137
|
+
<<~ERB
|
170
138
|
<div class="container">
|
171
139
|
<h1>Pagy Calendar App</h1>
|
172
140
|
<p>Self-contained, standalone app implementing nested calendar pagination for year, month, day units.</p>
|
@@ -174,10 +142,10 @@ TEMPLATE = <<~ERB
|
|
174
142
|
<p>Please, report the following versions in any new issue.</p>
|
175
143
|
<h2>Versions</h2>
|
176
144
|
<ul>
|
177
|
-
<li>Ruby:
|
178
|
-
<li>Rack:
|
179
|
-
<li>
|
180
|
-
<li>Pagy:
|
145
|
+
<li>Ruby: <%= RUBY_VERSION %></li>
|
146
|
+
<li>Rack: <%= Rack::RELEASE %></li>
|
147
|
+
<li>Sinatra: <%= Sinatra::VERSION %></li>
|
148
|
+
<li>Pagy: <%= Pagy::VERSION %></li>
|
181
149
|
</ul>
|
182
150
|
<hr>
|
183
151
|
|
@@ -196,14 +164,14 @@ TEMPLATE = <<~ERB
|
|
196
164
|
<!-- calendar filtering navs -->
|
197
165
|
<% if @calendar %>
|
198
166
|
<p>Showtime: <%= @calendar.showtime %></p>
|
199
|
-
|
200
|
-
|
201
|
-
|
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 -->
|
202
170
|
<% end %>
|
203
171
|
|
204
172
|
<!-- page info extended for the calendar unit -->
|
205
173
|
<div class="alert alert-primary" role="alert">
|
206
|
-
|
174
|
+
<%= pagy_info(@pagy, id: 'pagy-info') %>
|
207
175
|
<% if @calendar %>
|
208
176
|
for <b><%= @calendar.showtime.strftime('%Y-%m-%d') %></b>
|
209
177
|
<% end %>
|
@@ -217,13 +185,41 @@ TEMPLATE = <<~ERB
|
|
217
185
|
</div>
|
218
186
|
|
219
187
|
<!-- standard pagination of the selected month -->
|
220
|
-
<p
|
188
|
+
<p><%= pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
|
221
189
|
</div>
|
222
|
-
|
223
|
-
|
224
|
-
|
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
|
225
220
|
|
226
|
-
|
221
|
+
# Event times
|
222
|
+
data = <<~DATA
|
227
223
|
2021-10-21 13:18:23 +0000
|
228
224
|
2021-10-21 23:14:50 +0000
|
229
225
|
2021-10-23 01:06:02 +0000
|
@@ -729,13 +725,13 @@ TIMES = <<~TIMES
|
|
729
725
|
2023-11-12 04:22:50 +0000
|
730
726
|
2023-11-12 08:38:58 +0000
|
731
727
|
2023-11-13 15:43:40 +0000
|
732
|
-
|
728
|
+
DATA
|
733
729
|
|
734
730
|
# DB seed
|
735
731
|
events = []
|
736
|
-
|
732
|
+
data.each_line(chomp: true).with_index do |time, i|
|
737
733
|
events << { title: "Event ##{i + 1}", time: }
|
738
734
|
end
|
739
735
|
Event.insert_all(events)
|
740
736
|
|
741
|
-
run
|
737
|
+
run PagyCalendar
|