olauzon-weekender 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -0
- data/Rakefile +56 -0
- data/lib/core_ext/date.rb +15 -0
- data/lib/core_ext/string.rb +15 -0
- data/lib/weekender.rb +9 -0
- data/lib/weekender/view_helpers.rb +76 -0
- data/lib/weekender/weekender.rb +154 -0
- data/spec/fixtures/weekender.html +38 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/weekender_spec.rb +281 -0
- metadata +64 -0
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= weekender
|
2
|
+
|
3
|
+
A simple Ruby library for creating calendars based on weeks rather than months.
|
4
|
+
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
$ sudo gem sources -a http://gems.github.com
|
9
|
+
$ sudo gem install olauzon-weekender
|
10
|
+
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
>> weekender = Weekender.new( :year => Date.today.year,
|
15
|
+
:month => Date.today.month,
|
16
|
+
:day => Date.today.day,
|
17
|
+
:before => 3, # number of weeks to display before
|
18
|
+
:after => 4) # number of weeks to display after
|
19
|
+
=> Returns a Weekender instance
|
20
|
+
|
21
|
+
>> weekender.add_event(Date.today,
|
22
|
+
:html_class => 'special_event',
|
23
|
+
:content => '<p>special event 1</p>')
|
24
|
+
=> Returns weekender with an event (you can add as many events as necessary)
|
25
|
+
|
26
|
+
>> weekender.display
|
27
|
+
=> Outputs HTML calendar
|
28
|
+
|
29
|
+
|
30
|
+
== Inspiration
|
31
|
+
|
32
|
+
* nakajima's Calendar Maker http://github.com/nakajima/calendar-maker
|
33
|
+
|
34
|
+
|
35
|
+
== Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2009 Olivier Lauzon. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "weekender"
|
8
|
+
gem.summary = %Q{A simple Ruby library for creating calendars based on weeks rather than months.}
|
9
|
+
gem.email = "olauzon@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/olauzon/weekender"
|
11
|
+
gem.authors = ["Olivier Lauzon"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'cucumber/rake/task'
|
33
|
+
Cucumber::Rake::Task.new(:features)
|
34
|
+
rescue LoadError
|
35
|
+
task :features do
|
36
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "weekender #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/lib/weekender.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module WeekenderHelpers
|
2
|
+
|
3
|
+
attr_reader :date_format,
|
4
|
+
:name_format
|
5
|
+
|
6
|
+
def display(options={})
|
7
|
+
@date_format = options[:date_format] || '%Y-%m-%d'
|
8
|
+
@name_format = options[:name_format] || :long
|
9
|
+
output = '<table class="weekender">'
|
10
|
+
output.add header_row
|
11
|
+
output.add week_rows(:reverse => (options[:reverse] || false))
|
12
|
+
output.add '</table>'
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def header_row
|
18
|
+
output = '<tr class="weekender_header">'.tab(2)
|
19
|
+
Weekender::DAY_NAMES.each do |day_name|
|
20
|
+
output.add ['<th>', abbreviate(day_name), '</th>'].join.tab(4)
|
21
|
+
end
|
22
|
+
output.add '</tr>'.tab(2)
|
23
|
+
end
|
24
|
+
|
25
|
+
def week_rows(options={})
|
26
|
+
output = ''
|
27
|
+
if options[:reverse] && options[:reverse] == true
|
28
|
+
weeks.downto(1) do |week|
|
29
|
+
if week == weeks
|
30
|
+
output = '<tr>'.tab(2)
|
31
|
+
else
|
32
|
+
output.add '<tr>'.tab(2)
|
33
|
+
end
|
34
|
+
1.upto(7) do |day|
|
35
|
+
output.add day_cell(week, day)
|
36
|
+
end
|
37
|
+
output.add '</tr>'.tab(2)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
1.upto(weeks) do |week|
|
41
|
+
if week == 1
|
42
|
+
output = '<tr>'.tab(2)
|
43
|
+
else
|
44
|
+
output.add '<tr>'.tab(2)
|
45
|
+
end
|
46
|
+
1.upto(7) do |day|
|
47
|
+
output.add day_cell(week, day)
|
48
|
+
end
|
49
|
+
output.add '</tr>'.tab(2)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
output
|
53
|
+
end
|
54
|
+
|
55
|
+
def day_cell(week, day)
|
56
|
+
date = date_on(week, day)
|
57
|
+
output = '<td>'
|
58
|
+
output << '<a href="#" class="weekender_date">'
|
59
|
+
output << date.strftime(date_format)
|
60
|
+
output << '</a>'
|
61
|
+
output << content_on(date.to_s)
|
62
|
+
output << '</td>'
|
63
|
+
output.tab(4)
|
64
|
+
end
|
65
|
+
|
66
|
+
def abbreviate(day_name)
|
67
|
+
if name_format == :medium
|
68
|
+
day_name[0..2]
|
69
|
+
elsif name_format == :short
|
70
|
+
day_name[0..0]
|
71
|
+
else
|
72
|
+
day_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
class Weekender
|
2
|
+
|
3
|
+
include WeekenderHelpers
|
4
|
+
|
5
|
+
DAY_NAMES = [ 'Monday',
|
6
|
+
'Tuesday',
|
7
|
+
'Wednesday',
|
8
|
+
'Thursday',
|
9
|
+
'Friday',
|
10
|
+
'Saturday',
|
11
|
+
'Sunday' ]
|
12
|
+
|
13
|
+
attr_accessor :year,
|
14
|
+
:month,
|
15
|
+
:day,
|
16
|
+
:year_end,
|
17
|
+
:month_end,
|
18
|
+
:day_end,
|
19
|
+
:before,
|
20
|
+
:after,
|
21
|
+
:events
|
22
|
+
|
23
|
+
def initialize(options={})
|
24
|
+
@year = options[:year] || Date.today.year
|
25
|
+
@month = options[:month] || Date.today.month
|
26
|
+
@day = options[:day] || Date.today.day
|
27
|
+
@year_end = options[:year_end] || year
|
28
|
+
@month_end = options[:month_end] || month
|
29
|
+
@day_end = options[:day_end] || day
|
30
|
+
@before = options[:before] || 0
|
31
|
+
@after = options[:after] || 0
|
32
|
+
@events = options[:events] || []
|
33
|
+
end
|
34
|
+
|
35
|
+
def weeks
|
36
|
+
before + span + after
|
37
|
+
end
|
38
|
+
|
39
|
+
def span
|
40
|
+
((spans_to - spans_from).to_i + 1) / 7
|
41
|
+
end
|
42
|
+
|
43
|
+
def spans_from
|
44
|
+
Date.commercial(date.cwyear, date.cweek, 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def starts_on
|
48
|
+
Date.commercial(start_week.cwyear, start_week.cweek, 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ends_on
|
52
|
+
Date.commercial(end_week.cwyear, end_week.cweek, 7)
|
53
|
+
end
|
54
|
+
|
55
|
+
def spans_to
|
56
|
+
Date.commercial(end_date.cwyear, end_date.cweek, 7)
|
57
|
+
end
|
58
|
+
|
59
|
+
def date_on(week, day)
|
60
|
+
Date.commercial(week_date(week).cwyear, week_date(week).cweek, day)
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_event(date, options={})
|
64
|
+
@events << [date, options]
|
65
|
+
end
|
66
|
+
|
67
|
+
def event_on?(date)
|
68
|
+
if events.empty?
|
69
|
+
false
|
70
|
+
else
|
71
|
+
events_dates.include?(date)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def events_dates
|
76
|
+
events.map { |event| event[0] }
|
77
|
+
end
|
78
|
+
|
79
|
+
def events_on(date)
|
80
|
+
if event_on?(date)
|
81
|
+
events.select { |event| event[0] == date }
|
82
|
+
else
|
83
|
+
[]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def content_on(date)
|
88
|
+
content = ''
|
89
|
+
events_on(date).each do |event|
|
90
|
+
content << event[1][:content]
|
91
|
+
end
|
92
|
+
content
|
93
|
+
end
|
94
|
+
|
95
|
+
def html_classes_on(date)
|
96
|
+
classes = ''
|
97
|
+
events_on(date).each do |event|
|
98
|
+
classes << ' ' unless classes == ''
|
99
|
+
classes << event[1][:html_class]
|
100
|
+
end
|
101
|
+
classes
|
102
|
+
end
|
103
|
+
|
104
|
+
def previous
|
105
|
+
Weekender.new(
|
106
|
+
:year => previous_date.year,
|
107
|
+
:month => previous_date.month,
|
108
|
+
:day => previous_date.day,
|
109
|
+
:before => before,
|
110
|
+
:after => after
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def next
|
115
|
+
Weekender.new(
|
116
|
+
:year => next_date.year,
|
117
|
+
:month => next_date.month,
|
118
|
+
:day => next_date.day,
|
119
|
+
:before => before,
|
120
|
+
:after => after
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
# private
|
125
|
+
|
126
|
+
def date
|
127
|
+
Date.new(year, month, day)
|
128
|
+
end
|
129
|
+
|
130
|
+
def end_date
|
131
|
+
Date.new(year_end, month_end, day_end)
|
132
|
+
end
|
133
|
+
|
134
|
+
def start_week
|
135
|
+
date - (before * 7)
|
136
|
+
end
|
137
|
+
|
138
|
+
def end_week
|
139
|
+
end_date + (after * 7)
|
140
|
+
end
|
141
|
+
|
142
|
+
def week_date(week)
|
143
|
+
start_week + ((week - 1) * 7)
|
144
|
+
end
|
145
|
+
|
146
|
+
def previous_date
|
147
|
+
starts_on - 1 - (after * 7)
|
148
|
+
end
|
149
|
+
|
150
|
+
def next_date
|
151
|
+
ends_on + 1 + (before * 7)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<table class="weekender">
|
2
|
+
<tr class="weekender_header">
|
3
|
+
<th>Monday</th>
|
4
|
+
<th>Tuesday</th>
|
5
|
+
<th>Wednesday</th>
|
6
|
+
<th>Thursday</th>
|
7
|
+
<th>Friday</th>
|
8
|
+
<th>Saturday</th>
|
9
|
+
<th>Sunday</th>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td><a href="#" class="weekender_date">2009-04-20</a></td>
|
13
|
+
<td><a href="#" class="weekender_date">2009-04-21</a></td>
|
14
|
+
<td><a href="#" class="weekender_date">2009-04-22</a></td>
|
15
|
+
<td><a href="#" class="weekender_date">2009-04-23</a></td>
|
16
|
+
<td><a href="#" class="weekender_date">2009-04-24</a></td>
|
17
|
+
<td><a href="#" class="weekender_date">2009-04-25</a></td>
|
18
|
+
<td><a href="#" class="weekender_date">2009-04-26</a></td>
|
19
|
+
</tr>
|
20
|
+
<tr>
|
21
|
+
<td><a href="#" class="weekender_date">2009-04-27</a></td>
|
22
|
+
<td><a href="#" class="weekender_date">2009-04-28</a></td>
|
23
|
+
<td><a href="#" class="weekender_date">2009-04-29</a></td>
|
24
|
+
<td><a href="#" class="weekender_date">2009-04-30</a></td>
|
25
|
+
<td><a href="#" class="weekender_date">2009-05-01</a><p>This is an event</p></td>
|
26
|
+
<td><a href="#" class="weekender_date">2009-05-02</a><p>This is another event</p></td>
|
27
|
+
<td><a href="#" class="weekender_date">2009-05-03</a></td>
|
28
|
+
</tr>
|
29
|
+
<tr>
|
30
|
+
<td><a href="#" class="weekender_date">2009-05-04</a></td>
|
31
|
+
<td><a href="#" class="weekender_date">2009-05-05</a></td>
|
32
|
+
<td><a href="#" class="weekender_date">2009-05-06</a></td>
|
33
|
+
<td><a href="#" class="weekender_date">2009-05-07</a></td>
|
34
|
+
<td><a href="#" class="weekender_date">2009-05-08</a></td>
|
35
|
+
<td><a href="#" class="weekender_date">2009-05-09</a></td>
|
36
|
+
<td><a href="#" class="weekender_date">2009-05-10</a></td>
|
37
|
+
</tr>
|
38
|
+
</table>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Weekender do
|
4
|
+
|
5
|
+
describe "defaults" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@weekender = Weekender.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be this year" do
|
12
|
+
@weekender.year.should eql(Date.today.year)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be this month" do
|
16
|
+
@weekender.month.should eql(Date.today.month)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be today" do
|
20
|
+
@weekender.day.should eql(Date.today.day)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have 0 weeks before" do
|
24
|
+
@weekender.before.should eql(0)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have 0 weeks after" do
|
28
|
+
@weekender.after.should eql(0)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have 1 week" do
|
32
|
+
@weekender.weeks.should eql(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should start on a Monday" do
|
36
|
+
@weekender.starts_on.day_name.should eql("Monday")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should end on a Sunday" do
|
40
|
+
@weekender.ends_on.day_name.should eql("Sunday")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have a date by week number and day number" do
|
44
|
+
@weekender.date_on(1, 1).should eql(@weekender.starts_on)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a date on end week and end day" do
|
48
|
+
@weekender.date_on(1, 7).should eql(@weekender.ends_on)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should start and end on the same date" do
|
52
|
+
@weekender.date.strftime('%Y-%m-%d').
|
53
|
+
should eql(@weekender.end_date.strftime('%Y-%m-%d'))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should start and end on the same week" do
|
57
|
+
@weekender.start_week.should eql(@weekender.end_week)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "with start date" do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@weekender = Weekender.new( :year => 1999,
|
66
|
+
:month => 12,
|
67
|
+
:day => 31,
|
68
|
+
:before => 3,
|
69
|
+
:after => 4)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be in 1999" do
|
73
|
+
@weekender.year.should eql(1999)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should start on a Monday" do
|
77
|
+
@weekender.starts_on.day_name.should eql("Monday")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should start in December" do
|
81
|
+
@weekender.starts_on.month_name.should eql('December')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should start on the 6th" do
|
85
|
+
@weekender.starts_on.day_of_month.should eql(6)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should start in 1999" do
|
89
|
+
@weekender.starts_on.year.should eql(1999)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should start on Monday, December 6th, 1999" do
|
93
|
+
@weekender.starts_on.should eql(Date.new(1999, 12, 6))
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should end on a Sunday" do
|
97
|
+
@weekender.ends_on.day_name.should eql("Sunday")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should end in January" do
|
101
|
+
@weekender.ends_on.month_name.should eql("January")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should end on the 29th" do
|
105
|
+
@weekender.ends_on.day_of_month.should eql(30)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should end in 2000" do
|
109
|
+
@weekender.ends_on.year.should eql(2000)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "with start and end date" do
|
115
|
+
|
116
|
+
before(:each) do
|
117
|
+
@weekender = Weekender.new( :year => 2009,
|
118
|
+
:month => 5,
|
119
|
+
:day => 1,
|
120
|
+
:year_end => 2009,
|
121
|
+
:month_end => 5,
|
122
|
+
:day_end => 15,
|
123
|
+
:before => 0,
|
124
|
+
:after => 0)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should start on Monday, April 27th, 2009" do
|
128
|
+
@weekender.starts_on.should eql(Date.new(2009, 4, 27))
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should end on a Sunday, May 17th, 2009" do
|
132
|
+
@weekender.ends_on.should eql(Date.new(2009, 5, 17))
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should have 3 weeks" do
|
136
|
+
@weekender.weeks.should eql(3)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'events' do
|
142
|
+
|
143
|
+
it 'should be an array of events' do
|
144
|
+
Weekender.new.events.should be_a_kind_of(Array)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should be initialized as empty by default' do
|
148
|
+
Weekender.new.events.should be_empty
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'adding' do
|
152
|
+
|
153
|
+
before(:each) do
|
154
|
+
@weekender = Weekender.new
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not be an eventful day by default" do
|
158
|
+
@weekender.event_on?(Date.today).should be_false
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should add events to the specified day' do
|
162
|
+
@weekender.add_event(Date.today - 1)
|
163
|
+
@weekender.event_on?(Date.today - 1).should be_true
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'adding with content' do
|
169
|
+
|
170
|
+
before(:each) do
|
171
|
+
@weekender = Weekender.new
|
172
|
+
|
173
|
+
@weekender.add_event(Date.today - 1,
|
174
|
+
:html_class => 'first',
|
175
|
+
:content => '<p>special content 1</p>')
|
176
|
+
|
177
|
+
@weekender.add_event(Date.today - 1,
|
178
|
+
:html_class => 'second',
|
179
|
+
:content => '<p>special content 2</p>')
|
180
|
+
|
181
|
+
@weekender.add_event(Date.today - 2,
|
182
|
+
:html_class => 'third',
|
183
|
+
:content => 'special content 3')
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should have two events yesterday" do
|
187
|
+
@weekender.events_on(Date.today - 1).length.should eql(2)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should store the content" do
|
191
|
+
@weekender.content_on(Date.today - 1).
|
192
|
+
should eql('<p>special content 1</p><p>special content 2</p>')
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should store the HTML class" do
|
196
|
+
@weekender.html_classes_on(Date.today - 1).
|
197
|
+
should eql('first second')
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "day names" do
|
205
|
+
|
206
|
+
it "should be Monday through Sunday" do
|
207
|
+
Weekender::DAY_NAMES.should eql(
|
208
|
+
[ 'Monday',
|
209
|
+
'Tuesday',
|
210
|
+
'Wednesday',
|
211
|
+
'Thursday',
|
212
|
+
'Friday',
|
213
|
+
'Saturday',
|
214
|
+
'Sunday' ]
|
215
|
+
)
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "previous and next" do
|
221
|
+
|
222
|
+
describe "defaults" do
|
223
|
+
|
224
|
+
it "should have previous" do
|
225
|
+
Weekender.new.previous.should be
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should have next" do
|
229
|
+
Weekender.new.next.should be
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "with weekender" do
|
235
|
+
|
236
|
+
before(:each) do
|
237
|
+
@weekender = Weekender.new(:year => 2009,
|
238
|
+
:month => 5,
|
239
|
+
:day => 1,
|
240
|
+
:before => 1,
|
241
|
+
:after => 1)
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should return the previous weekender" do
|
245
|
+
@weekender.previous.month.should eql(4)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should return the next weekender" do
|
249
|
+
@weekender.next.month.should eql(5)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
describe 'generate HTML' do
|
257
|
+
|
258
|
+
describe 'for default' do
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
@weekender = Weekender.new(:year => 2009,
|
262
|
+
:month => 5,
|
263
|
+
:day => 1,
|
264
|
+
:before => 1,
|
265
|
+
:after => 1)
|
266
|
+
@weekender.add_event("2009-05-01",
|
267
|
+
:content => "<p>This is an event</p>")
|
268
|
+
@weekender.add_event("2009-05-02",
|
269
|
+
:content => "<p>This is another event</p>")
|
270
|
+
@default_table = File.read('spec/fixtures/weekender.html').chomp
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should display an HTML calendar' do
|
274
|
+
@weekender.display.should == @default_table
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: olauzon-weekender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Olivier Lauzon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: olauzon@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/core_ext/date.rb
|
28
|
+
- lib/core_ext/string.rb
|
29
|
+
- lib/weekender.rb
|
30
|
+
- lib/weekender/view_helpers.rb
|
31
|
+
- lib/weekender/weekender.rb
|
32
|
+
- spec/fixtures/weekender.html
|
33
|
+
- spec/spec_helper.rb
|
34
|
+
- spec/weekender_spec.rb
|
35
|
+
has_rdoc: false
|
36
|
+
homepage: http://github.com/olauzon/weekender
|
37
|
+
licenses:
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A simple Ruby library for creating calendars based on weeks rather than months.
|
62
|
+
test_files:
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/weekender_spec.rb
|