parent
9a22c8eaf5
commit
8058096f7e
@ -1,20 +0,0 @@
|
|||||||
Copyright (c) 2006 Jeremy Voorhis and Geoffrey Grosenbach
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,30 +0,0 @@
|
|||||||
CalendarHelper
|
|
||||||
==============
|
|
||||||
|
|
||||||
A simple helper for creating an HTML calendar. The "calendar" method will be automatically available to your view templates.
|
|
||||||
|
|
||||||
There is also a Rails generator that copies some stylesheets for use alone or alongside existing stylesheets.
|
|
||||||
|
|
||||||
Authors
|
|
||||||
=======
|
|
||||||
|
|
||||||
Jeremy Voorhis -- http://jvoorhis.com
|
|
||||||
Original implementation
|
|
||||||
|
|
||||||
Jarkko Laine -- http://jlaine.net/
|
|
||||||
Dynamic enhancements for starting week on Monday and highlighting weekends
|
|
||||||
|
|
||||||
Geoffrey Grosenbach -- http://nubyonrails.com
|
|
||||||
Test suite and conversion to a Rails plugin
|
|
||||||
|
|
||||||
Usage
|
|
||||||
=====
|
|
||||||
|
|
||||||
See the RDoc (or use "rake rdoc").
|
|
||||||
|
|
||||||
To copy the CSS files, use
|
|
||||||
|
|
||||||
./script/generate calendar_styles
|
|
||||||
|
|
||||||
CSS will be copied to subdirectories of public/stylesheets/calendar.
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
require 'rake'
|
|
||||||
require 'rake/testtask'
|
|
||||||
require 'rake/rdoctask'
|
|
||||||
|
|
||||||
desc 'Default: run unit tests.'
|
|
||||||
task :default => :test
|
|
||||||
|
|
||||||
desc 'Test the calendar_helper plugin.'
|
|
||||||
Rake::TestTask.new(:test) do |t|
|
|
||||||
t.libs << 'lib'
|
|
||||||
t.pattern = 'test/**/test_*.rb'
|
|
||||||
t.verbose = true
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Generate documentation for the calendar_helper plugin.'
|
|
||||||
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
||||||
rdoc.rdoc_dir = 'rdoc'
|
|
||||||
rdoc.title = 'CalendarHelper'
|
|
||||||
rdoc.options << '--line-numbers' << '--inline-source'
|
|
||||||
rdoc.rdoc_files.include('README')
|
|
||||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
||||||
end
|
|
@ -1,7 +0,0 @@
|
|||||||
author: topfunky
|
|
||||||
summary: Generates a table-based HTML calendar that can be styled with CSS. Also includes a generator with relevant stylesheets.
|
|
||||||
homepage: http://nubyonrails.com
|
|
||||||
plugin: http://topfunky.net/svn/plugins/calendar_helper
|
|
||||||
license: MIT
|
|
||||||
version: 0.2
|
|
||||||
rails_version: 1.0+
|
|
@ -1,20 +0,0 @@
|
|||||||
class CalendarStylesGenerator < Rails::Generator::Base
|
|
||||||
|
|
||||||
def manifest
|
|
||||||
record do |m|
|
|
||||||
calendar_themes_dir = "public/stylesheets/calendar"
|
|
||||||
m.directory calendar_themes_dir
|
|
||||||
|
|
||||||
# Copy files
|
|
||||||
%w(red blue grey).each do |dir|
|
|
||||||
m.directory File.join(calendar_themes_dir, dir)
|
|
||||||
m.file File.join("#{dir}/style.css"), File.join(calendar_themes_dir, "#{dir}/style.css")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Dir.read("vendor/public/calendar_helper/generators/calendar_styles/templates").each do |dir|
|
|
||||||
# m.file "orig", File.join(calendar_themes_dir, dir.name, "some_file.css")
|
|
||||||
# end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
A blue based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
|
||||||
|
|
||||||
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
|
||||||
|
|
||||||
Colors:
|
|
||||||
Light Blue: bbccff
|
|
||||||
White: eeddee
|
|
||||||
Turq: 003355
|
|
||||||
Cream: ffffdd
|
|
||||||
*/
|
|
||||||
|
|
||||||
.calendar {
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.monthName th {
|
|
||||||
font-weight: normal;
|
|
||||||
text-align: right;
|
|
||||||
padding-top: 1em;
|
|
||||||
padding-bottom: 0.7em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dayName th {
|
|
||||||
font-size: 0.7em;
|
|
||||||
padding-top: 0.6em;
|
|
||||||
padding-bottom: 0.3em;
|
|
||||||
background-color: #303030;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth, .day, .specialDay {
|
|
||||||
padding: 0.7em 1em;
|
|
||||||
border-right: 1px solid white;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth {
|
|
||||||
color: #eeeeee;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.day, .specialDay {
|
|
||||||
text-align: center;
|
|
||||||
border-bottom: 1px dotted #bbbbbb;
|
|
||||||
background-color: #bbccff;
|
|
||||||
}
|
|
||||||
.specialDay {
|
|
||||||
background-color: #003355;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
.specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
.weekendDay {
|
|
||||||
background-color: #ffffdd;
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
A grey based theme, inspired by Blinksale and their ColorBurn widget. http://firewheeldesign.com
|
|
||||||
|
|
||||||
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
|
||||||
|
|
||||||
Colors:
|
|
||||||
dk: 787888
|
|
||||||
lt: 4f4f5b
|
|
||||||
lter: a8a8a8
|
|
||||||
white: ffffff
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
.calendar {
|
|
||||||
margin: auto;
|
|
||||||
color: white;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.monthName th {
|
|
||||||
font-weight: normal;
|
|
||||||
text-align: right;
|
|
||||||
padding-top: 1em;
|
|
||||||
padding-bottom: 0.7em;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dayName th {
|
|
||||||
font-size: 0.7em;
|
|
||||||
padding-top: 0.6em;
|
|
||||||
padding-bottom: 0.3em;
|
|
||||||
background-color: #303030;
|
|
||||||
color: white;
|
|
||||||
border-bottom: 1px solid white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth, .day, .specialDay {
|
|
||||||
padding: 0.7em 1em;
|
|
||||||
border-right: 1px solid #111111;
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth {
|
|
||||||
color: #999999;
|
|
||||||
background-color: #4f4f5b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.day, .specialDay {
|
|
||||||
border-bottom: 1px solid #111111;
|
|
||||||
background-color: #333333;
|
|
||||||
}
|
|
||||||
.specialDay {
|
|
||||||
background-color: #a8a8a8;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
.specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
.weekendDay {
|
|
||||||
background-color: #787888;
|
|
||||||
}
|
|
||||||
|
|
||||||
Colors:
|
|
||||||
dk: 787888
|
|
||||||
lt: 4f4f5b
|
|
||||||
lter: a8a8a8
|
|
||||||
white: ffffff
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
A red, white, and grey theme.
|
|
||||||
|
|
||||||
AUTHOR: Geoffrey Grosenbach http://nubyonrails.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
.calendar {
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.monthName th {
|
|
||||||
font-weight: normal;
|
|
||||||
text-align: right;
|
|
||||||
padding-top: 1em;
|
|
||||||
padding-bottom: 0.7em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dayName th {
|
|
||||||
font-size: 0.7em;
|
|
||||||
padding-top: 0.6em;
|
|
||||||
padding-bottom: 0.3em;
|
|
||||||
background-color: #303030;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth, .day, .specialDay {
|
|
||||||
padding: 0.7em 1em;
|
|
||||||
border-right: 1px solid white;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.otherMonth {
|
|
||||||
color: #eeeeee;
|
|
||||||
}
|
|
||||||
.weekendDay {
|
|
||||||
background-color: #eeeeee;
|
|
||||||
}
|
|
||||||
|
|
||||||
.day, .specialDay {
|
|
||||||
text-align: center;
|
|
||||||
border-bottom: 1px dotted #bbbbbb;
|
|
||||||
}
|
|
||||||
|
|
||||||
.specialDay {
|
|
||||||
background-color: #d10a21;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
.specialDay a, .specialDay a:visited, .specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
.specialDay a:hover {
|
|
||||||
color: white;
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
ActionView::Base.send :include, CalendarHelper
|
|
@ -1,138 +0,0 @@
|
|||||||
require 'date'
|
|
||||||
|
|
||||||
# CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting
|
|
||||||
module CalendarHelper
|
|
||||||
# Returns an HTML calendar. In its simplest form, this method generates a plain
|
|
||||||
# calendar (which can then be customized using CSS) for a given month and year.
|
|
||||||
# However, this may be customized in a variety of ways -- changing the default CSS
|
|
||||||
# classes, generating the individual day entries yourself, and so on.
|
|
||||||
#
|
|
||||||
# The following options are required:
|
|
||||||
# :year # The year number to show the calendar for.
|
|
||||||
# :month # The month number to show the calendar for.
|
|
||||||
#
|
|
||||||
# The following are optional, available for customizing the default behaviour:
|
|
||||||
# :table_class => "calendar" # The class for the <table> tag.
|
|
||||||
# :month_name_class => "monthName" # The class for the name of the month, at the top of the table.
|
|
||||||
# :other_month_class => "otherMonth" # Not implemented yet.
|
|
||||||
# :day_name_class => "dayName" # The class is for the names of the weekdays, at the top.
|
|
||||||
# :day_class => "day" # The class for the individual day number cells.
|
|
||||||
# This may or may not be used if you specify a block (see below).
|
|
||||||
# :abbrev => (0..2) # This option specifies how the day names should be abbreviated.
|
|
||||||
# Use (0..2) for the first three letters, (0..0) for the first, and
|
|
||||||
# (0..-1) for the entire name.
|
|
||||||
# :first_day_of_week => 0 # Renders calendar starting on Sunday. Use 1 for Monday, and so on.
|
|
||||||
#
|
|
||||||
# For more customization, you can pass a code block to this method, that will get one argument, a Date object,
|
|
||||||
# and return a values for the individual table cells. The block can return an array, [cell_text, cell_attrs],
|
|
||||||
# cell_text being the text that is displayed and cell_attrs a hash containing the attributes for the <td> tag
|
|
||||||
# (this can be used to change the <td>'s class for customization with CSS).
|
|
||||||
# This block can also return the cell_text only, in which case the <td>'s class defaults to the value given in
|
|
||||||
# +:day_class+. If the block returns nil, the default options are used.
|
|
||||||
#
|
|
||||||
# Example usage:
|
|
||||||
# calendar(:year => 2005, :month => 6) # This generates the simplest possible calendar.
|
|
||||||
# calendar({:year => 2005, :month => 6, :table_class => "calendar_helper"}) # This generates a calendar, as
|
|
||||||
# # before, but the <table>'s class
|
|
||||||
# # is set to "calendar_helper".
|
|
||||||
# calendar(:year => 2005, :month => 6, :abbrev => (0..-1)) # This generates a simple calendar but shows the
|
|
||||||
# # entire day name ("Sunday", "Monday", etc.) instead
|
|
||||||
# # of only the first three letters.
|
|
||||||
# calendar(:year => 2005, :month => 5) do |d| # This generates a simple calendar, but gives special days
|
|
||||||
# if listOfSpecialDays.include?(d) # (days that are in the array listOfSpecialDays) one CSS class,
|
|
||||||
# [d.mday, {:class => "specialDay"}] # "specialDay", and gives the rest of the days another CSS class,
|
|
||||||
# else # "normalDay". You can also use this highlight today differently
|
|
||||||
# [d.mday, {:class => "normalDay"}] # from the rest of the days, etc.
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# An additional 'weekend' class is applied to weekend days.
|
|
||||||
#
|
|
||||||
# For consistency with the themes provided in the calendar_styles generator, use "specialDay" as the CSS class for marked days.
|
|
||||||
#
|
|
||||||
def calendar(options = {}, &block)
|
|
||||||
raise(ArgumentError, "No year given") unless options.has_key?(:year)
|
|
||||||
raise(ArgumentError, "No month given") unless options.has_key?(:month)
|
|
||||||
|
|
||||||
block ||= Proc.new {|d| nil}
|
|
||||||
|
|
||||||
defaults = {
|
|
||||||
:table_class => 'calendar',
|
|
||||||
:month_name_class => 'monthName',
|
|
||||||
:other_month_class => 'otherMonth',
|
|
||||||
:day_name_class => 'dayName',
|
|
||||||
:day_class => 'day',
|
|
||||||
:abbrev => (0..2),
|
|
||||||
:first_day_of_week => 0
|
|
||||||
}
|
|
||||||
options = defaults.merge options
|
|
||||||
|
|
||||||
first = Date.civil(options[:year], options[:month], 1)
|
|
||||||
last = Date.civil(options[:year], options[:month], -1)
|
|
||||||
|
|
||||||
first_weekday = first_day_of_week(options[:first_day_of_week])
|
|
||||||
last_weekday = last_day_of_week(options[:first_day_of_week])
|
|
||||||
|
|
||||||
day_names = Date::DAYNAMES.dup
|
|
||||||
first_weekday.times do
|
|
||||||
day_names.push(day_names.shift)
|
|
||||||
end
|
|
||||||
|
|
||||||
cal = %(<table class="#{options[:table_class]}" border="0" cellspacing="0" cellpadding="0">)
|
|
||||||
cal << %(<thead><tr class="#{options[:month_name_class]}"><th><a href="#" id="calendar_prev">«</a></th><th colspan="5">#{Date::MONTHNAMES[options[:month]]}</th><th><a href="#" id="calendar_next">»</a></th></tr><tr class="#{options[:day_name_class]}">)
|
|
||||||
day_names.each {|d| cal << "<th>#{d[options[:abbrev]]}</th>"}
|
|
||||||
cal << "</tr></thead><tbody><tr>"
|
|
||||||
beginning_of_week(first, first_weekday).upto(first - 1) do |d|
|
|
||||||
cal << %(<td class="#{options[:other_month_class]})
|
|
||||||
cal << " weekendDay" if weekend?(d)
|
|
||||||
cal << %(">#{d.day}</td>)
|
|
||||||
end unless first.wday == first_weekday
|
|
||||||
first.upto(last) do |cur|
|
|
||||||
cell_text, cell_attrs = block.call(cur)
|
|
||||||
cell_text ||= cur.mday
|
|
||||||
cell_attrs ||= {:class => options[:day_class]}
|
|
||||||
cell_attrs[:class] += " weekendDay" if [0, 6].include?(cur.wday)
|
|
||||||
cell_attrs = cell_attrs.map {|k, v| %(#{k}="#{v}") }.join(" ")
|
|
||||||
cal << "<td #{cell_attrs}>#{cell_text}</td>"
|
|
||||||
cal << "</tr><tr>" if cur.wday == last_weekday
|
|
||||||
end
|
|
||||||
(last + 1).upto(beginning_of_week(last + 7, first_weekday) - 1) do |d|
|
|
||||||
cal << %(<td class="#{options[:other_month_class]})
|
|
||||||
cal << " weekendDay" if weekend?(d)
|
|
||||||
cal << %(">#{d.day}</td>)
|
|
||||||
end unless last.wday == last_weekday
|
|
||||||
cal << "</tr></tbody></table>"
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def first_day_of_week(day)
|
|
||||||
day
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_day_of_week(day)
|
|
||||||
if day > 0
|
|
||||||
day - 1
|
|
||||||
else
|
|
||||||
6
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def days_between(first, second)
|
|
||||||
if first > second
|
|
||||||
second + (7 - first)
|
|
||||||
else
|
|
||||||
second - first
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def beginning_of_week(date, start = 1)
|
|
||||||
days_to_beg = days_between(start, date.wday)
|
|
||||||
date - days_to_beg
|
|
||||||
end
|
|
||||||
|
|
||||||
def weekend?(date)
|
|
||||||
[0, 6].include?(date.wday)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -1,32 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Stylesheet Tester</title>
|
|
||||||
<link href="../generators/calendar_styles/templates/grey/style.css" media="screen" rel="Stylesheet" type="text/css" />
|
|
||||||
<style>
|
|
||||||
body, tr, td {
|
|
||||||
font-family: Verdana;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body style="background-color: #eeeeee">
|
|
||||||
|
|
||||||
<table class="calendar" border="0" cellspacing="0" cellpadding="0">
|
|
||||||
<thead>
|
|
||||||
<tr class="monthName">
|
|
||||||
<th colspan="7">April</th>
|
|
||||||
</tr>
|
|
||||||
<tr class="dayName">
|
|
||||||
<th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> <th>Sun</th> </tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
<tr> </tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,85 +0,0 @@
|
|||||||
require 'test/unit'
|
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../lib/calendar_helper")
|
|
||||||
|
|
||||||
class CalendarHelperTest < Test::Unit::TestCase
|
|
||||||
|
|
||||||
include CalendarHelper
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple
|
|
||||||
assert_match %r{August}, calendar_with_defaults
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_required_fields
|
|
||||||
# Year and month are required
|
|
||||||
assert_raises(ArgumentError) {
|
|
||||||
calendar
|
|
||||||
}
|
|
||||||
assert_raises(ArgumentError) {
|
|
||||||
calendar :year => 1
|
|
||||||
}
|
|
||||||
assert_raises(ArgumentError) {
|
|
||||||
calendar :month => 1
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_default_css_classes
|
|
||||||
# :other_month_class is not implemented yet
|
|
||||||
{ :table_class => "calendar",
|
|
||||||
:month_name_class => "monthName",
|
|
||||||
:day_name_class => "dayName",
|
|
||||||
:day_class => "day" }.each do |key, value|
|
|
||||||
assert_correct_css_class_for_default value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_custom_css_classes
|
|
||||||
# Uses the key name as the CSS class name
|
|
||||||
# :other_month_class is not implemented yet
|
|
||||||
[:table_class, :month_name_class, :day_name_class, :day_class].each do |key|
|
|
||||||
assert_correct_css_class_for_key key.to_s, key
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_abbrev
|
|
||||||
assert_match %r{>Mon<}, calendar_with_defaults(:abbrev => (0..2))
|
|
||||||
assert_match %r{>M<}, calendar_with_defaults(:abbrev => (0..0))
|
|
||||||
assert_match %r{>Monday<}, calendar_with_defaults(:abbrev => (0..-1))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_block
|
|
||||||
# Even days are special
|
|
||||||
assert_match %r{class="special_day">2<}, calendar(:year => 2006, :month => 8) { |d|
|
|
||||||
if d.mday % 2 == 0
|
|
||||||
[d.mday, {:class => 'special_day'}]
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_first_day_of_week
|
|
||||||
assert_match %r{<tr class="dayName">\s*<th>Sun}, calendar_with_defaults
|
|
||||||
assert_match %r{<tr class="dayName">\s*<th>Mon}, calendar_with_defaults(:first_day_of_week => 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
|
|
||||||
def assert_correct_css_class_for_key(css_class, key)
|
|
||||||
assert_match %r{class="#{css_class}"}, calendar_with_defaults(key => css_class)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_correct_css_class_for_default(css_class)
|
|
||||||
assert_match %r{class="#{css_class}"}, calendar_with_defaults
|
|
||||||
end
|
|
||||||
|
|
||||||
def calendar_with_defaults(options={})
|
|
||||||
options = { :year => 2006, :month => 8 }.merge options
|
|
||||||
calendar options
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
Reference in new issue