simple_calendar 2.2.5 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b59a6e0877e1ff3b71901bc01ba95dc961d03313
4
- data.tar.gz: c2e415e9f1a24e92f970d50cc6119e8becd37615
2
+ SHA256:
3
+ metadata.gz: 60dcc26bdf5d0e6bc7eed23fe0bf3d5c35977b8a189b9a045897410abc4ce36e
4
+ data.tar.gz: cc92323a3b5766f2f428ff1e3adfa40641843ddd5fce25068aeb7eee224ca710
5
5
  SHA512:
6
- metadata.gz: 1baea65b91560b3d247c717dccc9daac1d789a214b7df9db56adb94d9d68877dfaf66e3e8f2023c7db92b93b443c594f0b7be7cdc6cf378f2276b983989a33e6
7
- data.tar.gz: 410701770d8ff9cc6f66132037f37a79e34dc61afc420049fc333f448cfe2ec37a06c3ba71994f893da14d3e3ea589bd300edd6386f6081a30f03e765b8f1857
6
+ metadata.gz: d7ad3f165f583b789c6b8f8300c8377eac55cac5cb138429435185a6f50ee4b4b276b4d56e75e396ff1bce3f612b9029f1aa69023e6464346de3118d1aa3d580
7
+ data.tar.gz: 994a400d806c3a3c06939828d64254efad0dd04c34c00dab5a21a842e7ff7460d4e9bb2cb988cedeec0686360e91f53ebe99697979aaf5d23ab342136c771137
@@ -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']
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- - 2.2.5
3
+ - 2.4.2
4
+ - 2.3.5
5
+ - 2.2.8
@@ -0,0 +1,14 @@
1
+ ### 2.4.1
2
+
3
+ * [FIX] Use iso8601 format for start_date links in the header. Fixes any
4
+ customization to the Rails default date format that might cause the
5
+ parser to fail parsing that with `to_date`
6
+
7
+ ### 2.4.0
8
+
9
+ * [BREAKING] Fixes Rails 4.2 by changing `block` to `passed_block`. A
10
+ security fix in Rails makes `block` a reserved local name that we can
11
+ no longer use.
12
+
13
+ **Upgrading**: If you've customized the simple_calendar views, rename
14
+ `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.
@@ -90,8 +102,6 @@ You can set a different partial name for calendars by passing the partial path.
90
102
  <% end %>
91
103
  ```
92
104
 
93
- Setting `number_of_days` is optional and defaults to 4.
94
-
95
105
  ## Rendering Events
96
106
 
97
107
  What's a calendar without events in it? There are two simple steps for creating
@@ -110,17 +120,26 @@ $ rails g scaffold Meeting name start_time:datetime
110
120
  $ rails g scaffold Meeting name start_time:datetime end_time:datetime
111
121
  ```
112
122
 
113
- By default it uses `start_time` as the attribute name. Optionally the `end_time`
114
- attribute can be used which enables multi-day event rendering.
115
-
116
- **If you'd like to use another attribute other than start_time or end_time, just
117
- 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`**
118
126
 
119
127
  ```erb
120
128
  <%= month_calendar(attribute: :starts_at) do |date| %>
121
129
  <%= date %>
122
130
  <% end %>
123
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
+
124
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**
125
144
  ```ruby
126
145
  class MyModel
@@ -186,7 +205,7 @@ edit to your heart's desire.
186
205
  Setting `Time.zone` will make sure the calendar start days are correctly computed
187
206
  in the right timezone. You can set this globally in your `application.rb` file or
188
207
  if you have a User model with a time_zone attribute, you can set it on every request by using
189
- a before_filter like the following example.
208
+ a before_action like the following example.
190
209
 
191
210
  This code example uses [Devise](https://github.com/plataformatec/devise)'s
192
211
  `current_user` and `user_signed_in?` methods to retrieve the user's timezone and set it for the duration of the request.
@@ -195,7 +214,7 @@ using some other method of authentication.
195
214
 
196
215
  ```ruby
197
216
  class ApplicationController < ActionController::Base
198
- before_filter :set_time_zone, if: :user_signed_in?
217
+ before_action :set_time_zone, if: :user_signed_in?
199
218
 
200
219
  private
201
220
 
@@ -215,7 +234,7 @@ config.time_zone = 'Central Time (US & Canada)'
215
234
  ### Beginning Of Week
216
235
 
217
236
  You can also change the beginning day of the week by setting
218
- `Date.beginning_of_week` in a `before_filter` just like in the previous
237
+ `Date.beginning_of_week` in a `before_action` just like in the previous
219
238
  example. If you want to set this globally, you can put this line in
220
239
  `config/application.rb`:
221
240
 
@@ -223,18 +242,6 @@ example. If you want to set this globally, you can put this line in
223
242
  config.beginning_of_week = :sunday
224
243
  ```
225
244
 
226
- ### Default Stylesheet
227
-
228
- If you're using Bootstrap, the calendar should already have a border and
229
- nice spacing for days.
230
-
231
- Optionally, you can include the default stylesheet for the calendar in
232
- your `app/assets/stylesheets/application.css` file:
233
-
234
- ```scss
235
- *= require simple_calendar
236
- ```
237
-
238
245
  ### Custom CSS Classes
239
246
 
240
247
  Setting classes on the table and elements are pretty easy.
@@ -319,7 +326,7 @@ The main method you'll need to implement is the `date_range` so that
319
326
  your calendar can have a custom length.
320
327
 
321
328
  ```ruby
322
- class SimpleCalendar::BusinessWeekCalendar
329
+ class SimpleCalendar::BusinessWeekCalendar < SimpleCalendar::Calendar
323
330
  private
324
331
 
325
332
  def date_range
@@ -333,7 +340,7 @@ end
333
340
  To render this in the view, you can do:
334
341
 
335
342
  ```erb
336
- <%= SimpleCalendar::BusinessWeekCalendar.new(self).render do |date| %>
343
+ <%= SimpleCalendar::BusinessWeekCalendar.new(self, {}).render do |date| %>
337
344
  <%= date %>
338
345
  <% end %>
339
346
  ```
@@ -16,17 +16,17 @@
16
16
 
17
17
  <tbody>
18
18
  <% date_range.each_slice(7) do |week| %>
19
- <tr>
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?(block) %>
23
- <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
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
- <% block.call day, sorted_events.fetch(day, []) %>
25
+ <% passed_block.call day, sorted_events.fetch(day, []) %>
26
26
  <% end %>
27
27
  <% end %>
28
28
  <% end %>
29
- </tr>
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?(block) %>
23
- <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
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
- <% block.call day, sorted_events.fetch(day, []) %>
25
+ <% passed_block.call day, sorted_events.fetch(day, []) %>
26
26
  <% end %>
27
27
  <% end %>
28
28
  <% end %>
@@ -23,10 +23,10 @@
23
23
  <tr>
24
24
  <% week.each do |day| %>
25
25
  <%= content_tag :td, class: calendar.td_classes_for(day) do %>
26
- <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(block) %>
27
- <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
26
+ <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
27
+ <% capture_haml(day, sorted_events.fetch(day, []), &passed_block) %>
28
28
  <% else %>
29
- <% block.call day, sorted_events.fetch(day, []) %>
29
+ <% passed_block.call day, sorted_events.fetch(day, []) %>
30
30
  <% end %>
31
31
  <% end %>
32
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
- block: block,
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(start_date_param => date_range.last + 1.day))
61
+ view_context.url_for(@params.merge(start_date_param => (date_range.last + 1.day).iso8601))
50
62
  end
51
63
 
52
64
  def url_for_previous_view
53
- view_context.url_for(@params.merge(start_date_param => date_range.first - 1.day))
65
+ view_context.url_for(@params.merge(start_date_param => (date_range.first - 1.day).iso8601))
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
@@ -104,10 +120,6 @@ module SimpleCalendar
104
120
  date_range.last
105
121
  end
106
122
 
107
- def date_range
108
- (start_date..(start_date + additional_days.days)).to_a
109
- end
110
-
111
123
  def additional_days
112
124
  options.fetch(:number_of_days, 4) - 1
113
125
  end
@@ -1,10 +1,8 @@
1
1
  module SimpleCalendar
2
2
  class MonthCalendar < SimpleCalendar::Calendar
3
- private
4
-
5
- def date_range
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,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "2.2.5"
2
+ VERSION = "2.4.1"
3
3
  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" : "%W"
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
 
@@ -13,13 +13,11 @@ module SimpleCalendar
13
13
  week_number + number_of_weeks - 1
14
14
  end
15
15
 
16
- private
16
+ def date_range
17
+ starting = start_date.beginning_of_week
18
+ ending = (starting + (number_of_weeks - 1).weeks).end_of_week
17
19
 
18
- def date_range
19
- starting = start_date.beginning_of_week
20
- ending = (starting + (number_of_weeks - 1).weeks).end_of_week
21
-
22
- (starting..ending).to_a
23
- end
20
+ (starting..ending).to_a
21
+ end
24
22
  end
25
23
  end
@@ -1,23 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'action_controller'
3
3
  require 'simple_calendar/calendar'
4
-
5
- class ViewContext
6
- attr_accessor :start_date, :start_date_param
7
-
8
- def initialize(start_date=nil, options={})
9
- @start_date = start_date
10
- @start_date_param = options.fetch(:start_date_param, :start_date)
11
- end
12
-
13
- def params
14
- if @start_date.present?
15
- ActionController::Parameters.new({start_date_param => @start_date})
16
- else
17
- ActionController::Parameters.new
18
- end
19
- end
20
- end
4
+ require_relative 'support/fake_event'
5
+ require_relative 'support/view_context'
21
6
 
22
7
  describe SimpleCalendar::Calendar do
23
8
  let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
@@ -113,18 +98,79 @@ describe SimpleCalendar::Calendar do
113
98
  end
114
99
  end
115
100
 
116
- it 'has a param that determines the start date of the calendar'
117
- it 'generates a default date if no start date is present'
118
- it 'has a range of dates'
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
113
+ end
114
+
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
119
140
 
120
141
  it 'can split the range of dates into weeks'
121
142
  it 'has a title'
122
143
  it 'has a next view link'
123
144
  it 'has a previous view link'
124
145
 
125
- it 'accepts an array of events'
126
- it 'sorts the events'
127
- it 'yields the events for each day'
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
128
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
173
+
174
+ it 'yields the events for each day'
129
175
  it "doesn't crash when an event has a nil start_time"
130
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
- it 'renders a full calendar month'
6
- it 'render the days of next and previous months on the edges of the calendar'
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,9 @@
1
+ class FakeEvent
2
+ attr_accessor :name, :start_time, :end_time
3
+
4
+ def initialize(name='event', start_time=nil, end_time=nil)
5
+ @name = name
6
+ @start_time = start_time
7
+ @end_time = end_time
8
+ end
9
+ 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.2.5
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2020-06-25 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,12 +73,14 @@ 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:
77
81
  - MIT
78
82
  metadata: {}
79
- post_install_message:
83
+ post_install_message:
80
84
  rdoc_options: []
81
85
  require_paths:
82
86
  - lib
@@ -91,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
95
  - !ruby/object:Gem::Version
92
96
  version: '0'
93
97
  requirements: []
94
- rubyforge_project: simple_calendar
95
- rubygems_version: 2.5.1
96
- signing_key:
98
+ rubygems_version: 3.1.4
99
+ signing_key:
97
100
  specification_version: 4
98
101
  summary: A simple Rails calendar
99
102
  test_files:
@@ -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