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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08c146f5a7b38c2327df0f20dc4026598a0f9d8a
4
- data.tar.gz: ac0162169f6c8fb91de3ec38db5fea38e9a82678
3
+ metadata.gz: 796aabd52df101faf850fc78a815ff5c77cdec9f
4
+ data.tar.gz: 624565897e01b55df78704601826f9c7bac1d432
5
5
  SHA512:
6
- metadata.gz: 761eaa0a862661b6a6e50794f7ed4a7ff286eae058019abd49b70ec298dd0b5d1971a73e475da816114298007aadcf8eac59a90474c6988e66f541c99012ec80
7
- data.tar.gz: ca7d0f0b8cbbfcd82d2543d769f6d92cd78b16ec8c397e5e1f226ebc490e7fc5199dd4e3956000326a93a8811a9fd7ba43c6b15bac0faf769168c097a3c1e3de
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`, `header`, and
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("&laquo;"), param_name => range.first - 1.day },
240
- header: ->{ content_tag :span, "#{I18n.t("date.month_names")[start_date.month]} #{start_date.year}", class: "calendar-header" },
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("&raquo;"), 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
- `header` option is just a simple span tag with the month and year
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 disable any of these partsof the header, just pass in
258
- `false` and that will hide it:
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
- <%= month_calendar header: false do |day| %>
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
- header: default_header,
14
+ title: default_title,
14
15
  next_link: default_next_link,
15
16
  td: default_td_classes,
16
- header_div: {class: "calendar-header"}
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 :div, get_option(:header_div) do
34
+ content_tag :header, get_option(:header) do
34
35
  concat get_option(:previous_link, param_name, date_range)
35
- concat get_option(:header, start_date)
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
- content_tag :tbody, get_option(:tbody) do
44
- render_weeks
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 day, events_for_date(day)
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("&laquo;"), param => date_range.first - 1.day }
82
84
  end
83
85
 
84
- def default_header
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("&raquo;"), 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 default_header
8
- ->(start_date) { content_tag :span, month_name(start_date), class: "calendar-header" }
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)
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver