HTML-Calendar-Monthly
view release on metacpan or search on metacpan
---
name: HTML-Calendar-Monthly
version: 0.03
author:
- 'Johan Vromans <jv@cpan.org>'
abstract: A very simple HTML calendar
license: perl
resources:
license: ~
requires:
Date::Simple: 0
build_requires:
Test::More: 0
provides:
HTML::Calendar::Monthly:
file: lib/HTML/Calendar/Monthly.pm
HTML::Calendar::Monthly
This is a very simple module which will make an HTML representation of
a given month. You can add links to individual days.
Yes, the inspiration for this came out of me looking at
HTML::Calendar::Simple, and thinking 'Hmmm. A bit too complicated for
what I want. I know, I will write a simplified version.' So I did.
Along with the module comes a flexible program to generate monthly
calendars for inclusion in web sites.
INSTALLATION
To install this module, run the following commands:
perl Build.PL
./Build
./Build test
./Build install
lib/HTML/Calendar/Monthly.pm view on Meta::CPAN
package HTML::Calendar::Monthly;
# Monthly.pm -- A very simple HTML calendar
# RCS Info : $Id: Monthly.pm,v 1.4 2009/06/25 09:18:25 jv Exp $
# Author : Johan Vromans
# Created On : Thu Apr 30 22:13:00 2009
# Last Modified By: Johan Vromans
# Last Modified On: Thu Jun 25 11:18:16 2009
# Update Count : 4
# Status : Unknown, Use with caution!
use strict;
use warnings;
our $VERSION = "0.03";
=head1 NAME
HTML::Calendar::Monthly - A very simple HTML calendar
=head1 SYNOPSIS
use HTML::Calendar::Monthly;
my $cal = HTML::Calendar::Monthly->new; # This month, this year
$cal = HTML::Calendar::Monthly->new({ 'month' => $month }); # This year
$cal = HTML::Calendar::Monthly->new({ 'month' => $month,
'year' => $year});
my $month = $cal->month;
my $year = $cal->year;
# Add a link for a day.
$cal->add_link( $day, $link );
# Get HTML representation.
my $html = $cal->calendar_month;
=head1 DESCRIPTION
This is a very simple module which will make an HTML representation of
a given month. You can add links to individual days.
Yes, the inspiration for this came out of me looking at
HTML::Calendar::Simple, and thinking 'Hmmm. A bit too complicated for
what I want. I know, I will write a simplified version.' So I did.
lib/HTML/Calendar/Monthly.pm view on Meta::CPAN
This will return the numerical value of the month.
my $month = $cal->month_name;
This will return the name of the month.
=head2 year
my $year = $cal->year;
This will return the four-digit year of the calendar
=cut
sub month { $_[0]->{month} } # month in numerical format
sub month_name { $months[$_[0]->{month}-1 ]} # month name
sub year { $_[0]->{year} } # year in YYYY form
sub _the_month { @{ $_[0]->{the_month} } } # this is the list of hashrefs.
=head2 add_link
lib/HTML/Calendar/Monthly.pm view on Meta::CPAN
. "</td>";
}
else {
return
"<td class='hc_date'>"
. $ref->{date}->day
. "</td>";
}
}
=head2 calendar_month
my $html = $cal->calendar_month;
This will return an html string of the calendar month.
=cut
sub calendar_month {
my $self = shift;
my @seq = $self->_the_month;
my $cal = "<table class='hc_month'>\n"
. " <tr>\n"
. join("\n", map { " <th>$_</th>" } @days )
. " </tr>\n";
while ( @seq ) {
my @week_row = splice( @seq, 0, DAYS_IN_WEEK );
$#week_row = DAYS_IN_WEEK - 1;
$cal .= " <tr>\n"
script/hcgen view on Meta::CPAN
my $data = "";
foreach ( @files ) {
my ( $y, $m, $d, $file ) = @$_;
if ( sprintf("%04d%02d", $y, $m) ne $this ) {
if ( $cal ) {
$data .= "<div class='hc'>\n";
$data .= $cal->build_title($title_format) . "\n"
if $needhdr >= 0;
$needhdr++;
$data .= $cal->calendar_month;
$data .= "</div>\n";
}
$cal = HTML::Calendar::Monthly->new
({ 'month' => $m, year => $y });
$this = sprintf("%04d%02d", $y, $m);
}
$cal->add_link( $d, $linkpfx.$file );
}
if ( $cal ) {
$data .= "<div class='hc'>\n";
$data .= $cal->build_title . "\n" if $needhdr > 0;
$data .= $cal->calendar_month;
$data .= "</div>\n";
}
if ( $output ) {
if ( update_if_needed($output, $data) ) {
warn("$output: written\n");
}
else {
warn("$output: not modified\n");
}
script/hcgen view on Meta::CPAN
$pod2usage->(VERBOSE => 2) if $man;
}
}
__END__
################ Documentation ################
=head1 NAME
hcgen - generate simple HTML month calendar
=head1 SYNOPSIS
hcgen [options] [dir]
Options:
--output=XXX output file (see below)
--reverse output months in reverse order
--[no]title do [not] provide a title (see below)
--format=XXX title format
script/hcgen view on Meta::CPAN
--help brief help message
--man full documentation
--verbose verbose information
=head1 OPTIONS
=over 8
=item B<--output=>I<XXX>
Write the generated calendars to this file. If the file exists, and
contains the same calendar, it will not be modified so it is useful as
a make target.
=item B<--reverse>
Generate the calendars in reverse order, e.g., newest month first.
=item B<--title> B<--notitle>
Request titles above the generated calendars. With B<--title>, titles
are always provided. With B<--notitle>, titles are never provided.
Default is to only provide titles when more than one calendar is
generated.
=item B<--format=>I<XXX>
The format for the titles. It may contain the following substitutions:
%m the name of the month, e.g., april
%M same, titlecased, e.g., April
%y %Y the year, e.g., 2009
script/hcgen view on Meta::CPAN
<p class='hc_title'>...</p>
Default format is C<< "%M %Y" >>.
=item B<--prefix=>I<XXX>
A prefix to add to the generated day links.
=item B<--force=>I<YYYYMM>
Force the generation of a calendar for this year/month, even if there
are no files.
=item B<--filter=>I<YYYYMM>
Process only files for the given year/month.
This option may occur multiple times.
=item B<--help>
script/hcgen view on Meta::CPAN
documents) with names formatted as C<< YYYYMMDD.html >>.
Default is to process the current directory.
=back
=head1 DESCRIPTION
B<hcgen> will read the given directory and build a list of all files
that obey the name format C<< YYYYMMDD.html >>. This list will
determine the years and months for which calendars must be generated.
Each calendar consists of a table of 7 colums. The first row
contains short day names. The other cells contain the date numbers,
possibly with a link to a corresponding HTML document.
=head1 CSS CLASSES
The table can be completely formatted with CSS style sheets.
The CSS classes are shown in the following output excerpt.
<div class='hc'>
<p class='hc_title'>February 2009</p>
script/hcgen view on Meta::CPAN
text-decoration: none;
font-weight: bold;
}
.hc_empty {
background: #e0e0e0;
}
=head1 BUGS
The program and its associated module, L<HTML::Calendar::Monthly>
are currently hard-wired to generate dutch calendars.
=head1 SEE ALSO
L<HTML::Calendar::Monthly>
=head1 AUTHOR
Johan Vromans E<lt>jvromans@squirrel.nlE<gt>
=cut
t/01-basic.t view on Meta::CPAN
#! perl
use strict;
use warnings;
use Test::More tests => 1;
use HTML::Calendar::Monthly;
my $cal = HTML::Calendar::Monthly->new( { year => 2009, month => 4 });
my $ref = do { local $/; <DATA> };
is( $cal->calendar_month, $ref, "empty calendar");
__END__
<table class='hc_month'>
<tr>
<th>Ma</th>
<th>Di</th>
<th>Wo</th>
<th>Do</th>
<th>Vr</th>
<th>Za</th>
t/02-links.t view on Meta::CPAN
use warnings;
use Test::More tests => 1;
use HTML::Calendar::Monthly;
my $cal = HTML::Calendar::Monthly->new( { year => 2009, month => 4 });
$cal->add_link( 5, "foo.html" );
$cal->add_link( 15, "bar.html" );
my $ref = do { local $/; <DATA> };
is( $cal->calendar_month, $ref, "empty calendar");
__END__
<table class='hc_month'>
<tr>
<th>Ma</th>
<th>Di</th>
<th>Wo</th>
<th>Do</th>
<th>Vr</th>
<th>Za</th>
( run in 0.338 second using v1.01-cache-2.11-cpan-5dc5da66d9d )