simple_calendar 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -98,6 +98,7 @@ Possible options:
98
98
  :next_text # next month link text, default: »
99
99
  :start_day # starting day of week, default: :sunday
100
100
  :empty_date # block called when a date is empty
101
+ :class # HTML class attribute for the calendar
101
102
 
102
103
  If you wish to have Monday as the first day of the week, you'll need to
103
104
  change a couple things. First, when rendering the calendar, use the
@@ -134,5 +135,12 @@ the following line to your css:
134
135
  .calendar td { height: 100px; width: 14.28%; }
135
136
  ```
136
137
 
137
- By default simple_calendar will set the calendar to use .bordered-table
138
- and .calendar classes.
138
+ By default simple_calendar will set the calendar to use .table
139
+ .table-bordered .table-striped and .calendar classes.
140
+
141
+ You can also override the class by passing in the `class` option.
142
+
143
+ ```erb
144
+ <%= calendar @events, class: "simple-calendar" do |event| %>
145
+ <% end %>
146
+ ```
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -10,14 +10,16 @@ module SimpleCalendar
10
10
  :month => (params[:month] || Time.zone.now.month).to_i,
11
11
  :prev_text => raw("&laquo;"),
12
12
  :next_text => raw("&raquo;"),
13
- :start_day => :sunday
13
+ :start_day => :sunday,
14
+ :class => "table table-bordered table-striped calendar",
15
+
14
16
  }
15
17
  options.reverse_merge! opts
16
18
  events ||= []
17
- selected_month = Date.civil(options[:year], options[:month])
19
+ selected_month = Date.new(options[:year], options[:month])
18
20
  current_date = Date.today
19
21
  range = build_range selected_month, options
20
- month_array = build_month range
22
+ month_array = range.each_slice(7).to_a
21
23
 
22
24
  draw_calendar(selected_month, month_array, current_date, events, options, block)
23
25
  end
@@ -25,42 +27,20 @@ module SimpleCalendar
25
27
  private
26
28
 
27
29
  def build_range(selected_month, options)
28
- start_date = selected_month.beginning_of_month
29
- start_date = start_date.send(options[:start_day].to_s+'?') ? start_date : start_date.beginning_of_week(options[:start_day])
30
-
31
- end_date = selected_month.end_of_month
32
- end_date = end_date.saturday? ? end_date : end_date.end_of_week(options[:start_day])
30
+ start_date = selected_month.beginning_of_month.beginning_of_week(options[:start_day])
31
+ end_date = selected_month.end_of_month.end_of_week(options[:start_day])
33
32
 
34
33
  (start_date..end_date).to_a
35
34
  end
36
35
 
37
- def build_month(date_range)
38
- month = []
39
- week = []
40
- i = 0
41
-
42
- date_range.each do |date|
43
- week << date
44
- if i == 6
45
- i = 0
46
- month << week
47
- week = []
48
- else
49
- i += 1
50
- end
51
- end
52
-
53
- month
54
- end
55
-
56
36
  # Renders the calendar table
57
37
  def draw_calendar(selected_month, month, current_date, events, options, block)
58
38
  tags = []
59
39
  today = Date.today
60
- content_tag(:table, :class => "table table-bordered table-striped calendar") do
40
+ content_tag(:table, :class => options[:class]) do
61
41
  tags << month_header(selected_month, options)
62
42
  day_names = I18n.t("date.abbr_day_names")
63
- day_names.rotate(1) if options[:start_date] == :monday
43
+ day_names = day_names.rotate((Date::DAYS_INTO_WEEK[options[:start_day]] + 1) % 7)
64
44
  tags << content_tag(:thead, content_tag(:tr, day_names.collect { |name| content_tag :th, name, :class => (selected_month.month == Date.today.month && Date.today.strftime("%a") == name ? "current-day" : nil)}.join.html_safe))
65
45
  tags << content_tag(:tbody, :'data-month'=>selected_month.month, :'data-year'=>selected_month.year) do
66
46
 
@@ -75,12 +55,15 @@ module SimpleCalendar
75
55
  td_class << "future" if today < date
76
56
  td_class << "wday-#{date.wday.to_s}" # <- to enable different styles for weekend, etc
77
57
 
58
+ cur_events = day_events(date, events)
59
+
60
+ td_class << (cur_events.any? ? "events" : "no-events")
61
+
78
62
  content_tag(:td, :class => td_class.join(" "), :'data-date-iso'=>date.to_s, 'data-date'=>date.to_s.gsub('-', '/')) do
79
63
  content_tag(:div) do
80
64
  divs = []
81
65
  concat content_tag(:div, date.day.to_s, :class=>"day_number")
82
66
 
83
- cur_events = day_events(date, events)
84
67
  if cur_events.empty? && options[:empty_date]
85
68
  concat options[:empty_date].call(date)
86
69
  else
@@ -122,14 +105,8 @@ module SimpleCalendar
122
105
  end
123
106
 
124
107
  # Generates the link to next and previous months
125
- def month_link(text, month, opts={})
126
- link_to(text, "#{simple_calendar_path}?month=#{month.month}&year=#{month.year}", opts)
127
- end
128
-
129
- # Returns the full path to the calendar
130
- # This is used for generating the links to the next and previous months
131
- def simple_calendar_path
132
- request.fullpath.split('?').first
108
+ def month_link(text, date, opts={})
109
+ link_to(text, {:month => date.month, :year => date.year}, opts)
133
110
  end
134
111
  end
135
112
  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.5
4
+ version: 0.1.6
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: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-02-25 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: 676043402436518100
60
+ hash: 2470290329357686492
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: 676043402436518100
69
+ hash: 2470290329357686492
70
70
  requirements: []
71
71
  rubyforge_project: simple_calendar
72
72
  rubygems_version: 1.8.24