simple_calendar 2.1.5 → 2.2.0

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
2
  SHA1:
3
- metadata.gz: ee54f122b99caa56554d7a2460d03ce4f908d601
4
- data.tar.gz: ade58551f991b9c6d3509c40168dc759d55c52f5
3
+ metadata.gz: 8eae1b807d337ea3455ee73edfc5f72347d76f03
4
+ data.tar.gz: 31892462fa9549830caacf088c2bf5e29257e3be
5
5
  SHA512:
6
- metadata.gz: b095272aa825af1b5f0e86f1dcba946a226bd259c12d0a010dee842c7cf9fbb62e132cfe36ec8eef7e15512e91768f42c84baafa6aa914dcdf407446049b9b9a
7
- data.tar.gz: c489d8ed9b0d466880194c0e40153428b9639e5b084c5cfbfae585d9181979a52462485ed6e21a19e2f11928b4ab7c0634f3caf4784ce84a6030acd521b70244
6
+ metadata.gz: 6b1f60f31bc3f24e674bfabb1b29a4b8976fb9e0750b8cdb4a74ce443e6ebcce13903c25aa9591bfc9682895b534c077c66283af42f84f23f876ea9b05aeba2e
7
+ data.tar.gz: b5ee956d4ee2764ddee313684693f36fecaa5bf4120d98d69d7b4a6995845d3334bdc11ecb5d92478b3bb9afaffa7dc0c2f2a5a77bdd048dd52a66a1df59a898
data/.travis.yml CHANGED
@@ -1,6 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
4
- - 2.2.2
5
- - 2.1.6
6
- - 2.0.0
3
+ - 2.3.1
4
+ - 2.2.5
data/README.md CHANGED
@@ -20,8 +20,9 @@ Installation
20
20
  ------------
21
21
 
22
22
  Just add this into your Gemfile followed by a bundle install:
23
-
24
- gem "simple_calendar", "~> 2.0"
23
+ ```ruby
24
+ gem "simple_calendar", "~> 2.0"
25
+ ```
25
26
 
26
27
  Usage
27
28
  -----
@@ -68,6 +69,18 @@ You can generate calendars of any length by passing in the number of days you wa
68
69
 
69
70
  Setting `number_of_days` is optional and defaults to 4.
70
71
 
72
+ ### Custom Partial
73
+
74
+ You can set a different partial name for calendars by passing the partial path.
75
+
76
+ ```erb
77
+ <%= calendar partial: 'products/calendar' do |date| %>
78
+ <%= date %>
79
+ <% end %>
80
+ ```
81
+
82
+ Setting `number_of_days` is optional and defaults to 4.
83
+
71
84
  ## Rendering Events
72
85
 
73
86
  What's a calendar without events in it? There are two simple steps for creating
@@ -79,13 +92,18 @@ model called Meeting, but you can add this to any model or Ruby object.
79
92
  Here's an example model:
80
93
 
81
94
  ```bash
82
- rails g scaffold Meeting name start_time:datetime
95
+ # single day events
96
+ $ rails g scaffold Meeting name start_time:datetime
97
+
98
+ # multi-day events
99
+ $ rails g scaffold Meeting name start_time:datetime end_time:datetime
83
100
  ```
84
101
 
85
- By default it uses `start_time` as the attribute name.
102
+ By default it uses `start_time` as the attribute name. Optionally the `end_time`
103
+ attribute can be used which enables multi-day event rendering.
86
104
 
87
- **If you'd like to use another attribute other than start_time, just
88
- pass it in as the `attribute` option**
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**
89
107
 
90
108
  ```erb
91
109
  <%= month_calendar(attribute: :starts_at) do |date| %>
@@ -96,7 +114,7 @@ pass it in as the `attribute` option**
96
114
  ```ruby
97
115
  class MyModel
98
116
  ## Other code related to your model lives here
99
-
117
+
100
118
  def start_time
101
119
  self.my_related_model.start ##Where 'start' is a attribute of type 'Date' accessible through MyModel's relationship
102
120
  end
@@ -146,7 +164,7 @@ You can customize the layouts for each of the calendars by running the
146
164
  generators for simple_calendar:
147
165
 
148
166
  ```bash
149
- rails g simple_calendar:views
167
+ $ rails g simple_calendar:views
150
168
  ```
151
169
 
152
170
  This will generate a folder in app/views called simple_calendar that you
@@ -210,9 +228,6 @@ your `app/assets/stylesheets/application.css` file:
210
228
 
211
229
  Setting classes on the table and elements are pretty easy.
212
230
 
213
- You can simply run the following command to install the calendar views
214
- and then add your own helpers to the table, rows, headers, and days.
215
-
216
231
  simple_calendar comes with a handful of useful classes for each day in
217
232
  the calendar that you can use:
218
233
 
@@ -292,14 +307,14 @@ it will correspond to the name of the template it will try to render.
292
307
  The main method you'll need to implement is the `date_range` so that
293
308
  your calendar can have a custom length.
294
309
 
295
- ```
310
+ ```ruby
296
311
  class SimpleCalendar::BusinessWeekCalendar
297
312
  private
298
313
 
299
314
  def date_range
300
315
  beginning = start_date.beginning_of_week + 1.day
301
316
  ending = start_date.end_of_week - 1.day
302
- (beginning..ending)
317
+ (beginning..ending).to_a
303
318
  end
304
319
  end
305
320
  ```
@@ -338,7 +353,6 @@ With modifications as appropriate.
338
353
 
339
354
  ## TODO
340
355
 
341
- - Multi-day events
342
356
  - Rspec tests for Calendar
343
357
  - Rspec tests for MonthCalendar
344
358
  - Rspec tests for WeekCalendar
@@ -56,18 +56,34 @@ module SimpleCalendar
56
56
  private
57
57
 
58
58
  def partial_name
59
- self.class.name.underscore
59
+ @options[:partial] || self.class.name.underscore
60
60
  end
61
61
 
62
62
  def attribute
63
63
  options.fetch(:attribute, :start_time).to_sym
64
64
  end
65
65
 
66
+ def end_attribute
67
+ options.fetch(:end_attribute, :end_time).to_sym
68
+ end
69
+
66
70
  def sorted_events
67
71
  events = options.fetch(:events, []).sort_by(&attribute)
68
-
69
72
  scheduled = events.reject { |e| e.send(attribute).nil? }
70
- scheduled.group_by { |e| e.send(attribute).to_date }
73
+ group_events_by_date(scheduled)
74
+ end
75
+
76
+ def group_events_by_date(events)
77
+ events_grouped_by_date = Hash.new {|h,k| h[k] = [] }
78
+
79
+ events.each do |event|
80
+ event_start_date = event.send(attribute).to_date
81
+ event_end_date = (event.respond_to?(end_attribute) && !event.respond_to?(end_attribute).nil?) ? event.send(end_attribute).to_date : event_start_date
82
+ (event_start_date..event_end_date).to_a.each do |enumerated_date|
83
+ events_grouped_by_date[enumerated_date] << event
84
+ end
85
+ end
86
+ events_grouped_by_date
71
87
  end
72
88
 
73
89
  def start_date
@@ -78,6 +94,10 @@ module SimpleCalendar
78
94
  end
79
95
  end
80
96
 
97
+ def end_date
98
+ date_range.last
99
+ end
100
+
81
101
  def date_range
82
102
  (start_date..(start_date + additional_days.days)).to_a
83
103
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "2.1.5"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
19
  s.require_paths = ["lib"]
21
20
 
22
21
  s.add_dependency 'rails', '>= 3.0'
@@ -33,6 +33,16 @@ describe SimpleCalendar::Calendar do
33
33
  it 'allows you to override the default attribute' do
34
34
  expect(SimpleCalendar::Calendar.new(ViewContext.new, attribute: :starts_at).send(:attribute)).to eq(:starts_at)
35
35
  end
36
+
37
+ it "set a default when `partial` option isn't present" do
38
+ expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/calendar')
39
+ expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/month_calendar')
40
+ expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq('simple_calendar/week_calendar')
41
+ end
42
+
43
+ it 'allows to override the default partial' do
44
+ expect(SimpleCalendar::Calendar.new(ViewContext.new, partial: 'simple_calendar/custom_calendar').send(:partial_name)).to eq('simple_calendar/custom_calendar')
45
+ end
36
46
  end
37
47
 
38
48
  describe "#sorted_events" do
@@ -52,6 +62,22 @@ describe SimpleCalendar::Calendar do
52
62
  expect(sorted_events[tomorrow]).to eq([event3])
53
63
  end
54
64
 
65
+ it 'converts an array of multi-day events to a hash sorted by days' do
66
+ today, tomorrow = Date.today, Date.tomorrow
67
+
68
+ event1 = double(start_time: today.at_midnight, end_time: tomorrow.at_midnight)
69
+ event2 = double(start_time: today.at_noon)
70
+ event3 = double(start_time: tomorrow.at_noon)
71
+
72
+ events = [event1, event2, event3].shuffle
73
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
74
+
75
+ sorted_events = calendar.send(:sorted_events)
76
+
77
+ expect(sorted_events[today]).to eq([event1, event2])
78
+ expect(sorted_events[tomorrow]).to eq([event1, event3])
79
+ end
80
+
55
81
  it 'handles events without a start time' do
56
82
  event = double(start_time: nil)
57
83
  calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])
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.1.5
4
+ version: 2.2.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: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -41,9 +41,7 @@ dependencies:
41
41
  description: A simple Rails 3 and Rails 4 calendar
42
42
  email:
43
43
  - excid3@gmail.com
44
- executables:
45
- - console
46
- - setup
44
+ executables: []
47
45
  extensions: []
48
46
  extra_rdoc_files: []
49
47
  files: