Calendar-Plugin-Renderer

 view release on metacpan or  search on metacpan

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

    my ($self, $params) = @_;

    unless (exists $params->{day_names}) {
        $params->{day_names} = [qw(Sun Mon Tue Wed Thu Fri Sat)];
    }

    my $text = Calendar::Plugin::Renderer::Text->new($params);

    my $line1 = $text->get_dashed_line;
    my $line2 = $text->get_month_header;
    my $line3 = $text->get_blocked_line;
    my $line4 = $text->get_day_header;
    my $empty = $text->get_empty_space;
    my $dates = $text->get_dates;

    my $calendar = join("\n", $line1, $line2, $line3, $line4, $line3, $empty.$dates)."\n";

    return Term::ANSIColor::Markup->colorize($calendar);
}

=head2 svg_calendar(\%params)

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


=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>';

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


=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>



( run in 0.564 second using v1.01-cache-2.11-cpan-49f99fa48dc )