calendar_helper 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +13 -0
- data/README.txt +30 -0
- data/Rakefile +31 -0
- data/generators/calendar_styles/calendar_styles_generator.rb +20 -0
- data/generators/calendar_styles/templates/blue/style.css +63 -0
- data/generators/calendar_styles/templates/grey/style.css +74 -0
- data/generators/calendar_styles/templates/red/style.css +56 -0
- data/init.rb +1 -0
- data/lib/calendar_helper.rb +141 -0
- data/test/stylesheet_tester.html +32 -0
- data/test/test_calendar_helper.rb +85 -0
- metadata +69 -0
data/History.txt
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Jeremy Voorhis and Geoffrey Grosenbach
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
History.txt
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
generators/calendar_styles/calendar_styles_generator.rb
|
7
|
+
generators/calendar_styles/templates/blue/style.css
|
8
|
+
generators/calendar_styles/templates/grey/style.css
|
9
|
+
generators/calendar_styles/templates/red/style.css
|
10
|
+
init.rb
|
11
|
+
lib/calendar_helper.rb
|
12
|
+
test/stylesheet_tester.html
|
13
|
+
test/test_calendar_helper.rb
|
data/README.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
CalendarHelper
|
2
|
+
==============
|
3
|
+
|
4
|
+
A simple helper for creating an HTML calendar. The "calendar" method will be automatically available to your view templates.
|
5
|
+
|
6
|
+
There is also a Rails generator that copies some stylesheets for use alone or alongside existing stylesheets.
|
7
|
+
|
8
|
+
Authors
|
9
|
+
=======
|
10
|
+
|
11
|
+
Jeremy Voorhis -- http://jvoorhis.com
|
12
|
+
Original implementation
|
13
|
+
|
14
|
+
Jarkko Laine -- http://jlaine.net/
|
15
|
+
Dynamic enhancements for starting week on Monday and highlighting weekends
|
16
|
+
|
17
|
+
Geoffrey Grosenbach -- http://nubyonrails.com
|
18
|
+
Test suite and conversion to a Rails plugin
|
19
|
+
|
20
|
+
Usage
|
21
|
+
=====
|
22
|
+
|
23
|
+
See the RDoc (or use "rake rdoc").
|
24
|
+
|
25
|
+
To copy the CSS files, use
|
26
|
+
|
27
|
+
./script/generate calendar_styles
|
28
|
+
|
29
|
+
CSS will be copied to subdirectories of public/stylesheets/calendar.
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/calendar_helper.rb'
|
6
|
+
|
7
|
+
Hoe.new('calendar_helper', CalendarHelper::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'seattlerb'
|
9
|
+
p.author = 'Geoffrey Grosenbach'
|
10
|
+
p.email = 'boss AT topfunky.com'
|
11
|
+
p.summary = 'Generates a configurable, CSS-tagged HTML calendar.'
|
12
|
+
p.description = "A simple method to create an HTML calendar for a single month. Can be styled with CSS. Usable with Ruby on Rails."
|
13
|
+
p.url = "http://rubyforge.org/projects/seattlerb"
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
# desc "Test task (actually runs specs)"
|
18
|
+
# task "test" do
|
19
|
+
# system "spec --format specdoc --color spec/*_spec.rb"
|
20
|
+
# end
|
21
|
+
|
22
|
+
# -- Rails-specific --
|
23
|
+
|
24
|
+
desc 'Generate documentation for the calendar_helper plugin.'
|
25
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = 'CalendarHelper'
|
28
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
29
|
+
rdoc.rdoc_files.include('README')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CalendarStylesGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
calendar_themes_dir = "public/stylesheets/calendar"
|
6
|
+
m.directory calendar_themes_dir
|
7
|
+
|
8
|
+
# Copy files
|
9
|
+
%w(red blue grey).each do |dir|
|
10
|
+
m.directory File.join(calendar_themes_dir, dir)
|
11
|
+
m.file File.join("#{dir}/style.css"), File.join(calendar_themes_dir, "#{dir}/style.css")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Dir.read("vendor/public/calendar_helper/generators/calendar_styles/templates").each do |dir|
|
15
|
+
# m.file "orig", File.join(calendar_themes_dir, dir.name, "some_file.css")
|
16
|
+
# end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
A blue based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
3
|
+
|
4
|
+
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
5
|
+
|
6
|
+
Colors:
|
7
|
+
Light Blue: bbccff
|
8
|
+
White: eeddee
|
9
|
+
Turq: 003355
|
10
|
+
Cream: ffffdd
|
11
|
+
*/
|
12
|
+
|
13
|
+
.calendar {
|
14
|
+
margin: auto;
|
15
|
+
}
|
16
|
+
|
17
|
+
.monthName th {
|
18
|
+
font-weight: normal;
|
19
|
+
text-align: right;
|
20
|
+
padding-top: 1em;
|
21
|
+
padding-bottom: 0.7em;
|
22
|
+
}
|
23
|
+
|
24
|
+
.dayName th {
|
25
|
+
font-size: 0.7em;
|
26
|
+
padding-top: 0.6em;
|
27
|
+
padding-bottom: 0.3em;
|
28
|
+
background-color: #303030;
|
29
|
+
color: white;
|
30
|
+
}
|
31
|
+
|
32
|
+
.otherMonth, .day, .specialDay {
|
33
|
+
padding: 0.7em 1em;
|
34
|
+
border-right: 1px solid white;
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
.otherMonth {
|
39
|
+
color: #eeeeee;
|
40
|
+
background-color: white;
|
41
|
+
}
|
42
|
+
|
43
|
+
.day, .specialDay {
|
44
|
+
text-align: center;
|
45
|
+
border-bottom: 1px dotted #bbbbbb;
|
46
|
+
background-color: #bbccff;
|
47
|
+
}
|
48
|
+
.specialDay {
|
49
|
+
background-color: #003355;
|
50
|
+
color: white;
|
51
|
+
}
|
52
|
+
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
53
|
+
color: white;
|
54
|
+
text-decoration: none;
|
55
|
+
padding: 1em;
|
56
|
+
}
|
57
|
+
.specialDay a:hover {
|
58
|
+
color: white;
|
59
|
+
background-color: black;
|
60
|
+
}
|
61
|
+
.weekendDay {
|
62
|
+
background-color: #ffffdd;
|
63
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
/*
|
2
|
+
A grey based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
3
|
+
|
4
|
+
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
5
|
+
|
6
|
+
Colors:
|
7
|
+
dk: 787888
|
8
|
+
lt: 4f4f5b
|
9
|
+
lter: a8a8a8
|
10
|
+
white: ffffff
|
11
|
+
*/
|
12
|
+
|
13
|
+
/* TODO */
|
14
|
+
|
15
|
+
.calendar {
|
16
|
+
margin: auto;
|
17
|
+
color: white;
|
18
|
+
text-align: center;
|
19
|
+
}
|
20
|
+
|
21
|
+
.monthName th {
|
22
|
+
font-weight: normal;
|
23
|
+
text-align: right;
|
24
|
+
padding-top: 1em;
|
25
|
+
padding-bottom: 0.7em;
|
26
|
+
color: black;
|
27
|
+
}
|
28
|
+
|
29
|
+
.dayName th {
|
30
|
+
font-size: 0.7em;
|
31
|
+
padding-top: 0.6em;
|
32
|
+
padding-bottom: 0.3em;
|
33
|
+
background-color: #303030;
|
34
|
+
color: white;
|
35
|
+
border-bottom: 1px solid white;
|
36
|
+
}
|
37
|
+
|
38
|
+
.otherMonth, .day, .specialDay {
|
39
|
+
padding: 0.7em 1em;
|
40
|
+
border-right: 1px solid #111111;
|
41
|
+
}
|
42
|
+
|
43
|
+
.otherMonth {
|
44
|
+
color: #999999;
|
45
|
+
background-color: #4f4f5b;
|
46
|
+
}
|
47
|
+
|
48
|
+
.day, .specialDay {
|
49
|
+
border-bottom: 1px solid #111111;
|
50
|
+
background-color: #333333;
|
51
|
+
}
|
52
|
+
.specialDay {
|
53
|
+
background-color: #a8a8a8;
|
54
|
+
color: black;
|
55
|
+
}
|
56
|
+
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
57
|
+
color: white;
|
58
|
+
text-decoration: none;
|
59
|
+
padding: 1em;
|
60
|
+
}
|
61
|
+
.specialDay a:hover {
|
62
|
+
color: white;
|
63
|
+
background-color: black;
|
64
|
+
}
|
65
|
+
.weekendDay {
|
66
|
+
background-color: #787888;
|
67
|
+
}
|
68
|
+
|
69
|
+
Colors:
|
70
|
+
dk: 787888
|
71
|
+
lt: 4f4f5b
|
72
|
+
lter: a8a8a8
|
73
|
+
white: ffffff
|
74
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/*
|
2
|
+
A red, white, and grey theme.
|
3
|
+
|
4
|
+
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
5
|
+
*/
|
6
|
+
|
7
|
+
.calendar {
|
8
|
+
margin: auto;
|
9
|
+
}
|
10
|
+
|
11
|
+
.monthName th {
|
12
|
+
font-weight: normal;
|
13
|
+
text-align: right;
|
14
|
+
padding-top: 1em;
|
15
|
+
padding-bottom: 0.7em;
|
16
|
+
}
|
17
|
+
|
18
|
+
.dayName th {
|
19
|
+
font-size: 0.7em;
|
20
|
+
padding-top: 0.6em;
|
21
|
+
padding-bottom: 0.3em;
|
22
|
+
background-color: #303030;
|
23
|
+
color: white;
|
24
|
+
}
|
25
|
+
|
26
|
+
.otherMonth, .day, .specialDay {
|
27
|
+
padding: 0.7em 1em;
|
28
|
+
border-right: 1px solid white;
|
29
|
+
|
30
|
+
}
|
31
|
+
|
32
|
+
.otherMonth {
|
33
|
+
color: #eeeeee;
|
34
|
+
}
|
35
|
+
.weekendDay {
|
36
|
+
background-color: #eeeeee;
|
37
|
+
}
|
38
|
+
|
39
|
+
.day, .specialDay {
|
40
|
+
text-align: center;
|
41
|
+
border-bottom: 1px dotted #bbbbbb;
|
42
|
+
}
|
43
|
+
|
44
|
+
.specialDay {
|
45
|
+
background-color: #d10a21;
|
46
|
+
color: white;
|
47
|
+
}
|
48
|
+
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
49
|
+
color: white;
|
50
|
+
text-decoration: none;
|
51
|
+
padding: 1em;
|
52
|
+
}
|
53
|
+
.specialDay a:hover {
|
54
|
+
color: white;
|
55
|
+
background-color: black;
|
56
|
+
}
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ActionView::Base.send :include, CalendarHelper
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
# CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting
|
4
|
+
module CalendarHelper
|
5
|
+
|
6
|
+
VERSION = '0.2.0'
|
7
|
+
|
8
|
+
# Returns an HTML calendar. In its simplest form, this method generates a plain
|
9
|
+
# calendar (which can then be customized using CSS) for a given month and year.
|
10
|
+
# However, this may be customized in a variety of ways -- changing the default CSS
|
11
|
+
# classes, generating the individual day entries yourself, and so on.
|
12
|
+
#
|
13
|
+
# The following options are required:
|
14
|
+
# :year # The year number to show the calendar for.
|
15
|
+
# :month # The month number to show the calendar for.
|
16
|
+
#
|
17
|
+
# The following are optional, available for customizing the default behaviour:
|
18
|
+
# :table_class => "calendar" # The class for the <table> tag.
|
19
|
+
# :month_name_class => "monthName" # The class for the name of the month, at the top of the table.
|
20
|
+
# :other_month_class => "otherMonth" # Not implemented yet.
|
21
|
+
# :day_name_class => "dayName" # The class is for the names of the weekdays, at the top.
|
22
|
+
# :day_class => "day" # The class for the individual day number cells.
|
23
|
+
# This may or may not be used if you specify a block (see below).
|
24
|
+
# :abbrev => (0..2) # This option specifies how the day names should be abbreviated.
|
25
|
+
# Use (0..2) for the first three letters, (0..0) for the first, and
|
26
|
+
# (0..-1) for the entire name.
|
27
|
+
# :first_day_of_week => 0 # Renders calendar starting on Sunday. Use 1 for Monday, and so on.
|
28
|
+
#
|
29
|
+
# For more customization, you can pass a code block to this method, that will get one argument, a Date object,
|
30
|
+
# and return a values for the individual table cells. The block can return an array, [cell_text, cell_attrs],
|
31
|
+
# cell_text being the text that is displayed and cell_attrs a hash containing the attributes for the <td> tag
|
32
|
+
# (this can be used to change the <td>'s class for customization with CSS).
|
33
|
+
# This block can also return the cell_text only, in which case the <td>'s class defaults to the value given in
|
34
|
+
# +:day_class+. If the block returns nil, the default options are used.
|
35
|
+
#
|
36
|
+
# Example usage:
|
37
|
+
# calendar(:year => 2005, :month => 6) # This generates the simplest possible calendar.
|
38
|
+
# calendar({:year => 2005, :month => 6, :table_class => "calendar_helper"}) # This generates a calendar, as
|
39
|
+
# # before, but the <table>'s class
|
40
|
+
# # is set to "calendar_helper".
|
41
|
+
# calendar(:year => 2005, :month => 6, :abbrev => (0..-1)) # This generates a simple calendar but shows the
|
42
|
+
# # entire day name ("Sunday", "Monday", etc.) instead
|
43
|
+
# # of only the first three letters.
|
44
|
+
# calendar(:year => 2005, :month => 5) do |d| # This generates a simple calendar, but gives special days
|
45
|
+
# if listOfSpecialDays.include?(d) # (days that are in the array listOfSpecialDays) one CSS class,
|
46
|
+
# [d.mday, {:class => "specialDay"}] # "specialDay", and gives the rest of the days another CSS class,
|
47
|
+
# else # "normalDay". You can also use this highlight today differently
|
48
|
+
# [d.mday, {:class => "normalDay"}] # from the rest of the days, etc.
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# An additional 'weekend' class is applied to weekend days.
|
53
|
+
#
|
54
|
+
# For consistency with the themes provided in the calendar_styles generator, use "specialDay" as the CSS class for marked days.
|
55
|
+
#
|
56
|
+
def calendar(options = {}, &block)
|
57
|
+
raise(ArgumentError, "No year given") unless options.has_key?(:year)
|
58
|
+
raise(ArgumentError, "No month given") unless options.has_key?(:month)
|
59
|
+
|
60
|
+
block ||= Proc.new {|d| nil}
|
61
|
+
|
62
|
+
defaults = {
|
63
|
+
:table_class => 'calendar',
|
64
|
+
:month_name_class => 'monthName',
|
65
|
+
:other_month_class => 'otherMonth',
|
66
|
+
:day_name_class => 'dayName',
|
67
|
+
:day_class => 'day',
|
68
|
+
:abbrev => (0..2),
|
69
|
+
:first_day_of_week => 0
|
70
|
+
}
|
71
|
+
options = defaults.merge options
|
72
|
+
|
73
|
+
first = Date.civil(options[:year], options[:month], 1)
|
74
|
+
last = Date.civil(options[:year], options[:month], -1)
|
75
|
+
|
76
|
+
first_weekday = first_day_of_week(options[:first_day_of_week])
|
77
|
+
last_weekday = last_day_of_week(options[:first_day_of_week])
|
78
|
+
|
79
|
+
day_names = Date::DAYNAMES.dup
|
80
|
+
first_weekday.times do
|
81
|
+
day_names.push(day_names.shift)
|
82
|
+
end
|
83
|
+
|
84
|
+
cal = %(<table class="#{options[:table_class]}" border="0" cellspacing="0" cellpadding="0">)
|
85
|
+
cal << %(<thead><tr class="#{options[:month_name_class]}"><th colspan="7">#{Date::MONTHNAMES[options[:month]]}</th></tr><tr class="#{options[:day_name_class]}">)
|
86
|
+
day_names.each {|d| cal << "<th>#{d[options[:abbrev]]}</th>"}
|
87
|
+
cal << "</tr></thead><tbody><tr>"
|
88
|
+
beginning_of_week(first, first_weekday).upto(first - 1) do |d|
|
89
|
+
cal << %(<td class="#{options[:other_month_class]})
|
90
|
+
cal << " weekendDay" if weekend?(d)
|
91
|
+
cal << %(">#{d.day}</td>)
|
92
|
+
end unless first.wday == first_weekday
|
93
|
+
first.upto(last) do |cur|
|
94
|
+
cell_text, cell_attrs = block.call(cur)
|
95
|
+
cell_text ||= cur.mday
|
96
|
+
cell_attrs ||= {:class => options[:day_class]}
|
97
|
+
cell_attrs[:class] += " weekendDay" if [0, 6].include?(cur.wday)
|
98
|
+
cell_attrs = cell_attrs.map {|k, v| %(#{k}="#{v}") }.join(" ")
|
99
|
+
cal << "<td #{cell_attrs}>#{cell_text}</td>"
|
100
|
+
cal << "</tr><tr>" if cur.wday == last_weekday
|
101
|
+
end
|
102
|
+
(last + 1).upto(beginning_of_week(last + 7, first_weekday) - 1) do |d|
|
103
|
+
cal << %(<td class="#{options[:other_month_class]})
|
104
|
+
cal << " weekendDay" if weekend?(d)
|
105
|
+
cal << %(">#{d.day}</td>)
|
106
|
+
end unless last.wday == last_weekday
|
107
|
+
cal << "</tr></tbody></table>"
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def first_day_of_week(day)
|
113
|
+
day
|
114
|
+
end
|
115
|
+
|
116
|
+
def last_day_of_week(day)
|
117
|
+
if day > 0
|
118
|
+
day - 1
|
119
|
+
else
|
120
|
+
6
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def days_between(first, second)
|
125
|
+
if first > second
|
126
|
+
second + (7 - first)
|
127
|
+
else
|
128
|
+
second - first
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def beginning_of_week(date, start = 1)
|
133
|
+
days_to_beg = days_between(start, date.wday)
|
134
|
+
date - days_to_beg
|
135
|
+
end
|
136
|
+
|
137
|
+
def weekend?(date)
|
138
|
+
[0, 6].include?(date.wday)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Stylesheet Tester</title>
|
4
|
+
<link href="../generators/calendar_styles/templates/grey/style.css" media="screen" rel="Stylesheet" type="text/css" />
|
5
|
+
<style>
|
6
|
+
body, tr, td {
|
7
|
+
font-family: Verdana;
|
8
|
+
}
|
9
|
+
</style>
|
10
|
+
</head>
|
11
|
+
<body style="background-color: #eeeeee">
|
12
|
+
|
13
|
+
<table class="calendar" border="0" cellspacing="0" cellpadding="0">
|
14
|
+
<thead>
|
15
|
+
<tr class="monthName">
|
16
|
+
<th colspan="7">April</th>
|
17
|
+
</tr>
|
18
|
+
<tr class="dayName">
|
19
|
+
<th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> <th>Sun</th> </tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<tr> <td class="otherMonth">27</td> <td class="otherMonth">28</td> <td class="otherMonth">29</td> <td class="otherMonth">30</td> <td class="otherMonth">31</td> <td class="day weekendDay">1</td> <td class="day weekendDay">2</td> </tr>
|
23
|
+
<tr> <td class="day">3</td> <td class="day">4</td> <td class="day">5</td> <td class="day">6</td> <td class="day">7</td> <td class="day weekendDay">8</td> <td class="day weekendDay">9</td> </tr>
|
24
|
+
<tr> <td class="day">10</td> <td class="day">11</td> <td class="day">12</td> <td class="day">13</td> <td class="day">14</td> <td class="day weekendDay">15</td> <td class="day weekendDay">16</td> </tr>
|
25
|
+
<tr> <td class="day">17</td> <td class="day">18</td> <td class="day">19</td> <td class="day">20</td> <td class="day">21</td> <td class="day weekendDay">22</td> <td class="day weekendDay">23</td> </tr>
|
26
|
+
<tr> <td class="day">24</td> <td class="day">25</td> <td class="day">26</td> <td class="specialDay">27</td> <td class="day">28</td> <td class="day weekendDay">29</td> <td class="day weekendDay">30</td> </tr>
|
27
|
+
<tr> </tr>
|
28
|
+
</tbody>
|
29
|
+
</table>
|
30
|
+
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/calendar_helper")
|
3
|
+
|
4
|
+
class CalendarHelperTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include CalendarHelper
|
7
|
+
|
8
|
+
|
9
|
+
def test_simple
|
10
|
+
assert_match %r{August}, calendar_with_defaults
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_required_fields
|
15
|
+
# Year and month are required
|
16
|
+
assert_raises(ArgumentError) {
|
17
|
+
calendar
|
18
|
+
}
|
19
|
+
assert_raises(ArgumentError) {
|
20
|
+
calendar :year => 1
|
21
|
+
}
|
22
|
+
assert_raises(ArgumentError) {
|
23
|
+
calendar :month => 1
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_default_css_classes
|
28
|
+
# :other_month_class is not implemented yet
|
29
|
+
{ :table_class => "calendar",
|
30
|
+
:month_name_class => "monthName",
|
31
|
+
:day_name_class => "dayName",
|
32
|
+
:day_class => "day" }.each do |key, value|
|
33
|
+
assert_correct_css_class_for_default value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_custom_css_classes
|
39
|
+
# Uses the key name as the CSS class name
|
40
|
+
# :other_month_class is not implemented yet
|
41
|
+
[:table_class, :month_name_class, :day_name_class, :day_class].each do |key|
|
42
|
+
assert_correct_css_class_for_key key.to_s, key
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def test_abbrev
|
48
|
+
assert_match %r{>Mon<}, calendar_with_defaults(:abbrev => (0..2))
|
49
|
+
assert_match %r{>M<}, calendar_with_defaults(:abbrev => (0..0))
|
50
|
+
assert_match %r{>Monday<}, calendar_with_defaults(:abbrev => (0..-1))
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_block
|
55
|
+
# Even days are special
|
56
|
+
assert_match %r{class="special_day">2<}, calendar(:year => 2006, :month => 8) { |d|
|
57
|
+
if d.mday % 2 == 0
|
58
|
+
[d.mday, {:class => 'special_day'}]
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_first_day_of_week
|
65
|
+
assert_match %r{<tr class="dayName">\s*<th>Sun}, calendar_with_defaults
|
66
|
+
assert_match %r{<tr class="dayName">\s*<th>Mon}, calendar_with_defaults(:first_day_of_week => 1)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
|
72
|
+
def assert_correct_css_class_for_key(css_class, key)
|
73
|
+
assert_match %r{class="#{css_class}"}, calendar_with_defaults(key => css_class)
|
74
|
+
end
|
75
|
+
|
76
|
+
def assert_correct_css_class_for_default(css_class)
|
77
|
+
assert_match %r{class="#{css_class}"}, calendar_with_defaults
|
78
|
+
end
|
79
|
+
|
80
|
+
def calendar_with_defaults(options={})
|
81
|
+
options = { :year => 2006, :month => 8 }.merge options
|
82
|
+
calendar options
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: calendar_helper
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-06-24 00:00:00 -07:00
|
8
|
+
summary: Generates a configurable, CSS-tagged HTML calendar.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: boss AT topfunky.com
|
12
|
+
homepage: http://rubyforge.org/projects/seattlerb
|
13
|
+
rubyforge_project: seattlerb
|
14
|
+
description: A simple method to create an HTML calendar for a single month. Can be styled with CSS. Usable with Ruby on Rails.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Geoffrey Grosenbach
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- MIT-LICENSE
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- generators/calendar_styles/calendar_styles_generator.rb
|
38
|
+
- generators/calendar_styles/templates/blue/style.css
|
39
|
+
- generators/calendar_styles/templates/grey/style.css
|
40
|
+
- generators/calendar_styles/templates/red/style.css
|
41
|
+
- init.rb
|
42
|
+
- lib/calendar_helper.rb
|
43
|
+
- test/stylesheet_tester.html
|
44
|
+
- test/test_calendar_helper.rb
|
45
|
+
test_files:
|
46
|
+
- test/test_calendar_helper.rb
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
extra_rdoc_files:
|
51
|
+
- History.txt
|
52
|
+
- Manifest.txt
|
53
|
+
- README.txt
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
dependencies:
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: hoe
|
63
|
+
version_requirement:
|
64
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.1
|
69
|
+
version:
|