simple_calendar 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -15
- data/lib/simple_calendar/calendar.rb +2 -1
- data/lib/simple_calendar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1111d9baa8fca2e69d5e1891e1df353a6725e703
|
4
|
+
data.tar.gz: acc48d21cb13b6596b2981161d8104a05e176b49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a9501ebb265c7721b7fea63d3dff1a979444800a2b82119696ada6fc4e43287889b522df95b859f6da6ef2fa5283901f1f7bad007c2c6a09084447c9e7bd4eb
|
7
|
+
data.tar.gz: 4bd2cd2f82f5ab03d12fdd363b672ab1918fded1fe6d82f70a28732977136cb2978f54a82ed1f6810d3325b7ec0bfa3f6693d1db2d76bc51393602bfaa899144
|
data/README.md
CHANGED
@@ -66,25 +66,25 @@ Setting `number_of_days` is optional and defaults to 4.
|
|
66
66
|
|
67
67
|
## Rendering Events
|
68
68
|
|
69
|
-
What's a calendar without events in it? There are two simple steps for
|
70
|
-
|
69
|
+
What's a calendar without events in it? There are two simple steps for creating
|
70
|
+
calendars with events.
|
71
71
|
|
72
72
|
The first step is to add the following to your model. We'll be using a
|
73
|
-
model called
|
73
|
+
model called Meeting, but you can add this to any model or Ruby object.
|
74
74
|
|
75
75
|
Here's an example model:
|
76
76
|
|
77
77
|
```bash
|
78
|
-
rails g scaffold
|
78
|
+
rails g scaffold Meeting name starts_at:datetime
|
79
79
|
```
|
80
80
|
|
81
81
|
We use the `has_calendar` method to tell simple_calendar how to filter
|
82
|
-
and sort the
|
83
|
-
start date/time of your
|
82
|
+
and sort the meetings on the different calendar days. This should be the
|
83
|
+
start date/time of your meeting. By default it uses `starts_at` as the
|
84
84
|
attribute name.
|
85
85
|
|
86
86
|
```ruby
|
87
|
-
class
|
87
|
+
class Meeting < ActiveRecord::Base
|
88
88
|
extend SimpleCalendar
|
89
89
|
has_calendar
|
90
90
|
|
@@ -93,32 +93,32 @@ class Event < ActiveRecord::Base
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
-
In your controller, query for these
|
97
|
-
variable. We'll just load up all the
|
96
|
+
In your controller, query for these meetings and store them in an instance
|
97
|
+
variable. We'll just load up all the meetings for this example.
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
def index
|
101
|
-
@
|
101
|
+
@meetings = Meeting.all
|
102
102
|
end
|
103
103
|
```
|
104
104
|
|
105
105
|
Then in your view, you can pass in the `events` option to render. The
|
106
|
-
|
106
|
+
meetings will automatically be filtered out by day for you.
|
107
107
|
|
108
108
|
```erb
|
109
|
-
<%= month_calendar events: @
|
109
|
+
<%= month_calendar events: @meetings do |date, meetings| %>
|
110
110
|
<%= date %>
|
111
111
|
|
112
|
-
<%
|
112
|
+
<% meetings.each do |meeting| %>
|
113
113
|
<div>
|
114
|
-
<%=
|
114
|
+
<%= meeting.name %>
|
115
115
|
</div>
|
116
116
|
<% end %>
|
117
117
|
<% end %>
|
118
118
|
```
|
119
119
|
|
120
120
|
If you pass in objects that don't respond to the attribute method (like
|
121
|
-
starts_at), then all the
|
121
|
+
starts_at), then all the meetings will be yielded each day. This lets you
|
122
122
|
do custom filtering however you want.
|
123
123
|
|
124
124
|
## Customizing The Calendar
|
@@ -151,6 +151,13 @@ class ApplicationController < ActionController::Base
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
```
|
154
|
+
On the other hand, you can always pass a ``ActiveSupport::TimeZone`` object as an option to avoid possible timezone pollution:
|
155
|
+
|
156
|
+
```erb
|
157
|
+
<%= calendar timezone: ActiveSupport::TimeZone.new('Taipei') do |date, events| %>
|
158
|
+
<% end %>
|
159
|
+
```
|
160
|
+
|
154
161
|
If you want to set the time zone globally, you can set the following in
|
155
162
|
`config/application.rb`:
|
156
163
|
|
@@ -7,6 +7,7 @@ module SimpleCalendar
|
|
7
7
|
def initialize(view_context, opts={})
|
8
8
|
@view_context = view_context
|
9
9
|
@events = opts.delete(:events) { [] }
|
10
|
+
@timezone = opts.fetch(:timezone, Time.zone)
|
10
11
|
|
11
12
|
opts.reverse_merge!(
|
12
13
|
header: {class: "calendar-header"},
|
@@ -72,7 +73,7 @@ module SimpleCalendar
|
|
72
73
|
def events_for_date(current_date)
|
73
74
|
if events.any? && events.first.respond_to?(:simple_calendar_start_time)
|
74
75
|
events.select do |e|
|
75
|
-
current_date == e.send(:simple_calendar_start_time).to_date
|
76
|
+
current_date == @timezone.utc_to_local(e.send(:simple_calendar_start_time)).to_date
|
76
77
|
end.sort_by(&:simple_calendar_start_time)
|
77
78
|
else
|
78
79
|
events
|
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: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|