Calendar-Plugin-Renderer

 view release on metacpan or  search on metacpan

lib/Calendar/Plugin/Renderer/Text.pm  view on Meta::CPAN

=head2 get_day_header()

=cut

sub get_day_header   {
    my ($self) = @_;

    my $max_length_day_name = $self->max_days_name;
    my $day_names = $self->day_names;
    my $line = '<blue><bold>|</bold></blue>';
    my $i = 1;
    foreach (@$day_names) {
        my $x = length($_);
        my $y = $max_length_day_name - $x;
        my $z = $y + 1;
        if ($i == 1) {
            $line .= ((' ')x$z). "<yellow><bold>$_</bold></yellow>";
            $i++;
        }
        else {
            $line .= " <blue><bold>|</bold></blue>".((' ')x$z)."<yellow><bold>$_</bold></yellow>";
        }

    }
    $line .= " <blue><bold>|</bold></blue>";

    return $line;
}

=head2 get_month_header()

=cut

sub get_month_header {
    my ($self) = @_;

    my $f = $self->f;
    my $s = $self->s;
    my $h = $self->month_head;

    return '<blue><bold>|</bold></blue>'.
           (' ')x($f-1).
           '<yellow><bold>'.
           $h.
           '</bold></yellow>'.
           (' ')x($s-1).
           '<blue><bold>|</bold></blue>';
}

=head2 get_dashed_line()

=cut

sub get_dashed_line  {
    my ($self) = @_;

    my $line_size = $self->line_size;
    return '<blue><bold>+'.('-')x($line_size-2).'+</bold></blue>';
}

=head2 get_blocked_line()

=cut

sub get_blocked_line {
    my ($self) = @_;

    my $max_length_day_name = $self->max_days_name;
    my $line = '<blue><bold>+';
    foreach (1..7) {
        $line .= ('-')x($max_length_day_name+2).'+';
    }

    $line .= '</bold></blue>';

    return $line;
}

=head2 get_empty_space()

=cut

sub get_empty_space {
    my ($self) = @_;

    my $max_length_day_name = $self->max_days_name;
    my $start_index = $self->start_index;
    my $line = '';
    if ($start_index % 7 != 0) {
        $line .= '<blue><bold>|</bold></blue>'.(' ')x($max_length_day_name+2);
        map { $line .= ' 'x($max_length_day_name+3) } (2..($start_index %= 7));
    }

    return $line;
}

=head2 get_dates()

=cut

sub get_dates {
    my ($self) = @_;

    my $max_length_day_name = $self->max_days_name;
    my $start_index = $self->start_index;
    my $days        = $self->days;
    my $line = '';
    my $blocked_line = $self->get_blocked_line;
    foreach (1 .. $days) {
        $line .= sprintf("<blue><bold>|</bold></blue><cyan><bold>%".($max_length_day_name+1)."s </bold></cyan>", $_);
        if ($_ != $days) {
            $line .= "<blue><bold>|</bold></blue>\n".$blocked_line."\n" unless (($start_index + $_) % 7);
        }
        elsif ($_ == $days) {
            my $x = 7 - (($start_index + $_) % 7);
            if (($x >= 2) && ($x != 7)) {
                $line .= '<blue><bold>|</bold></blue>'. (' 'x($max_length_day_name+2));
                map { $line .= ' 'x($max_length_day_name+3) } (1..$x-1);
            }
            elsif ($x != 7) {
                $line .= '<blue><bold>|</bold></blue>'.' 'x($max_length_day_name+2);
            }
        }
    }

    return sprintf("%s<blue><bold>|</bold></blue>\n%s\n", $line, $blocked_line);
}


=head1 AUTHOR

Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>

=head1 REPOSITORY

L<https://github.com/manwar/Calendar-Plugin-Renderer>

=head1 BUGS

Please report any bugs / feature requests to C<bug-calendar-plugin-renderer at rt.cpan.org>,
or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Plugin-Renderer>.
I will be notified, and then you'll automatically be notified of progress on your
bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Calendar::Plugin::Renderer::Text

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Plugin-Renderer>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Calendar-Plugin-Renderer>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Calendar-Plugin-Renderer>

=item * Search CPAN

L<http://search.cpan.org/dist/Calendar-Plugin-Renderer/>

=back

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2015 - 2016 Mohammad S Anwar.

This program  is  free software; you can redistribute it and / or modify it under
the  terms  of the the Artistic License (2.0). You may obtain a  copy of the full
license at:

L<http://www.perlfoundation.org/artistic_license_2_0>

Any  use,  modification, and distribution of the Standard or Modified Versions is
governed by this Artistic License.By using, modifying or distributing the Package,
you accept this license. Do not use, modify, or distribute the Package, if you do
not accept this license.



( run in 1.368 second using v1.01-cache-2.11-cpan-e1769b4cff6 )