simple_calendar 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -8
- data/lib/simple_calendar/calendar.rb +25 -9
- data/lib/simple_calendar/month_calendar.rb +2 -2
- data/lib/simple_calendar/version.rb +1 -1
- 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: 796aabd52df101faf850fc78a815ff5c77cdec9f
|
4
|
+
data.tar.gz: 624565897e01b55df78704601826f9c7bac1d432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5998574923fe285b6bbe1ff027961dec8217fa2a88dfcb15985dbd1926c5ddb8d39ac74d585aa5f2f9fb19343d2e1f620dff5f4132f7a25e218fe6697ff7a3be
|
7
|
+
data.tar.gz: 4e06bc29b002fcb7dfb288907634637dee753bddf74b6db7e7a02c1b3b4986cc41aab3fc35636590a4c49d39a2f71c61e93296c785f49f3ea0d15d4e2837259a
|
data/README.md
CHANGED
@@ -224,25 +224,27 @@ And then your view would use `month_calendar_td_options` as the value.
|
|
224
224
|
<% end %>
|
225
225
|
```
|
226
226
|
|
227
|
-
### Custom Header Links
|
227
|
+
### Custom Header Title And Links
|
228
228
|
|
229
229
|
Each of the calendar methods will generate a header with links to the
|
230
230
|
previous and next views. The `month_calendar` also includes a header
|
231
|
-
that tells you the current month and year that you are viewing.
|
231
|
+
with a title that tells you the current month and year that you are viewing.
|
232
232
|
|
233
|
-
To change these, you can pass in the `prev_link`, `
|
233
|
+
To change these, you can pass in the `prev_link`, `title`, and
|
234
234
|
`next_link` options into the calendar methods.
|
235
235
|
|
236
236
|
The default `month_calendar` look like this:
|
237
237
|
|
238
238
|
```erb
|
239
239
|
<%= month_calendar prev_link: ->(range) { link_to raw("«"), param_name => range.first - 1.day },
|
240
|
-
|
240
|
+
title: ->{ content_tag :span, "#{I18n.t("date.month_names")[start_date.month]} #{start_date.year}", class: "calendar-title" },
|
241
241
|
next_link: ->(range) { link_to raw("»"), param_name => range.last + 1.day } do |day| %>
|
242
242
|
|
243
243
|
<% end %>
|
244
244
|
```
|
245
245
|
|
246
|
+
`title` option is a lambda that
|
247
|
+
|
246
248
|
`prev_link` option is a standard `link_to` that is a left arrow and
|
247
249
|
with the current url having `?start_date=2014-04-30` appended to it as
|
248
250
|
a date in the previous view of the calendar.
|
@@ -251,17 +253,71 @@ a date in the previous view of the calendar.
|
|
251
253
|
with the current url having `?start_date=2014-06-01` appended to it as
|
252
254
|
a date in the next view of the calendar.
|
253
255
|
|
254
|
-
`
|
256
|
+
`title` option is, by default, a simple span tag with the month and year
|
255
257
|
inside of it.
|
256
258
|
|
257
|
-
If you wish to
|
258
|
-
|
259
|
+
If you wish to add some styles to the header, you can use the `header`
|
260
|
+
option:
|
261
|
+
|
262
|
+
```erb
|
263
|
+
<%= month_calendar header: {class: "calendar-header"} do |day| %>
|
264
|
+
<% end %>
|
265
|
+
```
|
266
|
+
|
267
|
+
The table header (thead) is the row of day names across the top. It
|
268
|
+
tells you which column is which day. For example `Sun Mon Tue Wed`
|
269
|
+
|
270
|
+
If you want to use full day names instead of the abbreviated ones in the
|
271
|
+
table header, you can pass in the `day_names` option which points to a
|
272
|
+
validate I18n array.
|
273
|
+
|
274
|
+
```erb
|
275
|
+
<%= calendar day_names: "date.day_names" do |day, events| %>
|
276
|
+
<% end %>
|
277
|
+
```
|
278
|
+
|
279
|
+
Which renders:
|
280
|
+
|
281
|
+
```html
|
282
|
+
<thead>
|
283
|
+
<tr>
|
284
|
+
<th>Sunday</th>
|
285
|
+
<th>Monday</th>
|
286
|
+
<th>Tuesday</th>
|
287
|
+
<th>Wednesday</th>
|
288
|
+
</tr>
|
289
|
+
</thead>
|
290
|
+
```
|
291
|
+
|
292
|
+
By default we use the `date.abbr_day_names` translation to have shorter
|
293
|
+
header names.
|
259
294
|
|
260
295
|
```erb
|
261
|
-
<%=
|
296
|
+
<%= calendar day_names: "date.abbr_day_names" do |day, events| %>
|
262
297
|
<% end %>
|
263
298
|
```
|
264
299
|
|
300
|
+
This renders:
|
301
|
+
|
302
|
+
```html
|
303
|
+
<thead>
|
304
|
+
<tr>
|
305
|
+
<th>Sun</th>
|
306
|
+
<th>Mon</th>
|
307
|
+
<th>Tue</th>
|
308
|
+
<th>Wed</th>
|
309
|
+
</tr>
|
310
|
+
</thead>
|
311
|
+
```
|
312
|
+
|
313
|
+
You can disable the `thead` line if you like by passing in `false`.
|
314
|
+
|
315
|
+
```erb
|
316
|
+
<%= month_calendar thead: false do |day| %>
|
317
|
+
<% end %>
|
318
|
+
```
|
319
|
+
|
320
|
+
|
265
321
|
## TODO
|
266
322
|
|
267
323
|
- Multi-day events?
|
@@ -9,11 +9,12 @@ module SimpleCalendar
|
|
9
9
|
@events = opts.delete(:events) { [] }
|
10
10
|
|
11
11
|
opts.reverse_merge!(
|
12
|
+
header: {class: "calendar-header"},
|
12
13
|
previous_link: default_previous_link,
|
13
|
-
|
14
|
+
title: default_title,
|
14
15
|
next_link: default_next_link,
|
15
16
|
td: default_td_classes,
|
16
|
-
|
17
|
+
thead: default_thead,
|
17
18
|
)
|
18
19
|
|
19
20
|
@options = opts
|
@@ -30,9 +31,9 @@ module SimpleCalendar
|
|
30
31
|
|
31
32
|
def render_header
|
32
33
|
capture do
|
33
|
-
content_tag :
|
34
|
+
content_tag :header, get_option(:header) do
|
34
35
|
concat get_option(:previous_link, param_name, date_range)
|
35
|
-
concat get_option(:
|
36
|
+
concat get_option(:title, start_date)
|
36
37
|
concat get_option(:next_link, param_name, date_range)
|
37
38
|
end
|
38
39
|
end
|
@@ -40,8 +41,9 @@ module SimpleCalendar
|
|
40
41
|
|
41
42
|
def render_table
|
42
43
|
content_tag :table, get_option(:table) do
|
43
|
-
|
44
|
-
|
44
|
+
capture do
|
45
|
+
concat get_option(:thead, date_range.to_a.slice(0, 7))
|
46
|
+
concat content_tag(:tbody, render_weeks, get_option(:tbody))
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -57,7 +59,7 @@ module SimpleCalendar
|
|
57
59
|
def render_week(week)
|
58
60
|
results = week.map do |day|
|
59
61
|
content_tag :td, get_option(:td, start_date, day) do
|
60
|
-
block.call
|
62
|
+
block.call(day, events_for_date(day))
|
61
63
|
end
|
62
64
|
end
|
63
65
|
safe_join results
|
@@ -81,7 +83,7 @@ module SimpleCalendar
|
|
81
83
|
->(param, date_range) { link_to raw("«"), param => date_range.first - 1.day }
|
82
84
|
end
|
83
85
|
|
84
|
-
def
|
86
|
+
def default_title
|
85
87
|
->(start_date) { }
|
86
88
|
end
|
87
89
|
|
@@ -89,8 +91,22 @@ module SimpleCalendar
|
|
89
91
|
->(param, date_range) { link_to raw("»"), param => date_range.last + 1.day }
|
90
92
|
end
|
91
93
|
|
94
|
+
def default_thead
|
95
|
+
->(dates) {
|
96
|
+
content_tag(:thead) do
|
97
|
+
content_tag(:tr) do
|
98
|
+
capture do
|
99
|
+
dates.each do |date|
|
100
|
+
concat content_tag(:th, I18n.t(options.fetch(:day_names, "date.abbr_day_names"))[date.wday])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
92
108
|
def start_date
|
93
|
-
@start_date ||= (params[param_name] ||Time.zone.now).to_date
|
109
|
+
@start_date ||= (params[param_name] || Time.zone.now).to_date
|
94
110
|
end
|
95
111
|
|
96
112
|
def date_range
|
@@ -4,8 +4,8 @@ module SimpleCalendar
|
|
4
4
|
@date_range ||= start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
->(start_date) { content_tag :span, month_name(start_date)
|
7
|
+
def default_title
|
8
|
+
->(start_date) { content_tag :span, month_name(start_date) }
|
9
9
|
end
|
10
10
|
|
11
11
|
def month_name(start_date)
|