HTML-Make-Calendar

 view release on metacpan or  search on metacpan

lib/HTML/Make/Calendar.pod  view on Meta::CPAN

<td class="cal-day cal-mon"><span class="cal-dom">11</span>
</td>
<td class="cal-day cal-tue"><span class="cal-dom">12</span>
</td>
<td class="cal-day cal-wed"><span class="cal-dom">13</span>
</td>
<td class="cal-day cal-thu"><span class="cal-dom">14</span>
</td>
<td class="cal-day cal-fri"><span class="cal-dom">15</span>
</td>
<td class="cal-day cal-sat"><span class="cal-dom">16</span>
</td>
<td class="cal-day cal-sun"><span class="cal-dom">17</span>
</td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon"><span class="cal-dom">18</span>
</td>
<td class="cal-day cal-tue"><span class="cal-dom">19</span>
</td>
<td class="cal-day cal-wed"><span class="cal-dom">20</span>
</td>
<td class="cal-day cal-thu"><span class="cal-dom">21</span>
</td>
<td class="cal-day cal-fri"><span class="cal-dom">22</span>
</td>
<td class="cal-day cal-sat"><span class="cal-dom">23</span>
</td>
<td class="cal-day cal-sun"><span class="cal-dom">24</span>
</td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon"><span class="cal-dom">25</span>
</td>
<td class="cal-day cal-tue"><span class="cal-dom">26</span>
</td>
<td class="cal-day cal-wed"><span class="cal-dom">27</span>
</td>
<td class="cal-day cal-thu"><span class="cal-dom">28</span>
</td>
<td class="cal-day cal-fri"><span class="cal-dom">29</span>
</td>
<td class="cal-day cal-sat"><span class="cal-dom">30</span>
</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>
<th colspan="7">January 2021</th>
</tr>
<tr>
<th class="cal-dow">Su</th>
<th class="cal-dow">Mo</th>
<th class="cal-dow">Tu</th>
<th class="cal-dow">We</th>
<th class="cal-dow">Th</th>
<th class="cal-dow">Fr</th>
<th class="cal-dow">Sa</th>
</tr>
<tr class="cal-week">
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-fri"><span class="cal-dom">1</span>
</td>
<td class="cal-day cal-sat"><span class="cal-dom">2</span>
</td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-sun"><span class="cal-dom">3</span>
</td>
<td class="cal-day cal-mon"><span class="cal-dom">4</span>
</td>
<td class="cal-day cal-tue"><span class="cal-dom">5</span>
</td>
<td class="cal-day cal-wed"><span class="cal-dom">6</span>
</td>
<td class="cal-day cal-thu"><span class="cal-dom">7</span>
</td>
<td class="cal-day cal-fri"><span class="cal-dom">8</span>

lib/HTML/Make/Calendar.pod  view on Meta::CPAN

<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
</tr>
</tbody>
</table>


=end html

(This example is included as L<F<first.pl>|https://fastapi.metacpan.org/source/BKB/HTML-Make-Calendar-0.01/examples/first.pl> in the distribution.)


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>";
        $element->add_text ($text);
    }
    


=begin html

<p>The output HTML looks like this:</p>

<table class="cal-month">
<tbody><tr>
<th colspan="7">March 2021</th>
</tr>
<tr>
<th class="cal-dow">Mo</th>
<th class="cal-dow">Tu</th>
<th class="cal-dow">We</th>
<th class="cal-dow">Th</th>
<th class="cal-dow">Fr</th>
<th class="cal-dow">Sa</th>
<th class="cal-dow">Su</th>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon">🌕 <b>1</b></td>
<td class="cal-day cal-tue">🌕 <b>2</b></td>
<td class="cal-day cal-wed">🌖 <b>3</b></td>
<td class="cal-day cal-thu">🌖 <b>4</b></td>
<td class="cal-day cal-fri">🌖 <b>5</b></td>
<td class="cal-day cal-sat">🌖 <b>6</b></td>
<td class="cal-day cal-sun">🌗 <b>7</b></td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon">🌗 <b>8</b></td>
<td class="cal-day cal-tue">🌗 <b>9</b></td>
<td class="cal-day cal-wed">🌘 <b>10</b></td>
<td class="cal-day cal-thu">🌘 <b>11</b></td>
<td class="cal-day cal-fri">🌘 <b>12</b></td>
<td class="cal-day cal-sat">🌘 <b>13</b></td>
<td class="cal-day cal-sun">🌑 <b>14</b></td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon">🌑 <b>15</b></td>
<td class="cal-day cal-tue">🌑 <b>16</b></td>
<td class="cal-day cal-wed">🌑 <b>17</b></td>
<td class="cal-day cal-thu">🌒 <b>18</b></td>
<td class="cal-day cal-fri">🌒 <b>19</b></td>
<td class="cal-day cal-sat">🌒 <b>20</b></td>
<td class="cal-day cal-sun">🌒 <b>21</b></td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon">🌓 <b>22</b></td>
<td class="cal-day cal-tue">🌓 <b>23</b></td>
<td class="cal-day cal-wed">🌓 <b>24</b></td>
<td class="cal-day cal-thu">🌓 <b>25</b></td>
<td class="cal-day cal-fri">🌔 <b>26</b></td>
<td class="cal-day cal-sat">🌔 <b>27</b></td>
<td class="cal-day cal-sun">🌔 <b>28</b></td>
</tr>
<tr class="cal-week">
<td class="cal-day cal-mon">🌕 <b>29</b></td>
<td class="cal-day cal-tue">🌕 <b>30</b></td>
<td class="cal-day cal-wed">🌕 <b>31</b></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
</tr>
</tbody>
</table>


=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) {
            my $food = $foods->[int (rand (@$foods))];
            $menu->push ('li', text => $food);
        }
        $element->push ($menu);
    }


=begin html

<p>The output HTML looks like this:</p>

<table class="cal-month">
<tbody><tr>
<th colspan="7">January 2021</th>
</tr>
<tr>
<th class="cal-dow">Mo</th>
<th class="cal-dow">Tu</th>
<th class="cal-dow">We</th>
<th class="cal-dow">Th</th>
<th class="cal-dow">Fr</th>
<th class="cal-dow">Sa</th>
<th class="cal-dow">Su</th>
</tr>
<tr class="cal-week">
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-noday"></td>
<td class="cal-day cal-fri"><span>1</span>
<ol>
<li>🍍</li>
<li>🍅</li>
<li>🍅</li>
</ol>
</td>
<td class="cal-day cal-sat"><span>2</span>
<ol>
<li>🧄</li>
<li>🎂</li>
<li>🌰</li>
</ol>
</td>
<td class="cal-day cal-sun"><span>3</span>
<ol>
<li>🍌</li>
<li>🍅</li>
<li>🧄</li>
</ol>
</td>



( run in 0.669 second using v1.01-cache-2.11-cpan-39bf76dae61 )