calendar_helper 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
|
|
1
1
|
/*
|
2
2
|
A blue based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
3
|
-
|
3
|
+
|
4
4
|
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
5
|
-
|
6
|
-
Colors:
|
7
|
-
Light Blue: bbccff
|
5
|
+
|
6
|
+
Colors:
|
7
|
+
Light Blue: bbccff
|
8
8
|
White: eeddee
|
9
9
|
Turq: 003355
|
10
10
|
Cream: ffffdd
|
@@ -64,3 +64,6 @@
|
|
64
64
|
.today{
|
65
65
|
background-color: #4682b4;
|
66
66
|
}
|
67
|
+
.weekNumber {
|
68
|
+
background-color: #dedede;
|
69
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
/*
|
2
2
|
A grey based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
3
|
-
|
3
|
+
|
4
4
|
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
5
|
-
|
6
|
-
Colors:
|
5
|
+
|
6
|
+
Colors:
|
7
7
|
dk: 787888
|
8
8
|
lt: 4f4f5b
|
9
9
|
lter: a8a8a8
|
@@ -73,10 +73,6 @@ thead tr {
|
|
73
73
|
background-color: white;
|
74
74
|
color: black;
|
75
75
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
lt: 4f4f5b
|
80
|
-
lter: a8a8a8
|
81
|
-
white: ffffff
|
82
|
-
|
76
|
+
.weekNumber {
|
77
|
+
background-color: #222;
|
78
|
+
}
|
data/lib/calendar_helper.rb
CHANGED
@@ -40,6 +40,7 @@ module CalendarHelper
|
|
40
40
|
# :next_month_text => nil # Displayed right of the month name if set
|
41
41
|
# :month_header => false # If you use false, the current month header will disappear.
|
42
42
|
# :calendar_title => month_names[options[:month]] # Pass in a custom title for the calendar. Defaults to month name
|
43
|
+
# :show_other_months => true # Do not show the days for the previous and next months
|
43
44
|
#
|
44
45
|
# For more customization, you can pass a code block to this method, that will get one argument, a Date object,
|
45
46
|
# and return a values for the individual table cells. The block can return an array, [cell_text, cell_attrs],
|
@@ -96,7 +97,12 @@ module CalendarHelper
|
|
96
97
|
:next_month_text => nil,
|
97
98
|
:month_header => true,
|
98
99
|
:calendar_title => month_names[options[:month]],
|
99
|
-
:summary => "Calendar for #{month_names[options[:month]]} #{options[:year]}"
|
100
|
+
:summary => "Calendar for #{month_names[options[:month]]} #{options[:year]}",
|
101
|
+
:show_week_numbers => false,
|
102
|
+
:week_number_class => 'weekNumber',
|
103
|
+
:week_number_title => 'CW',
|
104
|
+
:week_number_format => :iso8601, # :iso8601 or :us_canada,
|
105
|
+
:show_other_months => true
|
100
106
|
}
|
101
107
|
options = defaults.merge options
|
102
108
|
|
@@ -121,9 +127,9 @@ module CalendarHelper
|
|
121
127
|
cal << %(<tr>)
|
122
128
|
if options[:previous_month_text] or options[:next_month_text]
|
123
129
|
cal << %(<th colspan="2">#{options[:previous_month_text]}</th>)
|
124
|
-
colspan=3
|
130
|
+
colspan = options[:show_week_numbers] ? 4 : 3
|
125
131
|
else
|
126
|
-
colspan=7
|
132
|
+
colspan = options[:show_week_numbers] ? 8 : 7
|
127
133
|
end
|
128
134
|
cal << %(<th colspan="#{colspan}" class="#{options[:month_name_class]}">#{options[:calendar_title]}</th>)
|
129
135
|
cal << %(<th colspan="2">#{options[:next_month_text]}</th>) if options[:next_month_text]
|
@@ -132,6 +138,8 @@ module CalendarHelper
|
|
132
138
|
|
133
139
|
cal << %(<tr class="#{options[:day_name_class]}">)
|
134
140
|
|
141
|
+
cal << %(<th>#{options[:week_number_title]}</th>) if options[:show_week_numbers]
|
142
|
+
|
135
143
|
week_days.each do |wday|
|
136
144
|
cal << %(<th id="#{th_id(Date::DAYNAMES[wday], options[:table_id])}" scope="col">)
|
137
145
|
cal << (options[:abbrev] ? %(<abbr title="#{day_names[wday]}">#{abbr_day_names[wday]}</abbr>) : day_names[wday])
|
@@ -141,7 +149,10 @@ module CalendarHelper
|
|
141
149
|
cal << "</tr></thead><tbody><tr>"
|
142
150
|
|
143
151
|
# previous month
|
144
|
-
beginning_of_week(first, first_weekday)
|
152
|
+
begin_of_week = beginning_of_week(first, first_weekday)
|
153
|
+
cal << %(<td class="#{options[:week_number_class]}">#{week_number(begin_of_week, options[:week_number_format])}</td>) if options[:show_week_numbers]
|
154
|
+
|
155
|
+
begin_of_week.upto(first - 1) do |d|
|
145
156
|
cal << generate_other_month_cell(d, options)
|
146
157
|
end unless first.wday == first_weekday
|
147
158
|
|
@@ -149,6 +160,7 @@ module CalendarHelper
|
|
149
160
|
cell_text, cell_attrs = block.call(cur)
|
150
161
|
cell_text ||= cur.mday
|
151
162
|
cell_attrs ||= {}
|
163
|
+
cell_attrs["data-date"] = cur
|
152
164
|
cell_attrs[:headers] = th_id(cur, options[:table_id])
|
153
165
|
cell_attrs[:class] ||= options[:day_class]
|
154
166
|
cell_attrs[:class] += " weekendDay" if [0, 6].include?(cur.wday)
|
@@ -156,7 +168,14 @@ module CalendarHelper
|
|
156
168
|
cell_attrs[:class] += " today" if (cur == today) and options[:show_today]
|
157
169
|
|
158
170
|
cal << generate_cell(cell_text, cell_attrs)
|
159
|
-
|
171
|
+
|
172
|
+
if cur.wday == last_weekday
|
173
|
+
cal << %(</tr>)
|
174
|
+
if cur != last
|
175
|
+
cal << %(<tr>)
|
176
|
+
cal << %(<td class="#{options[:week_number_class]}">#{week_number(cur + 1, options[:week_number_format])}</td>) if options[:show_week_numbers]
|
177
|
+
end
|
178
|
+
end
|
160
179
|
end
|
161
180
|
|
162
181
|
# next month
|
@@ -170,6 +189,29 @@ module CalendarHelper
|
|
170
189
|
|
171
190
|
private
|
172
191
|
|
192
|
+
def week_number(day, format)
|
193
|
+
case format
|
194
|
+
when :iso8601
|
195
|
+
reference_day = seek_previous_wday(day, 1)
|
196
|
+
reference_day.strftime('%V').to_i
|
197
|
+
when :us_canada
|
198
|
+
# US: the first day of the year defines the first calendar week
|
199
|
+
first_day_of_year = Date.new((day + 7).year, 1, 1)
|
200
|
+
reference_day = seek_next_wday(seek_next_wday(day, first_day_of_year.wday), 0)
|
201
|
+
reference_day.strftime('%U').to_i
|
202
|
+
else
|
203
|
+
raise "Invalid calendar week format provided."
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def seek_previous_wday(ref_date, wday)
|
208
|
+
ref_date - days_between(ref_date.wday, wday)
|
209
|
+
end
|
210
|
+
|
211
|
+
def seek_next_wday(ref_date, wday)
|
212
|
+
ref_date + days_between(ref_date.wday, wday)
|
213
|
+
end
|
214
|
+
|
173
215
|
def first_day_of_week(day)
|
174
216
|
day
|
175
217
|
end
|
@@ -201,10 +243,14 @@ module CalendarHelper
|
|
201
243
|
end
|
202
244
|
|
203
245
|
def generate_other_month_cell(date, options)
|
246
|
+
unless options[:show_other_months]
|
247
|
+
return generate_cell("", {})
|
248
|
+
end
|
204
249
|
cell_attrs = {}
|
205
250
|
cell_attrs[:headers] = th_id(date, options[:table_id])
|
206
251
|
cell_attrs[:class] = options[:other_month_class]
|
207
252
|
cell_attrs[:class] += " weekendDay" if weekend?(date)
|
253
|
+
cell_attrs["data-date"] = date
|
208
254
|
|
209
255
|
cell_text = date.day
|
210
256
|
if options[:accessible]
|
@@ -135,6 +135,16 @@ class CalendarHelperTest < Test::Unit::TestCase
|
|
135
135
|
assert_match %r{<td [^>]*headers=\"calendar-2011-08-mon\"[^>]*>1</td>}, html
|
136
136
|
end
|
137
137
|
|
138
|
+
def test_week_number_iso8601
|
139
|
+
html = calendar_with_defaults(:year => 2011, :month => 1, :week_number_format => :iso8601, :show_week_numbers => true, :first_day_of_week => 1)
|
140
|
+
[52,1,2,3,4,5].each { |cw| assert_match %r{<td class=\"weekNumber\">#{cw}</td>}, html }
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_week_number_us_canada
|
144
|
+
html = calendar_with_defaults(:year => 2011, :month => 1, :week_number_format => :us_canada, :show_week_numbers => true)
|
145
|
+
[1,2,3,4,5,6].each { |cw| assert_match %r{<td class=\"weekNumber\">#{cw}</td>}, html }
|
146
|
+
end
|
147
|
+
|
138
148
|
def test_non_english_language
|
139
149
|
# mock I18n.t to simulate internationalized setting
|
140
150
|
CalendarHelper.const_set :I18n, Class.new {
|
metadata
CHANGED
@@ -1,91 +1,90 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: calendar_helper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Geoffrey Grosenbach
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2013-08-05 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: open4
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
31
36
|
name: rake
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
37
|
prerelease: false
|
40
|
-
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rdoc
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
54
47
|
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rdoc
|
55
51
|
prerelease: false
|
56
|
-
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.10'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: flexmock
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
65
53
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 19
|
58
|
+
segments:
|
59
|
+
- 3
|
60
|
+
- 10
|
61
|
+
version: "3.10"
|
70
62
|
type: :development
|
63
|
+
version_requirements: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: flexmock
|
71
66
|
prerelease: false
|
72
|
-
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
68
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
78
|
+
description: " A simple helper for creating an HTML calendar. The \"calendar\" method will\n be automatically available to your Rails view templates, or can be used\n with Sinatra or other webapps.\n\n There is also a Rails generator that copies some stylesheets for use alone\n or alongside existing stylesheets.\n"
|
82
79
|
email: boss@topfunky.com
|
83
80
|
executables: []
|
81
|
+
|
84
82
|
extensions: []
|
85
|
-
|
83
|
+
|
84
|
+
extra_rdoc_files:
|
86
85
|
- README.rdoc
|
87
86
|
- History.rdoc
|
88
|
-
files:
|
87
|
+
files:
|
89
88
|
- MIT-LICENSE
|
90
89
|
- README.rdoc
|
91
90
|
- History.rdoc
|
@@ -95,31 +94,40 @@ files:
|
|
95
94
|
- app/assets/stylesheets/calendar_styles/grey.css
|
96
95
|
- app/assets/stylesheets/calendar_styles/red.css
|
97
96
|
- test/test_calendar_helper.rb
|
97
|
+
has_rdoc: true
|
98
98
|
homepage:
|
99
99
|
licenses: []
|
100
|
+
|
100
101
|
post_install_message:
|
101
|
-
rdoc_options:
|
102
|
+
rdoc_options:
|
102
103
|
- --main
|
103
104
|
- README.rdoc
|
104
|
-
require_paths:
|
105
|
+
require_paths:
|
105
106
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
108
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
117
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
118
125
|
requirements: []
|
126
|
+
|
119
127
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 1.6.2
|
121
129
|
signing_key:
|
122
130
|
specification_version: 3
|
123
131
|
summary: A simple helper for creating an HTML calendar
|
124
|
-
test_files:
|
132
|
+
test_files:
|
125
133
|
- test/test_calendar_helper.rb
|