view release on metacpan or search on metacpan
Changes
examples/calendar.pl
examples/first.pl
examples/japanese.pl
examples/menu.pl
examples/moon.pl
examples/synopsis.pl
examples/weekless.pl
lib/HTML/Make/Calendar.pm
lib/HTML/Make/Calendar.pod
lib/HTML/Make/Calendar/html.txt
Makefile.PL
MANIFEST			This list of files
MANIFEST.SKIP
README
script/html-cal
t/html-make-calendar.t
META.yml                                 Module YAML meta-data (added by MakeMaker)
META.json                                Module JSON meta-data (added by MakeMaker)
{
   "abstract" : "Make an HTML calendar",
   "author" : [
      "Ben Bullock <bkb@cpan.org>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
            "Date::Calc" : "6.4",
            "HTML::Make" : "0.13",
            "Table::Readable" : "0.03",
            "perl" : "5.006001"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "bugtracker" : {
         "web" : "https://github.com/benkasminbullock/html-make-calendar/issues"
      },
      "repository" : {
         "type" : "git",
         "url" : "git://github.com/benkasminbullock/html-make-calendar.git",
         "web" : "https://github.com/benkasminbullock/html-make-calendar"
      }
   },
   "version" : "0.01",
   "x_serialization_backend" : "JSON::PP version 4.04"
}
---
abstract: 'Make an HTML calendar'
author:
  - 'Ben Bullock <bkb@cpan.org>'
build_requires:
  ExtUtils::MakeMaker: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
no_index:
  directory:
    - t
    - inc
requires:
  Date::Calc: '6.4'
  HTML::Make: '0.13'
  Table::Readable: '0.03'
  perl: '5.006001'
resources:
  bugtracker: https://github.com/benkasminbullock/html-make-calendar/issues
  repository: git://github.com/benkasminbullock/html-make-calendar.git
version: '0.01'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker;
my $pm = 'lib/HTML/Make/Calendar.pm';
my $pod = 'lib/HTML/Make/Calendar.pod';
my $github = 'github.com/benkasminbullock/html-make-calendar';
my $repo = "https://$github";
WriteMakefile (
    EXE_FILES => ['script/html-cal',],
    NAME => 'HTML::Make::Calendar',
    VERSION_FROM => $pm,
    ABSTRACT_FROM => $pod,
    AUTHOR => 'Ben Bullock <bkb@cpan.org>',
    LICENSE => 'perl',
    PREREQ_PM => {
	'Date::Calc' => '6.4',
2. Documentation - how to learn more about the module
3. Installation - how to install this module on a computer
4. Help - what to do if you get stuck
-----------------------------------------------------------------------------
1. ABOUT
HTML::Make::Calendar - Make an HTML calendar
This module constructs HTML calendars.
-----------------------------------------------------------------------------
2. DOCUMENTATION
You can read the documentation for the module online at the following
website:
    * http://metacpan.org/release/HTML-Make-Calendar
"make" and before "make install".
-----------------------------------------------------------------------------
4. HELP
To get help with the module, you can email the author, Ben Bullock, at
<bkb@cpan.org>. If you think there is a problem in the module, you can
report a bug at 
<https://github.com/benkasminbullock/html-make-calendar/issues>,
or if you want to alter the source code of HTML::Make::Calendar, try the
public repository on github at 
<https://github.com/benkasminbullock/html-make-calendar>. 
-----------------------------------------------------------------------------
This README was written on Sun Mar 14 09:01:34 2021.
-----------------------------------------------------------------------------
examples/calendar.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use HTML::Make::Calendar 'calendar';
my $out = calendar (year => 2021, month => 1);
print $out->text ();
examples/first.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use HTML::Make::Calendar 'calendar';
my $cal = calendar (first => 7);
print $cal->text ();
examples/japanese.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use HTML::Make::Calendar 'calendar';
use Date::Qreki 'rokuyou_unicode';
use Calendar::Japanese::Holiday;
use Lingua::JA::Numbers 'num2ja';
use Lingua::JA::FindDates 'seireki_to_nengo';
binmode STDOUT, ":encoding(utf8)";
my @daynames = (qw!æ ç« æ°´ æ¨ é å æ¥!);
my $calendar = calendar (daynames => \@daynames,
			 monthc => \&jmonth,
			 dayc => \&jday, first => 7);
print $calendar->text ();
exit;
sub jday
{
    my (undef, $date, $element) = @_;
    my @jdate = ($date->{year}, $date->{month}, $date->{dom});
    my $name = isHoliday (@jdate);
    my $rokuyou = rokuyou_unicode (@jdate);
    $element->push ('span', text => num2ja ($date->{dom}));
    $element->push ('br');
examples/menu.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use HTML::Make::Calendar 'calendar';
binmode STDOUT, ":encoding(utf8)";
my @foods = split '', <<EOF;
ðððððððð¥ððððððð¥ð
ð¥
ð
ð¥ð¥¬ð¥¦ð§ð§
ðð¥ð°ððððððð ð¢
ð£ð¤ð¥ð¥®ð¡ð¥ð¥ ð¥¡ð¦ªð¦ð§ð¨ð©ðªðð°ð§
EOF
@foods = grep {!/\s/} @foods;
my $cal = calendar (cdata => \@foods, dayc => \&add_food);
print $cal->text ();
exit;
sub add_food
{
    my ($foods, $date, $element) = @_;
    my $today = 
    $element->push ('span', text => $date->{dom});
    my $menu = HTML::Make->new ('ol');
    for (1..3) {
examples/moon.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use HTML::Make::Calendar 'calendar';
use Astro::MoonPhase;
use Date::Calc 'Date_to_Time';
binmode STDOUT, ":encoding(utf8)";
my @moons = qw!ð ð ð ð ð ð ð ð!;
my $cal = calendar (dayc => \&daymoon, cdata => \@moons);
print $cal->text ();
exit;
sub daymoon
{
    my ($moons, $date, $element) = @_;
    my $epochtime = Date_to_Time ($date->{year}, $date->{month},
				  $date->{dom}, 0, 0, 0);
    my ($phase) = phase ($epochtime);
    my $text = $moons->[int (8*$phase)] . " <b>$date->{dom}</b>";
examples/synopsis.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use HTML::Make::Calendar 'calendar';
my $cal = calendar ();
print $cal->text ();
my $oldcal = calendar (year => 1966, month => 3);
print $oldcal->text ();
examples/weekless.pl view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use HTML::Make::Calendar 'calendar';
use File::Slurper 'write_text';
my $css =<<EOF;
<style>
.cal-month {
display:grid;
grid-template-columns: repeat(7, fr);
}
.cal-day {
list-style-type: none;
height: 2em;
examples/weekless.pl view on Meta::CPAN
grid-column-start: 6;
background: #9f9;
}
.cal-sun {
grid-column-start: 7;
background: #979;
}
</style>
EOF
my $cal = calendar (weekless => 1, month_html => 'ul', day_html => 'li');
my $text = $css . $cal->text ();
write_text ('/usr/local/www/data/weekless.html', $text);
lib/HTML/Make/Calendar.pm view on Meta::CPAN
package HTML::Make::Calendar;
use warnings;
use strict;
use Carp;
use utf8;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw/calendar/;
our %EXPORT_TAGS = (
    all => \@EXPORT_OK,
);
our $VERSION = '0.01';
use Date::Calc ':all';
use HTML::Make;
use Table::Readable 'read_table';
#use Data::Dumper;
lib/HTML/Make/Calendar.pm view on Meta::CPAN
    else {
	# Allow non-class elements if the user doesn't want a class.
	$element = $parent->push ($type);
    }
    return $element;
}
sub add_month_heading
{
    my ($o, $tbody) = @_;
    # Add the title to the calendar
    my $titler = $tbody->push ('tr');
    my $titleh = $titler->push ('th', attr => {colspan => 7});
    my $my;
    if ($o->{monthc}) {
	my $date = {month => $o->{month}, year => $o->{year}};
	$my = &{$o->{monthc}} ($o->{cdata}, $date, $titleh);
    }
    else {
	$my = Month_to_Text ($o->{month}) . " $o->{year}";
	$titleh->add_text ($my);
lib/HTML/Make/Calendar.pm view on Meta::CPAN
    if ($o->{first} != 1) {
	if (int ($o->{first}) != $o->{first} ||
	    $o->{first} < 1 ||
	    $o->{first} > 7) {
	    carp "Use a number between 1 (Monday) and 7 (Sunday) for first";
	    $o->{first} = 1;
	}
    }
}
# Map from columns of the calendar to days of the week, e.g. 1 -> 7 if
# Sunday is the first day of the week.
sub map_dow2col
{
    my ($o) = @_;
    my %col2dow;
    for (1..7) {
	my $col2dow = $_ + $o->{first} - 1;
	if ($col2dow > 7) {
	    $col2dow -= 7;
	}
	$col2dow{$_} = $col2dow;
    }
    my %dow2col = reverse %col2dow;
    $o->{col2dow} = \%col2dow;
    $o->{dow2col} = \%dow2col;
}
sub calendar
{
    my (%options) = @_;
    my $o = {};
    bless $o;
    $o->option (\%options, 'verbose');
    ($o->{year}, $o->{month}, undef) = Today ();
    $o->option (\%options, 'year');
    $o->option (\%options, 'month');
    $o->option (\%options, 'dayc');
    $o->option (\%options, 'monthc');
lib/HTML/Make/Calendar.pm view on Meta::CPAN
    for (1..$o->{fill_start}) {
	push @cells, {};
    }
    for (1..$dim) {
	my $col = $col[$_];
	push @cells, {dom => $_, col => $col, dow => $o->{col2dow}{$col}};
    }
    for (1..$o->{fill_end}) {
	push @cells, {};
    }
    my $calendar = HTML::Make->new ($o->{month_html},
				    class => $html{month}{class});
    my $tbody = $calendar;
    my $table;
    if ($o->{month_html} eq 'table') {
	$tbody = $calendar->push ('tbody');
	$table = 1;
    }
    if (! $o->{weekless}) {
	if ($table) {
	    $o->add_month_heading ($tbody);
	}
    }
    # wom = week of month
    for my $wom (1..$weeks) {
	my $week = $tbody;
lib/HTML/Make/Calendar.pm view on Meta::CPAN
		else {
		    $day->push ('span', text => $dom, class => 'cal-dom');
		}
	    }
	    else {
		$day->add_class ('cal-noday');
	    }
	    # To do: allow a callback on the packing cells
	}
    }
    return $calendar;
}
# To do: Add caller line numbers rather than just use print.
sub vmsg
{
    print "@_\n";
}
1;
lib/HTML/Make/Calendar.pod view on Meta::CPAN
=encoding UTF-8
=head1 NAME
HTML::Make::Calendar - Make an HTML calendar
=head1 SYNOPSIS
    
    use HTML::Make::Calendar 'calendar';
    my $cal = calendar ();
    print $cal->text ();
    my $oldcal = calendar (year => 1966, month => 3);
    print $oldcal->text ();
    
=begin html
<p>The output HTML looks like this:</p>
<table class="cal-month">
<tbody><tr>
lib/HTML/Make/Calendar.pod view on Meta::CPAN
=end html
(This example is included as L<F<synopsis.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/synopsis.pl> in the distribution.)
=head1 VERSION
This documents version 0.01 of HTML-Make-Calendar
corresponding to L<git commit 0a44bc7f4d5e94e6c7729395bd3083814175fb90|https://github.com/benkasminbullock/html-make-calendar/commit/0a44bc7f4d5e94e6c7729395bd3083814175fb90> released on Sun Mar 14 09:01:16 2021 +0900.
=head1 DESCRIPTION
This module constructs HTML calendars.
=head1 FUNCTIONS
=head2 calendar
    my $out = calendar (year => 2010, month => 10);
Make the calendar. The return value is an HTML::Make object. To get
the actual HTML, call its C<text> method:
    
    use HTML::Make::Calendar 'calendar';
    my $out = calendar (year => 2021, month => 1);
    print $out->text ();
=begin html
<p>The output HTML looks like this:</p>
<table class="cal-month">
<tbody><tr>
<th colspan="7">January 2021</th>
lib/HTML/Make/Calendar.pod view on Meta::CPAN
</td>
<td class="cal-day cal-sun"><span class="cal-dom">31</span>
</td>
</tr>
</tbody>
</table>
=end html
(This example is included as L<F<calendar.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/calendar.pl> in the distribution.)
The possible arguments are
=over
=item cdata
Callback data, see L</dayc>.
=item day_html
Override the HTML element used to make the "day" cells. The default is
C<td>. If you override this then you also need to override the parent
elements, otherwise HTML::Make will fuss about compatibility.
=item dayc
Day callback which fills in the "day" cell of the calendar. If this is
omitted, a default element is added. The day callback is called with
three arguments, first L</cdata>, your data, second the date as a hash
reference with arguments C<year>, C<month> and C<dom> (day of month, a
number from 1 to 31), and third the HTML element to attach the return
value to, representing the cell of the calendar, like this:
    &{$dayc} ($cdata, {year => 2020, month => 12, dom => 21}, $td);
where C<$td> is an L<HTML::Make> object.
=item daynames
Specify the names of the days. See L</Japanese calendar> for an
example.
=item first
The first day of the week. The default is 1 for Monday. Specify 7 to
start on Sunday:
    
    use HTML::Make::Calendar 'calendar';
    my $cal = calendar (first => 7);
    print $cal->text ();
    
=begin html
<p>The output HTML looks like this:</p>
<table class="cal-month">
<tbody><tr>
lib/HTML/Make/Calendar.pod view on Meta::CPAN
Any other day of the week may also be used, for example specify 3 to
start the weeks on Wednesdays.
=item month
The month, as a number from 1 to 12. If the month is omitted, the
current month is used as given by L<Date::Calc/Today>.
=item month_html
The HTML element used to make a month of the calendar. The default is
C<table>. You don't need to supply E<lt> and E<gt>, just the
alphabetic part of the HTML element, as with the parent module
HTML::Make.
=item monthc
Callback for month and year name. See L</Japanese calendar> for an
example.
=item week_html
The HTML element used to make a week of the calendar. The default is
C<tr>. You don't need to supply E<lt> and E<gt>, just the
alphabetic part of the HTML element, as with the parent module
HTML::Make.
=item weekless
Set to a true value to not use weeks. If you switch off weeks, the
return value is the HTML elements but not subdivided into week blocks
but whose parent is the month. This is for people who want to style
their calendars with CSS, such as a CSS grid, rather than using HTML
tables.
=item year
The year, as a four-digit number like C<2020>. If the year is omitted,
the current year is used, as given by L<Date::Calc/Today>.
=back
=head3 Phases of the moon
This example demonstrates the use of L</dayc> and L</cdata> by adding
the phase of the moon to your calendar. It requires
L<Astro::MoonPhase> (not included with this distribution).
    
    use utf8;
    use HTML::Make::Calendar 'calendar';
    use Astro::MoonPhase;
    use Date::Calc 'Date_to_Time';
    my @moons = qw!ð ð ð ð ð ð ð ð!;
    my $cal = calendar (dayc => \&daymoon, cdata => \@moons);
    print $cal->text ();
    exit;
    
    sub daymoon
    {
        my ($moons, $date, $element) = @_;
        my $epochtime = Date_to_Time ($date->{year}, $date->{month},
                                      $date->{dom}, 0, 0, 0);
        my ($phase) = phase ($epochtime);
        my $text = $moons->[int (8*$phase)] . " <b>$date->{dom}</b>";
lib/HTML/Make/Calendar.pod view on Meta::CPAN
=end html
(This example is included as L<F<moon.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/moon.pl> in the distribution.)
=head3 Daily menu
This example demonstrates the use of L</dayc> and L</cdata>, and how
to add your own HTML into the cells of the calendar.
    
    use utf8;
    use FindBin '$Bin';
    use HTML::Make::Calendar 'calendar';
    my @foods = split '', <<EOF;
    ðððððððð¥ððððððð¥ð
ð¥
    ð
ð¥ð¥¬ð¥¦ð§ð§
ðð¥ð°ððððððð ð¢
    ð£ð¤ð¥ð¥®ð¡ð¥ð¥ ð¥¡ð¦ªð¦ð§ð¨ð©ðªðð°ð§
    EOF
    @foods = grep {!/\s/} @foods;
    my $cal = calendar (cdata => \@foods, dayc => \&add_food);
    print $cal->text ();
    exit;
    
    sub add_food
    {
        my ($foods, $date, $element) = @_;
        my $today = 
        $element->push ('span', text => $date->{dom});
        my $menu = HTML::Make->new ('ol');
        for (1..3) {
lib/HTML/Make/Calendar.pod view on Meta::CPAN
</tr>
</tbody>
</table>
=end html
(This example is included as L<F<menu.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/menu.pl> in the distribution.)
=head3 Japanese calendar
This example shows making a Japanese calendar using L</daynames> as
well as L</monthc> to put the month name into Japanese. It uses
L<Calendar::Japanese::Holiday>, L<Date::Qreki>,
L<Lingua::JA::Numbers>, and L<Lingua::JA::FindDates> to make various
bits of information typically found on Japanese calendars.
    
    use utf8;
    use HTML::Make::Calendar 'calendar';
    use Date::Qreki 'rokuyou_unicode';
    use Calendar::Japanese::Holiday;
    use Lingua::JA::Numbers 'num2ja';
    use Lingua::JA::FindDates 'seireki_to_nengo';
    my @daynames = (qw!æ ç« æ°´ æ¨ é å æ¥!);
    my $calendar = calendar (daynames => \@daynames,
                             monthc => \&jmonth,
                             dayc => \&jday, first => 7);
    print $calendar->text ();
    exit;
    
    sub jday
    {
        my (undef, $date, $element) = @_;
        my @jdate = ($date->{year}, $date->{month}, $date->{dom});
        my $name = isHoliday (@jdate);
        my $rokuyou = rokuyou_unicode (@jdate);
        $element->push ('span', text => num2ja ($date->{dom}));
        $element->push ('br');
lib/HTML/Make/Calendar.pod view on Meta::CPAN
</table>
=end html
(This example is included as L<F<japanese.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/japanese.pl> in the distribution.)
=head1 DEFAULT HTML ELEMENTS AND CSS CLASSES
The elements of the calendar have the following default HTML elements
and CSS default style names:
=over
=item calendar
The default HTML element for C<calendar> (the calendar itself) is C<< <table> >> with class C<calendar>.
=item month
The default HTML element for C<month> (a month) is C<< <table> >> with class C<cal-month>.
=item week
The default HTML element for C<week> (a week) is C<< <tr> >> with class C<cal-week>.
lib/HTML/Make/Calendar.pod view on Meta::CPAN
=back
=head1 TERMINOLOGY
=over
=item dow = day of the week (Monday, Tuesday, etc.)
=item dom = day of the month (1 to 31)
=item wom = week of the month (corresponds to the rows of the calendar)
=back
=head1 DEPENDENCIES
=over
=item L<Date::Calc>
Date::Calc supplies the date information for the calendar.
=item L<HTML::Make>
HTML::Make is used to generate the HTML for the calendar.
=item L<Table::Readable>
Table::Readable is used to read a table of HTML element and CSS class
defaults.
=back
=head1 SCRIPT
lib/HTML/Make/Calendar.pod view on Meta::CPAN
=item L<HTML::Calendar::Simple>
=item L<HTML::CalendarMonth>
=item L<HTML::CalendarMonthSimple>
=item L<SVG::Calendar>
=back
=head2 Other HTML calendar generators
=over
=item Python
The defaults of HTML calendar are somewhat based on Python's
L<calendar.HTMLCalendar|https://docs.python.org/3/library/calendar.html#calendar.HTMLCalendar>.
=back
=head1 AUTHOR
Ben Bullock, <bkb@cpan.org>
=head1 COPYRIGHT & LICENCE
lib/HTML/Make/Calendar/html.txt view on Meta::CPAN
item: calendar
element: table
class: calendar
desc: the calendar itself
item: month
element: table
class: cal-month
desc: a month
item: week
element: tr
class: cal-week
desc: a week
script/html-cal view on Meta::CPAN
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use HTML::Make::Calendar 'calendar';
use Getopt::Long;
my $ok = GetOptions (
    "year=i" => \my $year,
    "month=i" => \my $month,
    "verbose" => \my $verbose,
);
my $out = calendar (verbose => $verbose, year => $year, month => $month);
print $out->{html};
# Local variables:
# mode: perl
# End: