simple_calendar 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -6
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +37 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae8f18ccce8e55fd2c7caefb28f9260befdb50c8
|
4
|
+
data.tar.gz: ed5657eb62db1fee6021f516f935eed13c55335c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 687581a924042ef175fede1beb7fbf550dbbf5e8a936b7365d6b9c362d9484216c092bcc80abfcf3a116dff5184758393db77514c2023285662b86417e73170c
|
7
|
+
data.tar.gz: 2d70ac7b3b28297e0e6cdbf457078240dbadcff2ed0635d1f4fccae5e45acc722ebc5814367137ca9001908bbc51872987fb03c0540ffe2b00ad3ba6da5c25a8
|
data/README.md
CHANGED
@@ -106,7 +106,10 @@ this globally, you can put this line in
|
|
106
106
|
Date.beginning_of_week = :sunday
|
107
107
|
```
|
108
108
|
|
109
|
-
Setting classes on the table and elements are pretty
|
109
|
+
Setting classes on the table and elements are pretty easy.
|
110
|
+
|
111
|
+
Each of the options are passed directly to the
|
112
|
+
the `content_tag` method so each of them **must** be a hash.
|
110
113
|
|
111
114
|
```ruby
|
112
115
|
|
@@ -120,8 +123,44 @@ Setting classes on the table and elements are pretty:
|
|
120
123
|
This will set the class of `table table-bordered` on the `table` HTML
|
121
124
|
element.
|
122
125
|
|
123
|
-
|
124
|
-
|
126
|
+
### Custom Day Classes
|
127
|
+
|
128
|
+
`td` is an option for setting the options on the td content tag that is
|
129
|
+
generated. By default, simple_calendar renders the following classes for
|
130
|
+
any given day in a calendar:
|
131
|
+
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
td_class = ["day"]
|
135
|
+
td_class << "today" if today == current_calendar_date
|
136
|
+
td_class << "past" if today > current_calendar_date
|
137
|
+
td_class << "future" if today < current_calendar_date
|
138
|
+
td_class << "prev-month" if start_date.month != current_calendar_date.month && current_calendar_date < start_date
|
139
|
+
td_class << "next-month" if start_date.month != current_calendar_date.month && current_calendar_date > start_date
|
140
|
+
td_class << "current-month" if start_date.month == current_calendar_date.month
|
141
|
+
td_class << "wday-#{current_calendar_date.wday.to_s}"
|
142
|
+
```
|
143
|
+
|
144
|
+
You can set your CSS styles based upon these if you want to highlight
|
145
|
+
specific days or types of days. If you wish to override this
|
146
|
+
functionality, just set the `tr` option to a lambda that accepts two
|
147
|
+
dates and returns a hash. The hash will be passed in directly to the
|
148
|
+
content_tag options. If you wish to set a class or data attributes, just
|
149
|
+
set them as you normally would in a content_tag call.
|
150
|
+
|
151
|
+
```erb
|
152
|
+
<%= month_calendar :start_date, tr: ->(start_date,
|
153
|
+
current_calendar_date) { {class: "calendar-date", data: {day:
|
154
|
+
current_calendar_date}} } do |day| %>
|
155
|
+
<% end %>
|
156
|
+
```
|
157
|
+
|
158
|
+
This generate each day in the calendar like this:
|
159
|
+
|
160
|
+
```html
|
161
|
+
<td class="calendar-date" data-day="2014-05-11">
|
162
|
+
</td>
|
163
|
+
```
|
125
164
|
|
126
165
|
### Custom Header Links
|
127
166
|
|
@@ -143,15 +182,15 @@ The default `month_calendar` look like this:
|
|
143
182
|
<% end %>
|
144
183
|
```
|
145
184
|
|
146
|
-
|
185
|
+
`prev_link` option is a standard `link_to` that is a left arrow and
|
147
186
|
with the current url having `?start_date=2014-04-30` appended to it as
|
148
187
|
a date in the previous view of the calendar.
|
149
188
|
|
150
|
-
|
189
|
+
`next_link` option is a standard `link_to` that is a right arrow and
|
151
190
|
with the current url having `?start_date=2014-06-01` appended to it as
|
152
191
|
a date in the next view of the calendar.
|
153
192
|
|
154
|
-
|
193
|
+
`header` option is just a simple span tag with the month and year
|
155
194
|
inside of it.
|
156
195
|
|
157
196
|
If you wish to disable any of these partsof the header, just pass in
|
@@ -162,6 +201,13 @@ If you wish to disable any of these partsof the header, just pass in
|
|
162
201
|
<% end %>
|
163
202
|
```
|
164
203
|
|
204
|
+
## TODO
|
205
|
+
|
206
|
+
- Having an "events" option would be nice. Users can pass in all the
|
207
|
+
objects and we can use it to auto-filter them so the user doesn't
|
208
|
+
have to. This is what the previous version did and yielded the
|
209
|
+
day's events to the block.
|
210
|
+
- Multi-day events?
|
165
211
|
|
166
212
|
## Author
|
167
213
|
|
@@ -4,9 +4,11 @@ module SimpleCalendar
|
|
4
4
|
start_date = (params[param_name] || Time.zone.now).to_date
|
5
5
|
|
6
6
|
options.reverse_merge!(
|
7
|
+
td: day_classes,
|
7
8
|
prev_link: ->(range) { link_to raw("«"), param_name => range.first - 1.day },
|
8
|
-
header:
|
9
|
+
header: month_header,
|
9
10
|
next_link: ->(range) { link_to raw("»"), param_name => range.last + 1.day },
|
11
|
+
start_date: start_date,
|
10
12
|
)
|
11
13
|
render_calendar month_range(start_date), options, &block
|
12
14
|
end
|
@@ -16,9 +18,11 @@ module SimpleCalendar
|
|
16
18
|
number_of_weeks = options.fetch(:number_of_weeks, 1)
|
17
19
|
|
18
20
|
options.reverse_merge!(
|
21
|
+
td: day_classes,
|
19
22
|
prev_link: ->(range) { link_to raw("«"), param_name => range.first - 1.day },
|
20
23
|
header: false,
|
21
24
|
next_link: ->(range) { link_to raw("»"), param_name => range.last + 1.day },
|
25
|
+
start_date: start_date,
|
22
26
|
)
|
23
27
|
render_calendar week_range(start_date, number_of_weeks), options, &block
|
24
28
|
end
|
@@ -28,9 +32,11 @@ module SimpleCalendar
|
|
28
32
|
number_of_days_to_advance = options.fetch(:number_of_days, 4) - 1
|
29
33
|
|
30
34
|
options.reverse_merge!(
|
35
|
+
td: day_classes,
|
31
36
|
prev_link: ->(range) { link_to raw("«"), param_name => range.first - 1.day },
|
32
37
|
header: false,
|
33
38
|
next_link: ->(range) { link_to raw("»"), param_name => range.last + 1.day },
|
39
|
+
start_date: start_date,
|
34
40
|
)
|
35
41
|
render_calendar calendar_range(start_date, number_of_days_to_advance), options, &block
|
36
42
|
end
|
@@ -53,20 +59,21 @@ module SimpleCalendar
|
|
53
59
|
def render_calendar(range, options, &block)
|
54
60
|
raise 'SimpleCalendar requires a block' unless block_given?
|
55
61
|
|
56
|
-
@block
|
57
|
-
@options
|
62
|
+
@block = block
|
63
|
+
@options = options.reverse_merge default_options
|
64
|
+
@start_date = options.fetch(:start_date)
|
58
65
|
|
59
66
|
capture do
|
60
|
-
concat render_header(range)
|
67
|
+
concat render_header(@start_date, range)
|
61
68
|
concat render_table(range)
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
|
-
def render_header(range)
|
72
|
+
def render_header(start_date, range)
|
66
73
|
capture do
|
67
74
|
content_tag :div do
|
68
75
|
concat get_options(@options[:prev_link], range)
|
69
|
-
concat get_options(@options[:header])
|
76
|
+
concat get_options(@options[:header], start_date)
|
70
77
|
concat get_options(@options[:next_link], range)
|
71
78
|
end
|
72
79
|
end
|
@@ -93,7 +100,7 @@ module SimpleCalendar
|
|
93
100
|
|
94
101
|
def render_week(week)
|
95
102
|
results = week.map do |day|
|
96
|
-
content_tag :td, get_options(@options[:td], day) do
|
103
|
+
content_tag :td, get_options(@options[:td], @start_date, day) do
|
97
104
|
@block.call(day)
|
98
105
|
end
|
99
106
|
end
|
@@ -116,5 +123,28 @@ module SimpleCalendar
|
|
116
123
|
def default_options
|
117
124
|
{ table: {}, tr: {}, td: {}, }
|
118
125
|
end
|
126
|
+
|
127
|
+
def day_classes
|
128
|
+
->(start_date, current_calendar_date) {
|
129
|
+
today = Time.zone.now.to_date
|
130
|
+
td_class = ["day"]
|
131
|
+
|
132
|
+
td_class << "today" if today == current_calendar_date
|
133
|
+
td_class << "past" if today > current_calendar_date
|
134
|
+
td_class << "future" if today < current_calendar_date
|
135
|
+
td_class << "prev-month" if start_date.month != current_calendar_date.month && current_calendar_date < start_date
|
136
|
+
td_class << "next-month" if start_date.month != current_calendar_date.month && current_calendar_date > start_date
|
137
|
+
td_class << "current-month" if start_date.month == current_calendar_date.month
|
138
|
+
td_class << "wday-#{current_calendar_date.wday.to_s}"
|
139
|
+
|
140
|
+
{ class: td_class.join(" ") }
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def month_header
|
145
|
+
->(start_date) {
|
146
|
+
content_tag :span, "#{I18n.t("date.month_names")[start_date.month]} #{start_date.year}", class: "calendar-header"
|
147
|
+
}
|
148
|
+
end
|
119
149
|
end
|
120
150
|
end
|