Spreadsheet-HTML

 view release on metacpan or  search on metacpan

lib/Spreadsheet/HTML/Presets.pm  view on Meta::CPAN

        );
        my $first = $time->wday;
        my $last  = $time->month_last_day;
        my @flat  = ( 
            (map Time::Piece->strptime($_,"%d")->day, 4 .. 10),
            ('') x ($first - 1),
            1 .. $last
        );
        
        push @cal_args, ( data => \@flat );

        my $mday = '-' . Time::Piece->new->mday;
        $args->{$mday} = exists $args->{$mday} ? $args->{$mday} : $args->{today};
        my %day_args = map {($_ => $args->{$_})} grep /^-\d+$/, keys %$args;
        for (keys %day_args) {
            my $day = abs($_);
            next if $day > $last;
            my $index = $day + $first + 5;
            my $row = int($index / 7);
            my $col = $index % 7;
            push @cal_args, ( sprintf( '-r%sc%s', $row, $col ) => $day_args{$_} );
        }

        my $caption = join( ' ', $time->fullmonth, $time->year );
        if ($args->{scroll}) {
            $caption = qq{<p>$caption</p><button id="toggle" onClick="toggle()">Start</button>};
        }

        my $attr = { style => { 'font-weight' => 'bold' } };
        if ($args->{caption} and ref $args->{caption} eq 'HASH') {
            ($attr) = values %{ $args->{caption} };
        }

        push @cal_args, ( caption => { $caption => $attr } );
    }

    my @args = (
        @cal_args,
        @_,
        td => { %{ $args->{td} || {} }, style  => { %{ $args->{td}{style} || {} }, 'text-align' => 'right' } },
        wrap    => 7,
        theta   => 0,
        flip    => 0,
        matrix  => 0,
    );        

    return $self ? $self->generate( @args ) : Spreadsheet::HTML::generate( @args );
}

sub _js_wrapper {
    my %args = @_;

    unless ($NO_MINIFY) {
        $args{code} = JavaScript::Minifier::minify(
            input      => $args{code},
            copyright  => $args{copyright} || 'Copyright 2024 Jeff Anderson',
            stripDebug => 1,
        );
    }

    my $js = $args{_auto}->tag( tag => 'script', cdata => $args{code}, attr => { type => 'text/javascript' } );
    return $js if $args{bare};

    $args{jquery} ||= 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js';

    my $html = $args{_auto}->tag( tag => 'script', cdata => '',    attr => { src => $args{jquery} } );
    $html   .= $args{_auto}->tag( tag => 'script', cdata => '',    attr => { src => $args{jqueryui} } ) if $args{jqueryui};
    $html   .= $args{_auto}->tag( tag => 'script', cdata => '',    attr => { src => $args{handsonjs} } ) if $args{handsonjs};
    $html   .= $args{_auto}->tag( tag => 'link', attr => { rel => 'stylesheet', media => 'screen', href => $args{css} } ) if $args{css};

    return $html . $js;
}

=head1 NAME

Spreadsheet::HTML::Presets - Generate preset HTML tables.

=head1 DESCRIPTION

This is a container for L<Spreadsheet::HTML> preset methods.
These methods are not meant to be called from this package.
Instead, use the Spreadsheet::HTML interface:

  use Spreadsheet::HTML;
  my $generator = Spreadsheet::HTML->new( data => \@data );
  print $generator->layout;

  # or
  use Spreadsheet::HTML qw( layout );
  print layout( data => \@data );

=head1 METHODS

=over 4

=item * C<layout( %params )>

Layout tables are not recommended, but if you choose to
use them you should label them as such. This adds W3C
recommended layout attributes to the table tag and features:
emit only <td> tags, no padding or pruning of rows, forces
no HTML entity encoding in table cells.

=item * C<checkerboard( colors, %params )>

Preset for tables with checkerboard colors.

  checkerboard( colors => [qw(yellow orange blue)] )

Forms diagonal patterns by alternating the starting background
colors for each row. C<colors> defaults to red and green.

  checkerboard( class => [qw(foo bar baz)] )

Same thing but alternate class names (for external CSS).

=item * C<banner( dir, text, emboss, on, off, fill, %params )>

Will generate and display a banner using the given C<text> in the
'banner' font. Set C<emboss> to a true value and the font 'block'
will be emulated by highlighting the left and bottom borders of the cell.
Set the foreground color with C<on> and the background with C<off>.
You Must have L<Text::FIGlet> installed AND configured in order to use
this preset. If Text::FIGlet cannot find the fonts directory then it
will silently fail and produce no banner.

  banner( dir => '/path/to/figlet/fonts', text => 'HI', on => 'red' )



( run in 1.352 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )