simple_calendar 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,17 @@ SimpleCalendar will look for a method on your model called `start_time`.
24
24
  This is used to determine the day and time of the event. This should be
25
25
  a `DateTime` object or at least respond similarly.
26
26
 
27
+ The simplest way to use SimpleCalendar is to have an attribute on your
28
+ model called `start_time` and you won't need to make any changes to your
29
+ model at all. For example, I used `rails g model Event name:string
30
+ start_time:datetime` to generate this class:
31
+
32
+ ```ruby
33
+ class Event < ActiveRecord::Base
34
+ attr_accessible :name, :start_time
35
+ end
36
+ ```
37
+
27
38
  If you don't have an attribute called `start_time` on your model, you
28
39
  can simply delegate like so:
29
40
 
@@ -72,7 +83,8 @@ You may even pass options to calendar renderer to customize it's behavior
72
83
  <div><%= link_to event.title, event %></div>
73
84
  <% end %>
74
85
 
75
- This time calendar will use prev and next as labels for previous and next month links (which are normally set to &amp;laquo; (&laquo;) and &amp;raquo; (&raquo;)
86
+ This time calendar will use prev and next as labels for previous and next month
87
+ links (which are normally set to &amp;laquo; (&laquo;) and &amp;raquo; (&raquo;)
76
88
 
77
89
  Possible options:
78
90
 
@@ -80,6 +92,21 @@ Possible options:
80
92
  :month # current month, default: from params or current month
81
93
  :prev_text # previous month link text, default: &laquo;
82
94
  :next_text # next month link text, default: &raquo;
95
+ :start_day # starting day of week, default: :sunday
96
+
97
+ If you wish to have Monday as the first day of the week, you'll need to
98
+ change a couple things. First, when rendering the calendar, use the
99
+ `:start_day => :monday` option like so:
100
+
101
+ ```ruby
102
+ <%= calendar @events, :start_day => :monday do |event| %>
103
+ <%= link_to event.title, event %>
104
+ <% end %>
105
+ ```
106
+
107
+ And the second step is to make sure you've set your `I18n.locale` to the
108
+ correct one. There is a lot of information here regarding use of locales in Rails:
109
+ https://github.com/svenfuchs/rails-i18n
83
110
 
84
111
  CSS
85
112
  ---
@@ -92,8 +119,3 @@ the following line to your css:
92
119
 
93
120
  By default simple_calendar will set the calendar to use .bordered-table
94
121
  and .calendar classes.
95
-
96
- TODO
97
- ====
98
-
99
- * Customizable starting day of week
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -9,13 +9,14 @@ module SimpleCalendar
9
9
  :year => (params[:year] || Time.zone.now.year).to_i,
10
10
  :month => (params[:month] || Time.zone.now.month).to_i,
11
11
  :prev_text => raw("&laquo;"),
12
- :next_text => raw("&raquo;")
12
+ :next_text => raw("&raquo;"),
13
+ :start_day => :sunday
13
14
  }
14
15
  options.reverse_merge! opts
15
16
  events ||= []
16
17
  selected_month = Date.civil(options[:year], options[:month])
17
18
  current_date = Date.today
18
- range = build_range selected_month
19
+ range = build_range selected_month, options
19
20
  month_array = build_month range
20
21
 
21
22
  draw_calendar(selected_month, month_array, current_date, events, options, block)
@@ -23,12 +24,12 @@ module SimpleCalendar
23
24
 
24
25
  private
25
26
 
26
- def build_range(selected_month)
27
+ def build_range(selected_month, options)
27
28
  start_date = selected_month.beginning_of_month
28
- start_date = start_date.sunday? ? start_date : start_date.beginning_of_week(:sunday)
29
+ start_date = start_date.send(options[:start_day].to_s+'?') ? start_date : start_date.beginning_of_week(options[:start_day])
29
30
 
30
31
  end_date = selected_month.end_of_month
31
- end_date = end_date.saturday? ? end_date : end_date.end_of_week(:sunday)
32
+ end_date = end_date.saturday? ? end_date : end_date.end_of_week(options[:start_day])
32
33
 
33
34
  (start_date..end_date).to_a
34
35
  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: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  segments:
59
59
  - 0
60
- hash: 1074299040452234765
60
+ hash: -1583268356881306530
61
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  segments:
68
68
  - 0
69
- hash: 1074299040452234765
69
+ hash: -1583268356881306530
70
70
  requirements: []
71
71
  rubyforge_project: simple_calendar
72
72
  rubygems_version: 1.8.24