pagy 9.2.0 → 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 +115 -123
- data/apps/demo.ru +273 -259
- data/apps/index.rb +7 -0
- data/apps/keyset_ar.ru +139 -152
- data/apps/keyset_s.ru +135 -154
- data/apps/rails.ru +15 -16
- data/apps/repro.ru +107 -102
- data/bin/pagy +14 -18
- 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
@@ -1,61 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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
|
-
|
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.2.2'
|
19
20
|
|
20
|
-
#
|
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 '
|
29
|
-
|
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
|
-
#
|
67
|
-
|
68
|
-
|
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
|
-
|
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
|
-
|
89
|
+
erb :main
|
137
90
|
end
|
138
|
-
end
|
139
91
|
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
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:
|
182
|
-
<li>Rack:
|
183
|
-
<li>
|
184
|
-
<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>
|
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
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
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
|
188
|
+
<p><%= pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
|
225
189
|
</div>
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
-
|
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
|
-
|
728
|
+
DATA
|
737
729
|
|
738
730
|
# DB seed
|
739
731
|
events = []
|
740
|
-
|
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
|
737
|
+
run PagyCalendar
|