calendar_helper 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/README.txt +46 -12
- data/Rakefile +17 -10
- data/generators/calendar_styles/templates/grey/style.css +4 -0
- data/lib/calendar_helper.rb +32 -7
- data/test/test_calendar_helper.rb +12 -3
- metadata +88 -44
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 2.2.3 / 2010-05-21
|
2
|
+
|
3
|
+
* Don't crash if time zone is nil
|
4
|
+
* Upgrade to latest Hoe
|
5
|
+
* Added support to remove the month row on the table
|
6
|
+
* Fixed bug where passed ID for day cell would throw error on missing class name.
|
7
|
+
|
1
8
|
=== 0.2.2 / 2007-08-29
|
2
9
|
|
3
10
|
* Fixed missing tr tag in thead section. [Ian Struble]
|
data/README.txt
CHANGED
@@ -1,27 +1,61 @@
|
|
1
|
-
CalendarHelper
|
2
|
-
==============
|
1
|
+
= CalendarHelper
|
3
2
|
|
4
|
-
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
A simple helper for creating an HTML calendar. The "calendar" method will be automatically available to your Rails view templates, or can be used with Sinatra or other webapps.
|
5
6
|
|
6
7
|
There is also a Rails generator that copies some stylesheets for use alone or alongside existing stylesheets.
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
# Simple
|
12
|
+
calendar(:year => 2005, :month => 6)
|
13
|
+
|
14
|
+
# Set table class
|
15
|
+
calendar({:year => 2005, :month => 6, :table_class => "calendar_helper"})
|
16
|
+
|
17
|
+
# Full featured
|
18
|
+
calendar(:year => 2005, :month => 5) do |d| # This generates a simple calendar, but gives special days
|
19
|
+
if listOfSpecialDays.include?(d) # (days that are in the array listOfSpecialDays) one CSS class,
|
20
|
+
[d.mday, {:class => "specialDay"}] # "specialDay", and gives the rest of the days another CSS class,
|
21
|
+
else # "normalDay". You can also use this highlight today differently
|
22
|
+
[d.mday, {:class => "normalDay"}] # from the rest of the days, etc.
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
If using with ERb (Rails), put in a printing tag.
|
27
|
+
|
28
|
+
<%= calendar(:year => @year, :month => @month, :first_day_of_week => 1) do |d|
|
29
|
+
render_calendar_cell(d)
|
30
|
+
end
|
31
|
+
%>
|
32
|
+
|
33
|
+
With Haml, use a helper to set options for each cell.
|
34
|
+
|
35
|
+
= calendar(:year => @year, :month => @month, :first_day_of_week => 1) do |d|
|
36
|
+
- render_calendar_cell(d)
|
37
|
+
|
38
|
+
In Sinatra, include the CalendarHelper module in your helpers:
|
39
|
+
|
40
|
+
helpers do
|
41
|
+
include CalendarHelper
|
42
|
+
end
|
43
|
+
|
44
|
+
== AUTHORS:
|
10
45
|
|
11
46
|
Jeremy Voorhis -- http://jvoorhis.com
|
12
47
|
Original implementation
|
13
48
|
|
14
|
-
Jarkko Laine -- http://jlaine.net/
|
15
|
-
Dynamic enhancements for starting week on Monday and highlighting weekends
|
16
|
-
|
17
49
|
Geoffrey Grosenbach -- http://nubyonrails.com
|
18
50
|
Test suite and conversion to a Rails plugin
|
19
51
|
|
20
|
-
|
21
|
-
|
52
|
+
== Contributors:
|
53
|
+
|
54
|
+
* Jarkko Laine http://jlaine.net/
|
55
|
+
* Tom Armitage http://infovore.org
|
56
|
+
* Bryan Larsen http://larsen.st
|
22
57
|
|
23
|
-
|
24
|
-
=====
|
58
|
+
== USAGE:
|
25
59
|
|
26
60
|
See the RDoc (or use "rake rdoc").
|
27
61
|
|
data/Rakefile
CHANGED
@@ -4,17 +4,24 @@ require 'rake/rdoctask'
|
|
4
4
|
require 'hoe'
|
5
5
|
require './lib/calendar_helper.rb'
|
6
6
|
|
7
|
-
Hoe.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
p.url = "http://rubyforge.org/projects/seattlerb"
|
14
|
-
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
-
p.clean_globs = ['test/output']
|
7
|
+
Hoe.spec 'calendar_helper' do
|
8
|
+
developer('Geoffrey Grosenbach', 'boss@topfunky.com')
|
9
|
+
|
10
|
+
extra_deps << ['open4']
|
11
|
+
|
12
|
+
# self.rubyforge_name = 'osxscreenshotx' # if different than 'osxscreenshot'
|
16
13
|
end
|
17
14
|
|
15
|
+
|
16
|
+
# Hoe.new('calendar_helper', CalendarHelper::VERSION) do |p|
|
17
|
+
# p.rubyforge_name = 'seattlerb'
|
18
|
+
# p.summary = 'Generates a configurable, CSS-tagged HTML calendar.'
|
19
|
+
# p.description = "A simple method to create an HTML calendar for a single month. Can be styled with CSS. Usable with Ruby on Rails."
|
20
|
+
# p.url = "http://rubyforge.org/projects/seattlerb"
|
21
|
+
# p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
22
|
+
# p.clean_globs = ['test/output']
|
23
|
+
# end
|
24
|
+
|
18
25
|
# desc "Test task (actually runs specs)"
|
19
26
|
# task "test" do
|
20
27
|
# system "spec --format specdoc --color spec/*_spec.rb"
|
@@ -27,6 +34,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
27
34
|
rdoc.rdoc_dir = 'rdoc'
|
28
35
|
rdoc.title = 'CalendarHelper'
|
29
36
|
rdoc.options << '--line-numbers' << '--inline-source'
|
30
|
-
rdoc.rdoc_files.include('README')
|
37
|
+
rdoc.rdoc_files.include('README.txt')
|
31
38
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
32
39
|
end
|
data/lib/calendar_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'date'
|
|
3
3
|
# CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting
|
4
4
|
module CalendarHelper
|
5
5
|
|
6
|
-
VERSION = '0.2.
|
6
|
+
VERSION = '0.2.3'
|
7
7
|
|
8
8
|
# Returns an HTML calendar. In its simplest form, this method generates a plain
|
9
9
|
# calendar (which can then be customized using CSS) for a given month and year.
|
@@ -34,6 +34,9 @@ module CalendarHelper
|
|
34
34
|
#
|
35
35
|
# :show_today => false # Highlights today on the calendar using the CSS class 'today'.
|
36
36
|
# # Defaults to true.
|
37
|
+
# :previous_month_text => nil # Displayed left of the month name if set
|
38
|
+
# :next_month_text => nil # Displayed right of the month name if set
|
39
|
+
# :month_header => false # If you use false, the current month header will disappear.
|
37
40
|
#
|
38
41
|
# For more customization, you can pass a code block to this method, that will get one argument, a Date object,
|
39
42
|
# and return a values for the individual table cells. The block can return an array, [cell_text, cell_attrs],
|
@@ -77,7 +80,10 @@ module CalendarHelper
|
|
77
80
|
:abbrev => (0..2),
|
78
81
|
:first_day_of_week => 0,
|
79
82
|
:accessible => false,
|
80
|
-
:show_today => true
|
83
|
+
:show_today => true,
|
84
|
+
:previous_month_text => nil,
|
85
|
+
:next_month_text => nil,
|
86
|
+
:month_header => true
|
81
87
|
}
|
82
88
|
options = defaults.merge options
|
83
89
|
|
@@ -92,8 +98,25 @@ module CalendarHelper
|
|
92
98
|
day_names.push(day_names.shift)
|
93
99
|
end
|
94
100
|
|
95
|
-
|
96
|
-
cal
|
101
|
+
# TODO Use some kind of builder instead of straight HTML
|
102
|
+
cal = %(<table class="#{options[:table_class]}" border="0" cellspacing="0" cellpadding="0">)
|
103
|
+
cal << %(<thead>)
|
104
|
+
|
105
|
+
if (options[:month_header])
|
106
|
+
cal << %(<tr>)
|
107
|
+
if options[:previous_month_text] or options[:next_month_text]
|
108
|
+
cal << %(<th colspan="2">#{options[:previous_month_text]}</th>)
|
109
|
+
colspan=3
|
110
|
+
else
|
111
|
+
colspan=7
|
112
|
+
end
|
113
|
+
cal << %(<th colspan="#{colspan}" class="#{options[:month_name_class]}">#{Date::MONTHNAMES[options[:month]]}</th>)
|
114
|
+
cal << %(<th colspan="2">#{options[:next_month_text]}</th>) if options[:next_month_text]
|
115
|
+
cal << %(</tr>)
|
116
|
+
end
|
117
|
+
|
118
|
+
cal << %(<tr class="#{options[:day_name_class]}">)
|
119
|
+
|
97
120
|
day_names.each do |d|
|
98
121
|
unless d[options[:abbrev]].eql? d
|
99
122
|
cal << "<th scope='col'><abbr title='#{d}'>#{d[options[:abbrev]]}</abbr></th>"
|
@@ -114,9 +137,11 @@ module CalendarHelper
|
|
114
137
|
first.upto(last) do |cur|
|
115
138
|
cell_text, cell_attrs = block.call(cur)
|
116
139
|
cell_text ||= cur.mday
|
117
|
-
cell_attrs ||= {
|
118
|
-
cell_attrs[:class]
|
119
|
-
cell_attrs[:class] += "
|
140
|
+
cell_attrs ||= {}
|
141
|
+
cell_attrs[:class] ||= options[:day_class]
|
142
|
+
cell_attrs[:class] += " weekendDay" if [0, 6].include?(cur.wday)
|
143
|
+
today = (Time.respond_to?(:zone) && !(zone = Time.zone).nil? ? zone.now.to_date : Date.today)
|
144
|
+
cell_attrs[:class] += " today" if (cur == today) and options[:show_today]
|
120
145
|
cell_attrs = cell_attrs.map {|k, v| %(#{k}="#{v}") }.join(" ")
|
121
146
|
cal << "<td #{cell_attrs}>#{cell_text}</td>"
|
122
147
|
cal << "</tr><tr>" if cur.wday == last_weekday
|
@@ -14,11 +14,13 @@ class CalendarHelperTest < Test::Unit::TestCase
|
|
14
14
|
# include Inflector
|
15
15
|
# include ActionController::Assertions::SelectorAssertions
|
16
16
|
include CalendarHelper
|
17
|
-
|
17
|
+
|
18
18
|
|
19
19
|
def test_with_output
|
20
|
-
output =
|
21
|
-
|
20
|
+
output = []
|
21
|
+
%w(calendar_with_defaults calendar_for_this_month calendar_with_next_and_previous).each do |methodname|
|
22
|
+
output << "<h2>#{methodname}</h2>\n" + send(methodname.to_sym) + "\n\n"
|
23
|
+
end
|
22
24
|
write_sample "sample.html", output
|
23
25
|
end
|
24
26
|
|
@@ -118,6 +120,13 @@ class CalendarHelperTest < Test::Unit::TestCase
|
|
118
120
|
calendar options
|
119
121
|
end
|
120
122
|
|
123
|
+
def calendar_with_next_and_previous
|
124
|
+
calendar_for_this_month({
|
125
|
+
:previous_month_text => "PREVIOUS",
|
126
|
+
:next_month_text => "NEXT"
|
127
|
+
})
|
128
|
+
end
|
129
|
+
|
121
130
|
def write_sample(filename, content)
|
122
131
|
FileUtils.mkdir_p "test/output"
|
123
132
|
File.open("test/output/#{filename}", 'w') do |f|
|
metadata
CHANGED
@@ -1,33 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: calendar_helper
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-08-29 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:
|
4
|
+
version: 0.2.3
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Geoffrey Grosenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-05-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: open4
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rubyforge
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: gemcutter
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.3.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hoe
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.5.0
|
54
|
+
version:
|
55
|
+
description: |-
|
56
|
+
A simple helper for creating an HTML calendar. The "calendar" method will be automatically available to your Rails view templates, or can be used with Sinatra or other webapps.
|
57
|
+
|
58
|
+
There is also a Rails generator that copies some stylesheets for use alone or alongside existing stylesheets.
|
59
|
+
email:
|
60
|
+
- boss@topfunky.com
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions: []
|
64
|
+
|
65
|
+
extra_rdoc_files:
|
66
|
+
- History.txt
|
67
|
+
- Manifest.txt
|
68
|
+
- README.txt
|
31
69
|
files:
|
32
70
|
- History.txt
|
33
71
|
- MIT-LICENSE
|
@@ -41,28 +79,34 @@ files:
|
|
41
79
|
- init.rb
|
42
80
|
- lib/calendar_helper.rb
|
43
81
|
- test/test_calendar_helper.rb
|
44
|
-
|
45
|
-
|
82
|
+
has_rdoc: true
|
83
|
+
homepage:
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
46
87
|
rdoc_options:
|
47
88
|
- --main
|
48
89
|
- README.txt
|
49
|
-
|
50
|
-
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
57
104
|
requirements: []
|
58
105
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 1.3.0
|
68
|
-
version:
|
106
|
+
rubyforge_project: calendar_helper
|
107
|
+
rubygems_version: 1.3.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: A simple helper for creating an HTML calendar
|
111
|
+
test_files:
|
112
|
+
- test/test_calendar_helper.rb
|