simple_calendar 2.2.4 → 2.4.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 +5 -5
- data/.github/FUNDING.yml +12 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +8 -0
- data/README.md +42 -24
- data/app/views/simple_calendar/_calendar.html.erb +5 -5
- data/app/views/simple_calendar/_month_calendar.html.erb +3 -3
- data/app/views/simple_calendar/_week_calendar.html.erb +9 -5
- data/lib/simple_calendar/calendar.rb +24 -8
- data/lib/simple_calendar/month_calendar.rb +3 -5
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/week_calendar.rb +12 -10
- data/spec/calendar_spec.rb +75 -22
- data/spec/calendars/month_calendar_spec.rb +20 -2
- data/spec/support/fake_event.rb +9 -0
- data/spec/support/view_context.rb +20 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 994f74fe8cc221e2a6b74c3f57d24391d9214e9ad511ca03ba24a986ff0082c1
|
4
|
+
data.tar.gz: 4473aab5073e486696990218578198c35627d5fd8429bff8fb8e02a845f14b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91bcb6559bafdbe99cc18e0b6f1f6a373b5485908e0ad2622a8e2a2d5e8481e3d3bc884161a9164bd6859d2e2fc6729c715827bc7e1af5a1b91f2de5879e09d2
|
7
|
+
data.tar.gz: 7b2c6dfafab0edfecb1444fb14b6709ae89a9f324b6d64086bf4541df8001b9ee81c58f4229e96e10cdb73ba284a59d0e3abadfbe188e7cd15f546abef7be6b7
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: [excid3] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
### 2.4.0
|
2
|
+
|
3
|
+
* [BREAKING] Fixes Rails 4.2 by changing `block` to `passed_block`. A
|
4
|
+
security fix in Rails makes `block` a reserved local name that we can
|
5
|
+
no longer use.
|
6
|
+
|
7
|
+
**Upgrading**: If you've customized the simple_calendar views, rename
|
8
|
+
`block` to `passed_block`. Without this, calendar dates will be empty.
|
data/README.md
CHANGED
@@ -24,6 +24,16 @@ Just add this into your Gemfile followed by a bundle install:
|
|
24
24
|
gem "simple_calendar", "~> 2.0"
|
25
25
|
```
|
26
26
|
|
27
|
+
If you're using Bootstrap, the calendar should already have a border and
|
28
|
+
nice spacing for days.
|
29
|
+
|
30
|
+
Optionally, you can include the default stylesheet for the calendar in
|
31
|
+
your `app/assets/stylesheets/application.css` file:
|
32
|
+
|
33
|
+
```scss
|
34
|
+
*= require simple_calendar
|
35
|
+
```
|
36
|
+
|
27
37
|
Usage
|
28
38
|
-----
|
29
39
|
|
@@ -45,6 +55,8 @@ method.
|
|
45
55
|
<% end %>
|
46
56
|
```
|
47
57
|
|
58
|
+
To show the day of the month instead of the date, use `<%= date.day %>`
|
59
|
+
|
48
60
|
### Week Calendar
|
49
61
|
|
50
62
|
You can generate a week calendar with the `week_calendar` method.
|
@@ -69,6 +81,17 @@ You can generate calendars of any length by passing in the number of days you wa
|
|
69
81
|
|
70
82
|
Setting `number_of_days` is optional and defaults to 4.
|
71
83
|
|
84
|
+
### Custom Parameter Name
|
85
|
+
|
86
|
+
You can pass in `start_date_param` to change the name of the parameter
|
87
|
+
in the URL for the current calendar view.
|
88
|
+
|
89
|
+
```erb
|
90
|
+
<%= calendar start_date_param: :my_date do |date| %>
|
91
|
+
<%= date %>
|
92
|
+
<% end %>
|
93
|
+
```
|
94
|
+
|
72
95
|
### Custom Partial
|
73
96
|
|
74
97
|
You can set a different partial name for calendars by passing the partial path.
|
@@ -79,8 +102,6 @@ You can set a different partial name for calendars by passing the partial path.
|
|
79
102
|
<% end %>
|
80
103
|
```
|
81
104
|
|
82
|
-
Setting `number_of_days` is optional and defaults to 4.
|
83
|
-
|
84
105
|
## Rendering Events
|
85
106
|
|
86
107
|
What's a calendar without events in it? There are two simple steps for creating
|
@@ -99,17 +120,26 @@ $ rails g scaffold Meeting name start_time:datetime
|
|
99
120
|
$ rails g scaffold Meeting name start_time:datetime end_time:datetime
|
100
121
|
```
|
101
122
|
|
102
|
-
By default it uses `start_time` as the attribute name.
|
103
|
-
|
104
|
-
|
105
|
-
**If you'd like to use another attribute other than start_time or end_time, just
|
106
|
-
pass it in as the `attribute` or `end_attribute` options respectively**
|
123
|
+
By default it uses `start_time` as the attribute name.
|
124
|
+
**If you'd like to use another attribute other than start_time, just
|
125
|
+
pass it in as the `attribute`**
|
107
126
|
|
108
127
|
```erb
|
109
128
|
<%= month_calendar(attribute: :starts_at) do |date| %>
|
110
129
|
<%= date %>
|
111
130
|
<% end %>
|
112
131
|
```
|
132
|
+
|
133
|
+
Optionally the `end_time` attribute can be used which enables multi-day event rendering.
|
134
|
+
|
135
|
+
**Just pass in the `attribute` and `end_attribute` options respectively**
|
136
|
+
|
137
|
+
```erb
|
138
|
+
<%= month_calendar(attribute: :start_date, end_attribute: :end_date) do |date| %>
|
139
|
+
<%= date %>
|
140
|
+
<% end %>
|
141
|
+
```
|
142
|
+
|
113
143
|
**If you already have a model with a start time attribute called something other than `start_time` or accesses it through a relationship, you can alias the attribute by defining a `start_time` method in the my_model.rb file and not have to specify it separately as in the above example**
|
114
144
|
```ruby
|
115
145
|
class MyModel
|
@@ -175,7 +205,7 @@ edit to your heart's desire.
|
|
175
205
|
Setting `Time.zone` will make sure the calendar start days are correctly computed
|
176
206
|
in the right timezone. You can set this globally in your `application.rb` file or
|
177
207
|
if you have a User model with a time_zone attribute, you can set it on every request by using
|
178
|
-
a
|
208
|
+
a before_action like the following example.
|
179
209
|
|
180
210
|
This code example uses [Devise](https://github.com/plataformatec/devise)'s
|
181
211
|
`current_user` and `user_signed_in?` methods to retrieve the user's timezone and set it for the duration of the request.
|
@@ -184,7 +214,7 @@ using some other method of authentication.
|
|
184
214
|
|
185
215
|
```ruby
|
186
216
|
class ApplicationController < ActionController::Base
|
187
|
-
|
217
|
+
before_action :set_time_zone, if: :user_signed_in?
|
188
218
|
|
189
219
|
private
|
190
220
|
|
@@ -204,7 +234,7 @@ config.time_zone = 'Central Time (US & Canada)'
|
|
204
234
|
### Beginning Of Week
|
205
235
|
|
206
236
|
You can also change the beginning day of the week by setting
|
207
|
-
`Date.beginning_of_week` in a `
|
237
|
+
`Date.beginning_of_week` in a `before_action` just like in the previous
|
208
238
|
example. If you want to set this globally, you can put this line in
|
209
239
|
`config/application.rb`:
|
210
240
|
|
@@ -212,18 +242,6 @@ example. If you want to set this globally, you can put this line in
|
|
212
242
|
config.beginning_of_week = :sunday
|
213
243
|
```
|
214
244
|
|
215
|
-
### Default Stylesheet
|
216
|
-
|
217
|
-
If you're using Bootstrap, the calendar should already have a border and
|
218
|
-
nice spacing for days.
|
219
|
-
|
220
|
-
Optionally, you can include the default stylesheet for the calendar in
|
221
|
-
your `app/assets/stylesheets/application.css` file:
|
222
|
-
|
223
|
-
```scss
|
224
|
-
*= require simple_calendar
|
225
|
-
```
|
226
|
-
|
227
245
|
### Custom CSS Classes
|
228
246
|
|
229
247
|
Setting classes on the table and elements are pretty easy.
|
@@ -308,7 +326,7 @@ The main method you'll need to implement is the `date_range` so that
|
|
308
326
|
your calendar can have a custom length.
|
309
327
|
|
310
328
|
```ruby
|
311
|
-
class SimpleCalendar::BusinessWeekCalendar
|
329
|
+
class SimpleCalendar::BusinessWeekCalendar < SimpleCalendar::Calendar
|
312
330
|
private
|
313
331
|
|
314
332
|
def date_range
|
@@ -322,7 +340,7 @@ end
|
|
322
340
|
To render this in the view, you can do:
|
323
341
|
|
324
342
|
```erb
|
325
|
-
<%= SimpleCalendar::BusinessWeekCalendar.new(self).render do |date| %>
|
343
|
+
<%= SimpleCalendar::BusinessWeekCalendar.new(self, {}).render do |date| %>
|
326
344
|
<%= date %>
|
327
345
|
<% end %>
|
328
346
|
```
|
@@ -16,17 +16,17 @@
|
|
16
16
|
|
17
17
|
<tbody>
|
18
18
|
<% date_range.each_slice(7) do |week| %>
|
19
|
-
|
19
|
+
<%= content_tag :tr, class: calendar.tr_classes_for(week) do %>
|
20
20
|
<% week.each do |day| %>
|
21
21
|
<%= content_tag :td, class: calendar.td_classes_for(day) do %>
|
22
|
-
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(
|
23
|
-
<% capture_haml(day, sorted_events.fetch(day, []), &
|
22
|
+
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
|
23
|
+
<% capture_haml(day, sorted_events.fetch(day, []), &passed_block) %>
|
24
24
|
<% else %>
|
25
|
-
<%
|
25
|
+
<% passed_block.call day, sorted_events.fetch(day, []) %>
|
26
26
|
<% end %>
|
27
27
|
<% end %>
|
28
28
|
<% end %>
|
29
|
-
|
29
|
+
<% end %>
|
30
30
|
<% end %>
|
31
31
|
</tbody>
|
32
32
|
</table>
|
@@ -19,10 +19,10 @@
|
|
19
19
|
<tr>
|
20
20
|
<% week.each do |day| %>
|
21
21
|
<%= content_tag :td, class: calendar.td_classes_for(day) do %>
|
22
|
-
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(
|
23
|
-
<% capture_haml(day, sorted_events.fetch(day, []), &
|
22
|
+
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
|
23
|
+
<% capture_haml(day, sorted_events.fetch(day, []), &passed_block) %>
|
24
24
|
<% else %>
|
25
|
-
<%
|
25
|
+
<% passed_block.call day, sorted_events.fetch(day, []) %>
|
26
26
|
<% end %>
|
27
27
|
<% end %>
|
28
28
|
<% end %>
|
@@ -1,8 +1,12 @@
|
|
1
1
|
<div class="simple-calendar">
|
2
2
|
<div class="calendar-heading">
|
3
3
|
<%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
|
4
|
-
|
5
|
-
|
4
|
+
<% if calendar.number_of_weeks == 1 %>
|
5
|
+
<span class="calendar-title">Week <%= calendar.week_number %></span>
|
6
|
+
<%else%>
|
7
|
+
<span class="calendar-title">Week <%= calendar.week_number %> - <%= calendar.end_week %></span>
|
8
|
+
<%end%>
|
9
|
+
<%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
|
6
10
|
</div>
|
7
11
|
|
8
12
|
<table class="table table-striped">
|
@@ -19,10 +23,10 @@
|
|
19
23
|
<tr>
|
20
24
|
<% week.each do |day| %>
|
21
25
|
<%= content_tag :td, class: calendar.td_classes_for(day) do %>
|
22
|
-
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(
|
23
|
-
<% capture_haml(day, sorted_events.fetch(day, []), &
|
26
|
+
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
|
27
|
+
<% capture_haml(day, sorted_events.fetch(day, []), &passed_block) %>
|
24
28
|
<% else %>
|
25
|
-
<%
|
29
|
+
<% passed_block.call day, sorted_events.fetch(day, []) %>
|
26
30
|
<% end %>
|
27
31
|
<% end %>
|
28
32
|
<% end %>
|
@@ -10,16 +10,20 @@ module SimpleCalendar
|
|
10
10
|
@view_context = view_context
|
11
11
|
@options = opts
|
12
12
|
|
13
|
+
# Next and previous view links should use the same params as the current view
|
13
14
|
@params = @view_context.respond_to?(:params) ? @view_context.params : Hash.new
|
14
15
|
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
|
15
16
|
@params = @params.with_indifferent_access.except(*PARAM_KEY_BLACKLIST)
|
17
|
+
|
18
|
+
# Add in any additional params the user passed in
|
19
|
+
@params.merge!(@options.fetch(:params, {}))
|
16
20
|
end
|
17
21
|
|
18
22
|
def render(&block)
|
19
23
|
view_context.render(
|
20
24
|
partial: partial_name,
|
21
25
|
locals: {
|
22
|
-
|
26
|
+
passed_block: block,
|
23
27
|
calendar: self,
|
24
28
|
date_range: date_range,
|
25
29
|
start_date: start_date,
|
@@ -45,12 +49,24 @@ module SimpleCalendar
|
|
45
49
|
td_class
|
46
50
|
end
|
47
51
|
|
52
|
+
def tr_classes_for(week)
|
53
|
+
today = Date.current
|
54
|
+
tr_class = ['week']
|
55
|
+
tr_class << 'current-week' if week.include?(today)
|
56
|
+
|
57
|
+
tr_class
|
58
|
+
end
|
59
|
+
|
48
60
|
def url_for_next_view
|
49
|
-
view_context.url_for(@params.merge(
|
61
|
+
view_context.url_for(@params.merge(start_date_param => date_range.last + 1.day))
|
50
62
|
end
|
51
63
|
|
52
64
|
def url_for_previous_view
|
53
|
-
view_context.url_for(@params.merge(
|
65
|
+
view_context.url_for(@params.merge(start_date_param => date_range.first - 1.day))
|
66
|
+
end
|
67
|
+
|
68
|
+
def date_range
|
69
|
+
(start_date..(start_date + additional_days.days)).to_a
|
54
70
|
end
|
55
71
|
|
56
72
|
private
|
@@ -67,6 +83,10 @@ module SimpleCalendar
|
|
67
83
|
options.fetch(:end_attribute, :end_time).to_sym
|
68
84
|
end
|
69
85
|
|
86
|
+
def start_date_param
|
87
|
+
options.fetch(:start_date_param, :start_date).to_sym
|
88
|
+
end
|
89
|
+
|
70
90
|
def sorted_events
|
71
91
|
@sorted_events ||= begin
|
72
92
|
events = options.fetch(:events, []).reject { |e| e.send(attribute).nil? }.sort_by(&attribute)
|
@@ -92,7 +112,7 @@ module SimpleCalendar
|
|
92
112
|
if options.has_key?(:start_date)
|
93
113
|
options.fetch(:start_date).to_date
|
94
114
|
else
|
95
|
-
view_context.params.fetch(
|
115
|
+
view_context.params.fetch(start_date_param, Date.current).to_date
|
96
116
|
end
|
97
117
|
end
|
98
118
|
|
@@ -100,10 +120,6 @@ module SimpleCalendar
|
|
100
120
|
date_range.last
|
101
121
|
end
|
102
122
|
|
103
|
-
def date_range
|
104
|
-
(start_date..(start_date + additional_days.days)).to_a
|
105
|
-
end
|
106
|
-
|
107
123
|
def additional_days
|
108
124
|
options.fetch(:number_of_days, 4) - 1
|
109
125
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
class MonthCalendar < SimpleCalendar::Calendar
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
(start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
|
7
|
-
end
|
3
|
+
def date_range
|
4
|
+
(start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
|
5
|
+
end
|
8
6
|
end
|
9
7
|
end
|
10
8
|
|
@@ -1,21 +1,23 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
class WeekCalendar < SimpleCalendar::Calendar
|
3
3
|
def week_number
|
4
|
-
format = (Date.beginning_of_week == :sunday) ? "%U" : "%
|
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
|
|
8
|
-
|
8
|
+
def number_of_weeks
|
9
|
+
options.fetch(:number_of_weeks, 1)
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def end_week
|
13
|
+
week_number + number_of_weeks - 1
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
def date_range
|
17
|
+
starting = start_date.beginning_of_week
|
18
|
+
ending = (starting + (number_of_weeks - 1).weeks).end_of_week
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
+
(starting..ending).to_a
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
data/spec/calendar_spec.rb
CHANGED
@@ -1,22 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'action_controller'
|
3
3
|
require 'simple_calendar/calendar'
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :start_date
|
7
|
-
|
8
|
-
def initialize(start_date=nil)
|
9
|
-
@start_date = start_date
|
10
|
-
end
|
11
|
-
|
12
|
-
def params
|
13
|
-
if @start_date.present?
|
14
|
-
ActionController::Parameters.new({start_date: @start_date})
|
15
|
-
else
|
16
|
-
ActionController::Parameters.new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
4
|
+
require_relative 'support/fake_event'
|
5
|
+
require_relative 'support/view_context'
|
20
6
|
|
21
7
|
describe SimpleCalendar::Calendar do
|
22
8
|
let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
|
@@ -104,20 +90,87 @@ describe SimpleCalendar::Calendar do
|
|
104
90
|
calendar = SimpleCalendar::Calendar.new(view_context, start_date: Date.tomorrow)
|
105
91
|
expect(calendar.send(:start_date)).to eq(Date.tomorrow)
|
106
92
|
end
|
93
|
+
|
94
|
+
it "takes an option to override the start_date parameter" do
|
95
|
+
view_context = ViewContext.new(Date.yesterday, start_date_param: :date)
|
96
|
+
calendar = SimpleCalendar::Calendar.new(view_context, start_date_param: :date)
|
97
|
+
expect(calendar.send(:start_date)).to eq(Date.yesterday)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'current week class' do
|
102
|
+
it 'should have the current week' do
|
103
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
104
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
105
|
+
expect(calendar.send(:tr_classes_for, week)).to include('current-week')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not have the current week if it does not contain today' do
|
109
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new(6.months.ago))
|
110
|
+
week = calendar.date_range.each_slice(7).to_a[0]
|
111
|
+
expect(calendar.send(:tr_classes_for, week)).to_not include('current-week')
|
112
|
+
end
|
107
113
|
end
|
108
114
|
|
109
|
-
it 'has a param that determines the start date of the calendar'
|
110
|
-
|
111
|
-
|
115
|
+
it 'has a param that determines the start date of the calendar' do
|
116
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
117
|
+
|
118
|
+
rendering_variables = calendar.render[:locals]
|
119
|
+
|
120
|
+
expect(rendering_variables[:start_date]).not_to be_nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'generates a default date if no start date is present' do
|
124
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
125
|
+
|
126
|
+
calendar_start_date = calendar.render[:locals][:start_date]
|
127
|
+
|
128
|
+
expect(calendar_start_date).not_to be_nil
|
129
|
+
expect(calendar_start_date).to be_a(Date)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'has a range of dates' do
|
133
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
134
|
+
|
135
|
+
calendar_date_range = calendar.date_range
|
136
|
+
|
137
|
+
expect(calendar_date_range).to be_an(Array)
|
138
|
+
expect(calendar_date_range).to all(be_an(Date))
|
139
|
+
end
|
112
140
|
|
113
141
|
it 'can split the range of dates into weeks'
|
114
142
|
it 'has a title'
|
115
143
|
it 'has a next view link'
|
116
144
|
it 'has a previous view link'
|
117
145
|
|
118
|
-
it 'accepts an array of events'
|
119
|
-
|
120
|
-
|
146
|
+
it 'accepts an array of events' do
|
147
|
+
first_event = FakeEvent.new('event1', Date.today)
|
148
|
+
second_event = FakeEvent.new('event2', Date.today + 1.day)
|
149
|
+
events = [first_event, second_event]
|
150
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
151
|
+
|
152
|
+
calendar_sorted_events = calendar.render[:locals][:sorted_events]
|
153
|
+
|
154
|
+
expect(calendar_sorted_events.length).to eq(2)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'sorts the events' do
|
158
|
+
first_event = FakeEvent.new('event1', Date.today + 2.days)
|
159
|
+
second_event = FakeEvent.new('event2', Date.today + 1.day)
|
160
|
+
third_event = FakeEvent.new('event3', Date.today)
|
161
|
+
events = [first_event, third_event, second_event]
|
162
|
+
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
163
|
+
|
164
|
+
calendar_sorted_events = calendar.render[:locals][:sorted_events]
|
165
|
+
first_key = calendar_sorted_events.keys[0]
|
166
|
+
second_key = calendar_sorted_events.keys[1]
|
167
|
+
third_key = calendar_sorted_events.keys[2]
|
168
|
+
|
169
|
+
expect(calendar_sorted_events[first_key][0]).to eq(third_event)
|
170
|
+
expect(calendar_sorted_events[second_key][0]).to eq(second_event)
|
171
|
+
expect(calendar_sorted_events[third_key][0]).to eq(first_event)
|
172
|
+
end
|
121
173
|
|
174
|
+
it 'yields the events for each day'
|
122
175
|
it "doesn't crash when an event has a nil start_time"
|
123
176
|
end
|
@@ -1,7 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'simple_calendar/calendar'
|
2
4
|
require 'simple_calendar/month_calendar'
|
5
|
+
require 'support/view_context'
|
3
6
|
|
4
7
|
describe SimpleCalendar::MonthCalendar do
|
5
|
-
|
6
|
-
|
8
|
+
describe '#date_range' do
|
9
|
+
it 'renders a full calendar month' do
|
10
|
+
today = Date.today
|
11
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: Date.today)
|
12
|
+
|
13
|
+
expect(calendar.date_range.min).to be <= today.beginning_of_month
|
14
|
+
expect(calendar.date_range.max).to be >= today.end_of_month
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'render the days of next and previous months on the edges of the calendar' do
|
18
|
+
month = Date.new(2018, 8, 1)
|
19
|
+
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: month)
|
20
|
+
|
21
|
+
expect(calendar.date_range.first).to eq Date.new(2018, 7, 30)
|
22
|
+
expect(calendar.date_range.last).to eq Date.new(2018, 9, 2)
|
23
|
+
end
|
24
|
+
end
|
7
25
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ViewContext
|
2
|
+
attr_accessor :start_date, :start_date_param
|
3
|
+
|
4
|
+
def initialize(start_date=nil, options={})
|
5
|
+
@start_date = start_date
|
6
|
+
@start_date_param = options.fetch(:start_date_param, :start_date)
|
7
|
+
end
|
8
|
+
|
9
|
+
def params
|
10
|
+
if @start_date.present?
|
11
|
+
ActionController::Parameters.new({start_date_param => @start_date})
|
12
|
+
else
|
13
|
+
ActionController::Parameters.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(options = {})
|
18
|
+
options
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -45,9 +45,11 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".github/FUNDING.yml"
|
48
49
|
- ".gitignore"
|
49
50
|
- ".rspec"
|
50
51
|
- ".travis.yml"
|
52
|
+
- CHANGELOG.md
|
51
53
|
- Gemfile
|
52
54
|
- LICENSE.txt
|
53
55
|
- README.md
|
@@ -71,6 +73,8 @@ files:
|
|
71
73
|
- spec/calendars/month_calendar_spec.rb
|
72
74
|
- spec/simple_calendar_spec.rb
|
73
75
|
- spec/spec_helper.rb
|
76
|
+
- spec/support/fake_event.rb
|
77
|
+
- spec/support/view_context.rb
|
74
78
|
- spec/views_generators_spec.rb
|
75
79
|
homepage: https://github.com/excid3/simple_calendar
|
76
80
|
licenses:
|
@@ -91,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
95
|
- !ruby/object:Gem::Version
|
92
96
|
version: '0'
|
93
97
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.6.8
|
98
|
+
rubygems_version: 3.1.2
|
96
99
|
signing_key:
|
97
100
|
specification_version: 4
|
98
101
|
summary: A simple Rails calendar
|
@@ -101,4 +104,6 @@ test_files:
|
|
101
104
|
- spec/calendars/month_calendar_spec.rb
|
102
105
|
- spec/simple_calendar_spec.rb
|
103
106
|
- spec/spec_helper.rb
|
107
|
+
- spec/support/fake_event.rb
|
108
|
+
- spec/support/view_context.rb
|
104
109
|
- spec/views_generators_spec.rb
|