simple_calendar 1.1.3 → 1.1.4

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: 796aabd52df101faf850fc78a815ff5c77cdec9f
4
- data.tar.gz: 624565897e01b55df78704601826f9c7bac1d432
3
+ metadata.gz: 79b8594840b9e18fdf52c8c4fb78cc9010be8e38
4
+ data.tar.gz: ded158c9f803340a257b9ea3a00702d8dd0b4f55
5
5
  SHA512:
6
- metadata.gz: 5998574923fe285b6bbe1ff027961dec8217fa2a88dfcb15985dbd1926c5ddb8d39ac74d585aa5f2f9fb19343d2e1f620dff5f4132f7a25e218fe6697ff7a3be
7
- data.tar.gz: 4e06bc29b002fcb7dfb288907634637dee753bddf74b6db7e7a02c1b3b4986cc41aab3fc35636590a4c49d39a2f71c61e93296c785f49f3ea0d15d4e2837259a
6
+ metadata.gz: 25a41a24e87bc41f7cbb68297b64a57b17e8267ba15b5b5cd36b4ea2b37a1b7997d7c6f08575c1d7c8ca563bd8703b5769ca0891d300031d927bd36ea7607c74
7
+ data.tar.gz: 0728743caa642b7a3d057ce182bcf86e49410e56d17624683bc03642a44b6c74f91bc98dc072603cbf2eafb4f9e35e622c5ded6a5471f2c7aac7a36799213597
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Simple Calendar
2
2
  ===============
3
3
 
4
- Simple Calendar is design to do one thing really really well: render a
4
+ Simple Calendar is designed to do one thing really really well: render a
5
5
  calendar. It lets you render a calendar of any size. Maybe you want a
6
6
  day view, a 4 day agenda, a week view, a month view, or a 6 week
7
7
  calendar. You can do all of that with the new gem, just give it a range
@@ -97,7 +97,7 @@ end
97
97
  ```
98
98
 
99
99
  Then in your view, you can pass in the `events` option to render. The
100
- events will automatically be filter out by day for you.
100
+ events will automatically be filtered out by day for you.
101
101
 
102
102
  ```erb
103
103
  <%= month_calendar events: @events do |date, events| %>
@@ -145,13 +145,20 @@ class ApplicationController < ActionController::Base
145
145
  end
146
146
  end
147
147
  ```
148
+ If you want to set the time zone globally, you can set the following in
149
+ `config/application.rb`:
148
150
 
149
- You can also change the beginning day of the week. If you want to set
150
- this globally, you can put this line in
151
- `config/initializers/simple_calendar.rb`:
151
+ ```ruby
152
+ config.time_zone = 'Central Time (US & Canada)'
153
+ ```
154
+
155
+ You can also change the beginning day of the week by setting
156
+ `Date.beginning_of_week` in a `before_filter` just like in the previous
157
+ example. If you want to set this globally, you can put this line in
158
+ `config/application.rb`:
152
159
 
153
160
  ```ruby
154
- Date.beginning_of_week = :sunday
161
+ config.beginning_of_week = :sunday
155
162
  ```
156
163
 
157
164
  Setting classes on the table and elements are pretty easy.
@@ -161,7 +168,7 @@ the `content_tag` method so each of them **must** be a hash.
161
168
 
162
169
  ```ruby
163
170
 
164
- <%= calendar table: {class: "table table-bordered"}, tr: {class: "row"}, td: {class: "day"}, do |day| %>
171
+ <%= calendar table: {class: "table table-bordered"}, tr: {class: "calendar-row"}, td: {class: "day"}, do |date| %>
165
172
  <% end %>
166
173
  ```
167
174
 
@@ -207,7 +214,7 @@ This generate each day in the calendar like this:
207
214
 
208
215
  Instead of writing the lambdas inline, a cleaner approach is to write a
209
216
  helper that returns a lambda. You can duplicate the following example by
210
- adding this to your helpers
217
+ adding this to one of your helpers:
211
218
 
212
219
  ```ruby
213
220
  def month_calendar_td_options
@@ -220,7 +227,7 @@ end
220
227
  And then your view would use `month_calendar_td_options` as the value.
221
228
 
222
229
  ```erb
223
- <%= month_calendar td: month_calendar_td_options do |day| %>
230
+ <%= month_calendar td: month_calendar_td_options do |date| %>
224
231
  <% end %>
225
232
  ```
226
233
 
@@ -230,49 +237,63 @@ Each of the calendar methods will generate a header with links to the
230
237
  previous and next views. The `month_calendar` also includes a header
231
238
  with a title that tells you the current month and year that you are viewing.
232
239
 
233
- To change these, you can pass in the `prev_link`, `title`, and
240
+ To change these, you can pass in the `previous_link`, `title`, and
234
241
  `next_link` options into the calendar methods.
235
242
 
236
- The default `month_calendar` look like this:
243
+ **Use a method in your helpers to return a lambda instead of writing
244
+ them inline like these examples so your views are cleaner.**
237
245
 
238
- ```erb
239
- <%= month_calendar prev_link: ->(range) { link_to raw("&laquo;"), param_name => range.first - 1.day },
240
- title: ->{ content_tag :span, "#{I18n.t("date.month_names")[start_date.month]} #{start_date.year}", class: "calendar-title" },
241
- next_link: ->(range) { link_to raw("&raquo;"), param_name => range.last + 1.day } do |day| %>
246
+ * `title` option is a lambda that shows at the top of the calendar. For
247
+ month calendars, this is the Month and Year (May 2014)
242
248
 
249
+ ```erb
250
+ <%= calendar title: ->(start_date) { content_tag :span, "#{I18n.t("date.month_names")[start_date.month]} #{start_date.year}", class: "calendar-title" } do |date, events| %>
243
251
  <% end %>
244
252
  ```
245
253
 
246
- `title` option is a lambda that
247
-
248
- `prev_link` option is a standard `link_to` that is a left arrow and
254
+ * `previous_link` option is a standard `link_to` that is a left arrow and
249
255
  with the current url having `?start_date=2014-04-30` appended to it as
250
256
  a date in the previous view of the calendar.
251
257
 
252
- `next_link` option is a standard `link_to` that is a right arrow and
258
+ ```erb
259
+ <%= month_calendar previous_link: ->(param, date_range) { link_to raw("&laquo;"), {param => date_range.first - 1.day} } do |date, events| %>
260
+ <% end %>
261
+ ```
262
+
263
+ * `next_link` option is a standard `link_to` that is a right arrow and
253
264
  with the current url having `?start_date=2014-06-01` appended to it as
254
265
  a date in the next view of the calendar.
255
266
 
256
- `title` option is, by default, a simple span tag with the month and year
257
- inside of it.
267
+ ```erb
268
+ <%= calendar next_link: ->(param, date_range) { link_to raw("&raquo;"), {param => date_range.last + 1.day} } do |date, events| %>
269
+ <% end %>
270
+ ```
271
+
272
+ * `header` lets you add options to the header tag
273
+
274
+ ```erb
275
+ <%= calendar header: {class: "calendar-header"} do |date, events| %>
276
+ <% end %>
277
+ ```
278
+
279
+ * `thead` allows you to customize the table headers. These are the
280
+ abbreviated day names by default (Sun Mon Tue Wed).
258
281
 
259
- If you wish to add some styles to the header, you can use the `header`
260
- option:
282
+ You can disable the `thead` line if you like by passing in `false`.
261
283
 
262
284
  ```erb
263
- <%= month_calendar header: {class: "calendar-header"} do |day| %>
285
+ <%= calendar thead: false do |date, events| %>
264
286
  <% end %>
265
287
  ```
266
288
 
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`
289
+ * `day_names` lets you customize the day names in the `thead` row.
269
290
 
270
291
  If you want to use full day names instead of the abbreviated ones in the
271
292
  table header, you can pass in the `day_names` option which points to a
272
293
  validate I18n array.
273
294
 
274
295
  ```erb
275
- <%= calendar day_names: "date.day_names" do |day, events| %>
296
+ <%= calendar day_names: "date.day_names" do |date, events| %>
276
297
  <% end %>
277
298
  ```
278
299
 
@@ -293,7 +314,7 @@ By default we use the `date.abbr_day_names` translation to have shorter
293
314
  header names.
294
315
 
295
316
  ```erb
296
- <%= calendar day_names: "date.abbr_day_names" do |day, events| %>
317
+ <%= calendar day_names: "date.abbr_day_names" do |date, events| %>
297
318
  <% end %>
298
319
  ```
299
320
 
@@ -310,13 +331,14 @@ This renders:
310
331
  </thead>
311
332
  ```
312
333
 
313
- You can disable the `thead` line if you like by passing in `false`.
334
+ ### AJAX Calendars
314
335
 
315
- ```erb
316
- <%= month_calendar thead: false do |day| %>
317
- <% end %>
318
- ```
336
+ Rendering calendars that update with AJAX is pretty simple. You'll need
337
+ to wrap your calendar in a div, overwrite the `next_link` and `previous_link` options, and setup your
338
+ controller to respond to JS requests. The response can simply replace
339
+ the HTML of the div with the newly rendered calendar.
319
340
 
341
+ Take a look at **[excid3/simple_calendar-ajax-example](https://github.com/excid3/simple_calendar-ajax-example)** to see how it is done.
320
342
 
321
343
  ## TODO
322
344
 
@@ -106,7 +106,7 @@ module SimpleCalendar
106
106
  end
107
107
 
108
108
  def start_date
109
- @start_date ||= (params[param_name] || Time.zone.now).to_date
109
+ @start_date ||= (params[param_name] || get_option(:start_date) || Time.zone.now).to_date
110
110
  end
111
111
 
112
112
  def date_range
@@ -139,7 +139,7 @@ module SimpleCalendar
139
139
  when Hash
140
140
  option
141
141
  else
142
- option.call(*params) if option.respond_to? :call
142
+ option.respond_to?(:call) ? option.call(*params) : option
143
143
  end
144
144
  end
145
145
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
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.3
4
+ version: 1.1.4
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-05-14 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails