simple_calendar 2.4.3 → 3.0.0
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 +4 -4
- data/.github/workflows/ci.yml +5 -4
- data/.gitignore +4 -0
- data/Appraisals +5 -5
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +157 -136
- data/README.md +22 -15
- data/Rakefile +29 -5
- data/app/assets/stylesheets/simple_calendar.scss +4 -0
- data/app/views/simple_calendar/_calendar.html.erb +7 -7
- data/app/views/simple_calendar/_month_calendar.html.erb +8 -8
- data/app/views/simple_calendar/_week_calendar.html.erb +14 -12
- data/bin/rails +16 -0
- data/gemfiles/rails_6_1.gemfile +3 -1
- data/gemfiles/rails_6_1.gemfile.lock +159 -131
- data/gemfiles/{rails_6.gemfile → rails_7_0.gemfile} +4 -2
- data/gemfiles/rails_7_0.gemfile.lock +222 -0
- data/gemfiles/{rails_master.gemfile → rails_main.gemfile} +3 -1
- data/gemfiles/rails_main.gemfile.lock +246 -0
- data/lib/simple_calendar/calendar.rb +26 -14
- data/lib/simple_calendar/month_calendar.rb +4 -0
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +3 -3
- data/lib/simple_calendar/week_calendar.rb +5 -1
- data/lib/simple_calendar.rb +8 -1
- data/simple_calendar.gemspec +1 -3
- data/test/calendars/calendar_test.rb +154 -0
- data/test/calendars/month_calendar_test.rb +16 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +1 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +1 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/meetings_controller.rb +59 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/meetings_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +7 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/meeting.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/meetings/_form.html.erb +32 -0
- data/test/dummy/app/views/meetings/_meeting.html.erb +17 -0
- data/test/dummy/app/views/meetings/edit.html.erb +10 -0
- data/test/dummy/app/views/meetings/index.html.erb +24 -0
- data/test/dummy/app/views/meetings/new.html.erb +9 -0
- data/test/dummy/app/views/meetings/show.html.erb +10 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +33 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +67 -0
- data/test/dummy/config/environments/production.rb +87 -0
- data/test/dummy/config/environments/test.rb +60 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/config.ru +6 -0
- data/test/dummy/db/migrate/20220930184313_create_meetings.rb +11 -0
- data/test/dummy/db/schema.rb +21 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/storage/.keep +0 -0
- data/test/dummy/tmp/.keep +0 -0
- data/test/dummy/tmp/development_secret.txt +1 -0
- data/test/dummy/tmp/pids/.keep +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/dummy/tmp/restart.txt +0 -0
- data/test/dummy/tmp/storage/.keep +0 -0
- data/test/fixtures/meetings.yml +36 -0
- data/test/integrations/month_calendar_test.rb +58 -0
- data/test/simple_calendar_test.rb +7 -0
- data/test/test_helper.rb +14 -0
- metadata +80 -39
- data/gemfiles/rails_6.gemfile.lock +0 -195
- data/gemfiles/rails_master.gemfile.lock +0 -207
- data/spec/calendar_spec.rb +0 -176
- data/spec/calendars/month_calendar_spec.rb +0 -25
- data/spec/simple_calendar_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -96
- data/spec/support/fake_event.rb +0 -9
- data/spec/support/view_context.rb +0 -20
- data/spec/views_generators_spec.rb +0 -7
- /data/lib/simple_calendar/{railtie.rb → engine.rb} +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
GIT
|
|
2
|
+
remote: https://github.com/rails/rails.git
|
|
3
|
+
revision: c9cdd800d30ec38f079b3df0772ab47f4ba4b11f
|
|
4
|
+
specs:
|
|
5
|
+
actioncable (7.1.0.alpha)
|
|
6
|
+
actionpack (= 7.1.0.alpha)
|
|
7
|
+
activesupport (= 7.1.0.alpha)
|
|
8
|
+
nio4r (~> 2.0)
|
|
9
|
+
websocket-driver (>= 0.6.1)
|
|
10
|
+
zeitwerk (~> 2.6)
|
|
11
|
+
actionmailbox (7.1.0.alpha)
|
|
12
|
+
actionpack (= 7.1.0.alpha)
|
|
13
|
+
activejob (= 7.1.0.alpha)
|
|
14
|
+
activerecord (= 7.1.0.alpha)
|
|
15
|
+
activestorage (= 7.1.0.alpha)
|
|
16
|
+
activesupport (= 7.1.0.alpha)
|
|
17
|
+
mail (>= 2.7.1)
|
|
18
|
+
net-imap
|
|
19
|
+
net-pop
|
|
20
|
+
net-smtp
|
|
21
|
+
actionmailer (7.1.0.alpha)
|
|
22
|
+
actionpack (= 7.1.0.alpha)
|
|
23
|
+
actionview (= 7.1.0.alpha)
|
|
24
|
+
activejob (= 7.1.0.alpha)
|
|
25
|
+
activesupport (= 7.1.0.alpha)
|
|
26
|
+
mail (~> 2.5, >= 2.5.4)
|
|
27
|
+
net-imap
|
|
28
|
+
net-pop
|
|
29
|
+
net-smtp
|
|
30
|
+
rails-dom-testing (~> 2.0)
|
|
31
|
+
actionpack (7.1.0.alpha)
|
|
32
|
+
actionview (= 7.1.0.alpha)
|
|
33
|
+
activesupport (= 7.1.0.alpha)
|
|
34
|
+
nokogiri (>= 1.8.5)
|
|
35
|
+
rack (>= 2.2.4)
|
|
36
|
+
rack-session (>= 1.0.1)
|
|
37
|
+
rack-test (>= 0.6.3)
|
|
38
|
+
rails-dom-testing (~> 2.0)
|
|
39
|
+
rails-html-sanitizer (~> 1.6)
|
|
40
|
+
actiontext (7.1.0.alpha)
|
|
41
|
+
actionpack (= 7.1.0.alpha)
|
|
42
|
+
activerecord (= 7.1.0.alpha)
|
|
43
|
+
activestorage (= 7.1.0.alpha)
|
|
44
|
+
activesupport (= 7.1.0.alpha)
|
|
45
|
+
globalid (>= 0.6.0)
|
|
46
|
+
nokogiri (>= 1.8.5)
|
|
47
|
+
actionview (7.1.0.alpha)
|
|
48
|
+
activesupport (= 7.1.0.alpha)
|
|
49
|
+
builder (~> 3.1)
|
|
50
|
+
erubi (~> 1.11)
|
|
51
|
+
rails-dom-testing (~> 2.0)
|
|
52
|
+
rails-html-sanitizer (~> 1.6)
|
|
53
|
+
activejob (7.1.0.alpha)
|
|
54
|
+
activesupport (= 7.1.0.alpha)
|
|
55
|
+
globalid (>= 0.3.6)
|
|
56
|
+
activemodel (7.1.0.alpha)
|
|
57
|
+
activesupport (= 7.1.0.alpha)
|
|
58
|
+
activerecord (7.1.0.alpha)
|
|
59
|
+
activemodel (= 7.1.0.alpha)
|
|
60
|
+
activesupport (= 7.1.0.alpha)
|
|
61
|
+
timeout (>= 0.4.0)
|
|
62
|
+
activestorage (7.1.0.alpha)
|
|
63
|
+
actionpack (= 7.1.0.alpha)
|
|
64
|
+
activejob (= 7.1.0.alpha)
|
|
65
|
+
activerecord (= 7.1.0.alpha)
|
|
66
|
+
activesupport (= 7.1.0.alpha)
|
|
67
|
+
marcel (~> 1.0)
|
|
68
|
+
activesupport (7.1.0.alpha)
|
|
69
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
70
|
+
connection_pool (>= 2.2.5)
|
|
71
|
+
i18n (>= 1.6, < 2)
|
|
72
|
+
minitest (>= 5.1)
|
|
73
|
+
tzinfo (~> 2.0)
|
|
74
|
+
rails (7.1.0.alpha)
|
|
75
|
+
actioncable (= 7.1.0.alpha)
|
|
76
|
+
actionmailbox (= 7.1.0.alpha)
|
|
77
|
+
actionmailer (= 7.1.0.alpha)
|
|
78
|
+
actionpack (= 7.1.0.alpha)
|
|
79
|
+
actiontext (= 7.1.0.alpha)
|
|
80
|
+
actionview (= 7.1.0.alpha)
|
|
81
|
+
activejob (= 7.1.0.alpha)
|
|
82
|
+
activemodel (= 7.1.0.alpha)
|
|
83
|
+
activerecord (= 7.1.0.alpha)
|
|
84
|
+
activestorage (= 7.1.0.alpha)
|
|
85
|
+
activesupport (= 7.1.0.alpha)
|
|
86
|
+
bundler (>= 1.15.0)
|
|
87
|
+
railties (= 7.1.0.alpha)
|
|
88
|
+
railties (7.1.0.alpha)
|
|
89
|
+
actionpack (= 7.1.0.alpha)
|
|
90
|
+
activesupport (= 7.1.0.alpha)
|
|
91
|
+
irb
|
|
92
|
+
rackup (>= 1.0.0)
|
|
93
|
+
rake (>= 12.2)
|
|
94
|
+
thor (~> 1.0, >= 1.2.2)
|
|
95
|
+
zeitwerk (~> 2.6)
|
|
96
|
+
|
|
97
|
+
GIT
|
|
98
|
+
remote: https://github.com/thoughtbot/appraisal.git
|
|
99
|
+
revision: b200e636903700098bef25f4f51dbc4c46e4c04c
|
|
100
|
+
specs:
|
|
101
|
+
appraisal (2.4.1)
|
|
102
|
+
bundler
|
|
103
|
+
rake
|
|
104
|
+
thor (>= 0.14.0)
|
|
105
|
+
|
|
106
|
+
PATH
|
|
107
|
+
remote: ..
|
|
108
|
+
specs:
|
|
109
|
+
simple_calendar (3.0.0)
|
|
110
|
+
rails (>= 6.1)
|
|
111
|
+
|
|
112
|
+
GEM
|
|
113
|
+
remote: http://rubygems.org/
|
|
114
|
+
specs:
|
|
115
|
+
ast (2.4.2)
|
|
116
|
+
builder (3.2.4)
|
|
117
|
+
concurrent-ruby (1.2.2)
|
|
118
|
+
connection_pool (2.4.1)
|
|
119
|
+
crass (1.0.6)
|
|
120
|
+
date (3.3.3)
|
|
121
|
+
erubi (1.12.0)
|
|
122
|
+
globalid (1.1.0)
|
|
123
|
+
activesupport (>= 5.0)
|
|
124
|
+
i18n (1.14.1)
|
|
125
|
+
concurrent-ruby (~> 1.0)
|
|
126
|
+
io-console (0.6.0)
|
|
127
|
+
irb (1.7.3)
|
|
128
|
+
reline (>= 0.3.6)
|
|
129
|
+
json (2.6.3)
|
|
130
|
+
language_server-protocol (3.17.0.3)
|
|
131
|
+
lint_roller (1.1.0)
|
|
132
|
+
loofah (2.21.3)
|
|
133
|
+
crass (~> 1.0.2)
|
|
134
|
+
nokogiri (>= 1.12.0)
|
|
135
|
+
mail (2.8.1)
|
|
136
|
+
mini_mime (>= 0.1.1)
|
|
137
|
+
net-imap
|
|
138
|
+
net-pop
|
|
139
|
+
net-smtp
|
|
140
|
+
marcel (1.0.2)
|
|
141
|
+
mini_mime (1.1.2)
|
|
142
|
+
mini_portile2 (2.8.2)
|
|
143
|
+
minitest (5.18.1)
|
|
144
|
+
net-imap (0.3.6)
|
|
145
|
+
date
|
|
146
|
+
net-protocol
|
|
147
|
+
net-pop (0.1.2)
|
|
148
|
+
net-protocol
|
|
149
|
+
net-protocol (0.2.1)
|
|
150
|
+
timeout
|
|
151
|
+
net-smtp (0.3.3)
|
|
152
|
+
net-protocol
|
|
153
|
+
nio4r (2.5.9)
|
|
154
|
+
nokogiri (1.15.3)
|
|
155
|
+
mini_portile2 (~> 2.8.2)
|
|
156
|
+
racc (~> 1.4)
|
|
157
|
+
nokogiri (1.15.3-x86_64-darwin)
|
|
158
|
+
racc (~> 1.4)
|
|
159
|
+
nokogiri (1.15.3-x86_64-linux)
|
|
160
|
+
racc (~> 1.4)
|
|
161
|
+
parallel (1.23.0)
|
|
162
|
+
parser (3.2.2.3)
|
|
163
|
+
ast (~> 2.4.1)
|
|
164
|
+
racc
|
|
165
|
+
puma (6.3.0)
|
|
166
|
+
nio4r (~> 2.0)
|
|
167
|
+
racc (1.7.1)
|
|
168
|
+
rack (3.0.8)
|
|
169
|
+
rack-session (2.0.0)
|
|
170
|
+
rack (>= 3.0.0)
|
|
171
|
+
rack-test (2.1.0)
|
|
172
|
+
rack (>= 1.3)
|
|
173
|
+
rackup (2.1.0)
|
|
174
|
+
rack (>= 3)
|
|
175
|
+
webrick (~> 1.8)
|
|
176
|
+
rails-dom-testing (2.1.1)
|
|
177
|
+
activesupport (>= 5.0.0)
|
|
178
|
+
minitest
|
|
179
|
+
nokogiri (>= 1.6)
|
|
180
|
+
rails-html-sanitizer (1.6.0)
|
|
181
|
+
loofah (~> 2.21)
|
|
182
|
+
nokogiri (~> 1.14)
|
|
183
|
+
rainbow (3.1.1)
|
|
184
|
+
rake (13.0.6)
|
|
185
|
+
regexp_parser (2.8.1)
|
|
186
|
+
reline (0.3.6)
|
|
187
|
+
io-console (~> 0.5)
|
|
188
|
+
rexml (3.2.5)
|
|
189
|
+
rubocop (1.52.1)
|
|
190
|
+
json (~> 2.3)
|
|
191
|
+
parallel (~> 1.10)
|
|
192
|
+
parser (>= 3.2.2.3)
|
|
193
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
194
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
195
|
+
rexml (>= 3.2.5, < 4.0)
|
|
196
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
197
|
+
ruby-progressbar (~> 1.7)
|
|
198
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
199
|
+
rubocop-ast (1.29.0)
|
|
200
|
+
parser (>= 3.2.1.0)
|
|
201
|
+
rubocop-performance (1.18.0)
|
|
202
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
203
|
+
rubocop-ast (>= 0.4.0)
|
|
204
|
+
ruby-progressbar (1.13.0)
|
|
205
|
+
sqlite3 (1.6.3)
|
|
206
|
+
mini_portile2 (~> 2.8.0)
|
|
207
|
+
sqlite3 (1.6.3-x86_64-darwin)
|
|
208
|
+
sqlite3 (1.6.3-x86_64-linux)
|
|
209
|
+
standard (1.30.1)
|
|
210
|
+
language_server-protocol (~> 3.17.0.2)
|
|
211
|
+
lint_roller (~> 1.0)
|
|
212
|
+
rubocop (~> 1.52.0)
|
|
213
|
+
standard-custom (~> 1.0.0)
|
|
214
|
+
standard-performance (~> 1.1.0)
|
|
215
|
+
standard-custom (1.0.2)
|
|
216
|
+
lint_roller (~> 1.0)
|
|
217
|
+
rubocop (~> 1.50)
|
|
218
|
+
standard-performance (1.1.1)
|
|
219
|
+
lint_roller (~> 1.1)
|
|
220
|
+
rubocop-performance (~> 1.18.0)
|
|
221
|
+
thor (1.2.2)
|
|
222
|
+
timeout (0.4.0)
|
|
223
|
+
tzinfo (2.0.6)
|
|
224
|
+
concurrent-ruby (~> 1.0)
|
|
225
|
+
unicode-display_width (2.4.2)
|
|
226
|
+
webrick (1.8.1)
|
|
227
|
+
websocket-driver (0.7.5)
|
|
228
|
+
websocket-extensions (>= 0.1.0)
|
|
229
|
+
websocket-extensions (0.1.5)
|
|
230
|
+
zeitwerk (2.6.8)
|
|
231
|
+
|
|
232
|
+
PLATFORMS
|
|
233
|
+
ruby
|
|
234
|
+
x86_64-darwin-20
|
|
235
|
+
x86_64-linux
|
|
236
|
+
|
|
237
|
+
DEPENDENCIES
|
|
238
|
+
appraisal!
|
|
239
|
+
puma
|
|
240
|
+
rails!
|
|
241
|
+
simple_calendar!
|
|
242
|
+
sqlite3
|
|
243
|
+
standard
|
|
244
|
+
|
|
245
|
+
BUNDLED WITH
|
|
246
|
+
2.4.16
|
|
@@ -6,9 +6,11 @@ module SimpleCalendar
|
|
|
6
6
|
|
|
7
7
|
attr_accessor :view_context, :options
|
|
8
8
|
|
|
9
|
-
def initialize(view_context,
|
|
9
|
+
def initialize(view_context, options = {}, &block)
|
|
10
10
|
@view_context = view_context
|
|
11
|
-
@
|
|
11
|
+
@locals = options.delete(:locals) || {}
|
|
12
|
+
@options = options
|
|
13
|
+
@block = block
|
|
12
14
|
|
|
13
15
|
# Next and previous view links should use the same params as the current view
|
|
14
16
|
@params = @view_context.respond_to?(:params) ? @view_context.params : {}
|
|
@@ -19,16 +21,20 @@ module SimpleCalendar
|
|
|
19
21
|
@params.merge!(@options.fetch(:params, {}))
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
def
|
|
24
|
+
def render_in(view_context)
|
|
23
25
|
view_context.render(
|
|
24
26
|
partial: partial_name,
|
|
25
|
-
locals:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
locals: locals
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def locals(&block)
|
|
32
|
+
@locals.merge(
|
|
33
|
+
passed_block: @block,
|
|
34
|
+
calendar: self,
|
|
35
|
+
date_range: date_range,
|
|
36
|
+
start_date: start_date,
|
|
37
|
+
sorted_events: sorted_events
|
|
32
38
|
)
|
|
33
39
|
end
|
|
34
40
|
|
|
@@ -62,15 +68,17 @@ module SimpleCalendar
|
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
def url_for_previous_view
|
|
65
|
-
view_context.url_for(@params.merge(start_date_param => (date_range.first -
|
|
71
|
+
view_context.url_for(@params.merge(start_date_param => (date_range.first - date_range.count.days).iso8601))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def url_for_today_view
|
|
75
|
+
view_context.url_for(@params.merge(start_date_param => Time.current.to_date.iso8601))
|
|
66
76
|
end
|
|
67
77
|
|
|
68
78
|
def date_range
|
|
69
79
|
(start_date..(start_date + additional_days.days)).to_a
|
|
70
80
|
end
|
|
71
81
|
|
|
72
|
-
private
|
|
73
|
-
|
|
74
82
|
def partial_name
|
|
75
83
|
@options[:partial] || self.class.name.underscore
|
|
76
84
|
end
|
|
@@ -94,12 +102,16 @@ module SimpleCalendar
|
|
|
94
102
|
end
|
|
95
103
|
end
|
|
96
104
|
|
|
105
|
+
def sorted_events_for(day)
|
|
106
|
+
sorted_events.fetch(day, [])
|
|
107
|
+
end
|
|
108
|
+
|
|
97
109
|
def group_events_by_date(events)
|
|
98
110
|
events_grouped_by_date = Hash.new { |h, k| h[k] = [] }
|
|
99
111
|
|
|
100
112
|
events.each do |event|
|
|
101
113
|
event_start_date = event.send(attribute).to_date
|
|
102
|
-
event_end_date = event.respond_to?(end_attribute) && !event.send(end_attribute).nil? ? event.send(end_attribute).to_date : event_start_date
|
|
114
|
+
event_end_date = (event.respond_to?(end_attribute) && !event.send(end_attribute).nil?) ? event.send(end_attribute).to_date : event_start_date
|
|
103
115
|
(event_start_date..event_end_date.to_date).each do |enumerated_date|
|
|
104
116
|
events_grouped_by_date[enumerated_date] << event
|
|
105
117
|
end
|
|
@@ -3,5 +3,9 @@ module SimpleCalendar
|
|
|
3
3
|
def date_range
|
|
4
4
|
(start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
|
|
5
5
|
end
|
|
6
|
+
|
|
7
|
+
def url_for_previous_view
|
|
8
|
+
view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
|
|
9
|
+
end
|
|
6
10
|
end
|
|
7
11
|
end
|
|
@@ -2,17 +2,17 @@ module SimpleCalendar
|
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
def calendar(options = {}, &block)
|
|
4
4
|
raise "calendar requires a block" unless block
|
|
5
|
-
SimpleCalendar::Calendar.new(self, options
|
|
5
|
+
render SimpleCalendar::Calendar.new(self, options, &block)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def month_calendar(options = {}, &block)
|
|
9
9
|
raise "month_calendar requires a block" unless block
|
|
10
|
-
SimpleCalendar::MonthCalendar.new(self, options
|
|
10
|
+
render SimpleCalendar::MonthCalendar.new(self, options, &block)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def week_calendar(options = {}, &block)
|
|
14
14
|
raise "week_calendar requires a block" unless block
|
|
15
|
-
SimpleCalendar::WeekCalendar.new(self, options
|
|
15
|
+
render SimpleCalendar::WeekCalendar.new(self, options, &block)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module SimpleCalendar
|
|
2
2
|
class WeekCalendar < SimpleCalendar::Calendar
|
|
3
3
|
def week_number
|
|
4
|
-
format = Date.beginning_of_week == :sunday ? "%U" : "%V"
|
|
4
|
+
format = (Date.beginning_of_week == :sunday) ? "%U" : "%V"
|
|
5
5
|
start_date.beginning_of_week.strftime(format).to_i
|
|
6
6
|
end
|
|
7
7
|
|
|
@@ -19,5 +19,9 @@ module SimpleCalendar
|
|
|
19
19
|
|
|
20
20
|
(starting..ending).to_a
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
def url_for_previous_view
|
|
24
|
+
view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
|
|
25
|
+
end
|
|
22
26
|
end
|
|
23
27
|
end
|
data/lib/simple_calendar.rb
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
require "simple_calendar/engine"
|
|
1
2
|
require "simple_calendar/calendar"
|
|
2
3
|
require "simple_calendar/month_calendar"
|
|
3
4
|
require "simple_calendar/week_calendar"
|
|
4
|
-
require "simple_calendar/railtie"
|
|
5
5
|
require "simple_calendar/version"
|
|
6
6
|
require "simple_calendar/view_helpers"
|
|
7
|
+
|
|
8
|
+
module SimpleCalendar
|
|
9
|
+
autoload :Calendar, "simple_calendar/calendar"
|
|
10
|
+
autoload :MonthCalendar, "simple_calendar/month_calendar"
|
|
11
|
+
autoload :WeekCalendar, "simple_calendar/week_calendar"
|
|
12
|
+
autoload :ViewHelpers, "simple_calendar/view_helpers"
|
|
13
|
+
end
|
data/simple_calendar.gemspec
CHANGED
|
@@ -14,9 +14,7 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.rubyforge_project = "simple_calendar"
|
|
15
15
|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
17
|
s.require_paths = ["lib"]
|
|
19
18
|
|
|
20
|
-
s.add_dependency "rails", ">=
|
|
21
|
-
s.add_development_dependency "rspec"
|
|
19
|
+
s.add_dependency "rails", ">= 6.1"
|
|
22
20
|
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CalendarTest < ActionView::TestCase
|
|
4
|
+
attr_reader :calendar
|
|
5
|
+
|
|
6
|
+
setup do
|
|
7
|
+
@calendar = SimpleCalendar::Calendar.new(view)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "renders a partial with the same name as the class" do
|
|
11
|
+
assert_equal "simple_calendar/calendar", calendar.partial_name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "has start_time as the default attribute" do
|
|
15
|
+
assert_equal :start_time, calendar.attribute
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test "allows you to override the default attribute" do
|
|
19
|
+
assert_equal :starts_at, SimpleCalendar::Calendar.new(view, attribute: :starts_at).attribute
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "set a default when `partial` option isn't present" do
|
|
23
|
+
assert_equal "simple_calendar/calendar", SimpleCalendar::Calendar.new(view).partial_name
|
|
24
|
+
assert_equal "simple_calendar/month_calendar", SimpleCalendar::MonthCalendar.new(view).partial_name
|
|
25
|
+
assert_equal "simple_calendar/week_calendar", SimpleCalendar::WeekCalendar.new(view).partial_name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "allows to override the default partial" do
|
|
29
|
+
assert_equal "simple_calendar/custom_calendar", SimpleCalendar::Calendar.new(view, partial: "simple_calendar/custom_calendar").partial_name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "converts an array of events to a hash sorted by days" do
|
|
33
|
+
today, tomorrow = Date.today, Date.tomorrow
|
|
34
|
+
|
|
35
|
+
event1 = Meeting.new(start_time: today.at_midnight)
|
|
36
|
+
event2 = Meeting.new(start_time: today.at_noon)
|
|
37
|
+
event3 = Meeting.new(start_time: tomorrow.at_noon)
|
|
38
|
+
|
|
39
|
+
events = [event1, event2, event3].shuffle
|
|
40
|
+
calendar = SimpleCalendar::Calendar.new(view, events: events)
|
|
41
|
+
|
|
42
|
+
sorted_events = calendar.sorted_events
|
|
43
|
+
|
|
44
|
+
assert_equal [event1, event2], sorted_events[today]
|
|
45
|
+
assert_equal [event3], sorted_events[tomorrow]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test "converts an array of multi-day events to a hash sorted by days" do
|
|
49
|
+
today, tomorrow = Date.today, Date.tomorrow
|
|
50
|
+
|
|
51
|
+
event1 = Meeting.new(start_time: today.at_midnight, end_time: tomorrow.at_midnight)
|
|
52
|
+
event2 = Meeting.new(start_time: today.at_noon)
|
|
53
|
+
event3 = Meeting.new(start_time: tomorrow.at_noon)
|
|
54
|
+
|
|
55
|
+
events = [event1, event2, event3].shuffle
|
|
56
|
+
calendar = SimpleCalendar::Calendar.new(view, events: events)
|
|
57
|
+
|
|
58
|
+
assert_equal [event1, event2], calendar.sorted_events[today]
|
|
59
|
+
assert_equal [event1, event3], calendar.sorted_events[tomorrow]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test "handles events without a start time" do
|
|
63
|
+
event = Meeting.new(start_time: nil)
|
|
64
|
+
calendar = SimpleCalendar::Calendar.new(view, events: [event])
|
|
65
|
+
|
|
66
|
+
assert_nothing_raised do
|
|
67
|
+
calendar.sorted_events
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test "defaults to today's date" do
|
|
72
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
73
|
+
assert_equal Date.today, calendar.start_date
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
test "uses the view context's params start_date to override" do
|
|
77
|
+
params[:start_date] = Date.yesterday
|
|
78
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
79
|
+
assert_equal Date.yesterday, calendar.start_date
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test "uses the optional argument's start_date to override view_context's start_date" do
|
|
83
|
+
params[:start_date] = Date.yesterday
|
|
84
|
+
calendar = SimpleCalendar::Calendar.new(view, start_date: Date.tomorrow)
|
|
85
|
+
assert_equal Date.tomorrow, calendar.start_date
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
test "takes an option to override the start_date parameter" do
|
|
89
|
+
params[:date] = Date.yesterday
|
|
90
|
+
calendar = SimpleCalendar::Calendar.new(view, start_date_param: :date)
|
|
91
|
+
assert_equal Date.yesterday, calendar.start_date
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test "should have the current week" do
|
|
95
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
96
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
|
97
|
+
assert_includes calendar.tr_classes_for(week), "current-week"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
test "should not have the current week if it does not contain today" do
|
|
101
|
+
params[:start_date] = 6.months.ago
|
|
102
|
+
calendar = SimpleCalendar::MonthCalendar.new(view)
|
|
103
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
|
104
|
+
assert_not_includes calendar.tr_classes_for(week), "current-week"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
test "has a param that determines the start date of the calendar" do
|
|
108
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
109
|
+
rendering_variables = calendar.locals
|
|
110
|
+
assert_not_nil rendering_variables[:start_date]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
test "generates a default date if no start date is present" do
|
|
114
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
115
|
+
calendar_start_date = calendar.locals[:start_date]
|
|
116
|
+
assert_not_nil calendar_start_date
|
|
117
|
+
assert_kind_of Date, calendar_start_date
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
test "has a range of dates" do
|
|
121
|
+
calendar = SimpleCalendar::Calendar.new(view)
|
|
122
|
+
calendar_date_range = calendar.date_range
|
|
123
|
+
assert_kind_of Array, calendar_date_range
|
|
124
|
+
calendar_date_range.each do |date|
|
|
125
|
+
assert_kind_of Date, date
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
test "accepts an array of events" do
|
|
130
|
+
first_event = Meeting.new(name: "event1", start_time: Date.today)
|
|
131
|
+
second_event = Meeting.new(name: "event2", start_time: Date.today + 1.day)
|
|
132
|
+
events = [first_event, second_event]
|
|
133
|
+
calendar = SimpleCalendar::Calendar.new(view, events: events)
|
|
134
|
+
calendar_sorted_events = calendar.locals[:sorted_events]
|
|
135
|
+
|
|
136
|
+
assert_equal 2, calendar_sorted_events.length
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
test "sorts the events" do
|
|
140
|
+
first_event = Meeting.new(name: "event1", start_time: Date.today + 2.days)
|
|
141
|
+
second_event = Meeting.new(name: "event2", start_time: Date.today + 1.day)
|
|
142
|
+
third_event = Meeting.new(name: "event3", start_time: Date.today)
|
|
143
|
+
events = [first_event, third_event, second_event]
|
|
144
|
+
calendar = SimpleCalendar::Calendar.new(view, events: events)
|
|
145
|
+
calendar_sorted_events = calendar.locals[:sorted_events]
|
|
146
|
+
first_key = calendar_sorted_events.keys[0]
|
|
147
|
+
second_key = calendar_sorted_events.keys[1]
|
|
148
|
+
third_key = calendar_sorted_events.keys[2]
|
|
149
|
+
|
|
150
|
+
assert_equal third_event, calendar_sorted_events[first_key][0]
|
|
151
|
+
assert_equal second_event, calendar_sorted_events[second_key][0]
|
|
152
|
+
assert_equal first_event, calendar_sorted_events[third_key][0]
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class MonthCalendarTest < ActionView::TestCase
|
|
4
|
+
test "date_range returns a full calendar month" do
|
|
5
|
+
today = Date.today
|
|
6
|
+
calendar = SimpleCalendar::MonthCalendar.new(view, start_date: today)
|
|
7
|
+
assert calendar.date_range.min <= today.beginning_of_month
|
|
8
|
+
assert calendar.date_range.max >= today.end_of_month
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test "date_range returns the days of next and previous months on the edges of the calendar" do
|
|
12
|
+
calendar = SimpleCalendar::MonthCalendar.new(view, start_date: Date.new(2018, 8, 1))
|
|
13
|
+
assert_equal Date.new(2018, 7, 30), calendar.date_range.first
|
|
14
|
+
assert_equal Date.new(2018, 9, 2), calendar.date_range.last
|
|
15
|
+
end
|
|
16
|
+
end
|
data/test/dummy/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= link_directory ../stylesheets
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* Application styles */
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class MeetingsController < ApplicationController
|
|
2
|
+
before_action :set_meeting, only: %i[show edit update destroy]
|
|
3
|
+
|
|
4
|
+
# GET /meetings
|
|
5
|
+
def index
|
|
6
|
+
@meetings = Meeting.all
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# GET /meetings/1
|
|
10
|
+
def show
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /meetings/new
|
|
14
|
+
def new
|
|
15
|
+
@meeting = Meeting.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# GET /meetings/1/edit
|
|
19
|
+
def edit
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# POST /meetings
|
|
23
|
+
def create
|
|
24
|
+
@meeting = Meeting.new(meeting_params)
|
|
25
|
+
|
|
26
|
+
if @meeting.save
|
|
27
|
+
redirect_to @meeting, notice: "Meeting was successfully created."
|
|
28
|
+
else
|
|
29
|
+
render :new, status: :unprocessable_entity
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# PATCH/PUT /meetings/1
|
|
34
|
+
def update
|
|
35
|
+
if @meeting.update(meeting_params)
|
|
36
|
+
redirect_to @meeting, notice: "Meeting was successfully updated."
|
|
37
|
+
else
|
|
38
|
+
render :edit, status: :unprocessable_entity
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# DELETE /meetings/1
|
|
43
|
+
def destroy
|
|
44
|
+
@meeting.destroy
|
|
45
|
+
redirect_to meetings_url, notice: "Meeting was successfully destroyed."
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
51
|
+
def set_meeting
|
|
52
|
+
@meeting = Meeting.find(params[:id])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Only allow a list of trusted parameters through.
|
|
56
|
+
def meeting_params
|
|
57
|
+
params.require(:meeting).permit(:name, :start_time, :end_time)
|
|
58
|
+
end
|
|
59
|
+
end
|