App-Templer

 view release on metacpan or  search on metacpan

lib/Templer/Site.pm  view on Meta::CPAN

        #  Forced rebuild via the command-line.
        #
        $rebuild = 1 if ( $self->{ 'force' } );

        #
        #  OK skip if we're not rebuilding, otherwise increase the count.
        #
        next unless ($rebuild);
        $rebuilt += 1;


        #
        #  Load the HTML::Template module against the body of the page.
        #
        #  (Includes are relative to the path of the input.)
        #
        my $dirName = $page->source();
        if ( $dirName =~ /^(.*)\/(.*)$/ )
        {
            $dirName = $1;
        }
        my $body = HTML::Template->new( scalarref => \$page->content( \%data ),
                                        die_on_bad_params => 0,
                                        path => [@INCLUDES, $dirName],
                                        search_path_on_include => 1,
                                        global_vars            => 1,
                                        loop_context_vars      => 1,
                                        utf8                   => 1,
                                        filter                 => \@filters,
                                      );


        #
        #  Template-expand the body of the page.
        #
        $body->param( \%data );
        $data{ 'content' } = $body->output();


        #
        # Make the (updated) global and per-page data available
        # to the template object.
        #
        $tmpl->param( \%data );

        #
        # Make sure the output path exists.
        #
        my $path = $dst;
        if ( $path =~ /^(.*)\/(.*)$/ )
        {
            $path = $1;
            File::Path::mkpath( $path, { verbose => 0, mode => oct(755) } )
              if ( !-d $path );
        }

        #
        #  Output the expanded template to the destination file.
        #
        open my $handle, ">:utf8", $dst or die "Failed to write to '$dst' - $!";
        binmode( $handle, ":utf8" );
        print $handle $tmpl->output();
        close $handle;
    }

    #
    #  Cleanup any plugins.
    #
    $PLUGINS->cleanup();

    #
    #  Return count of rebuilt pages.
    #
    return ($rebuilt);
}


=head2 copyAssets

Copy all assets from the input directory to the output directory.

This method will use tar to do so semi-efficiently.

=cut

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


    #
    #  If we're running in-place then we don't need to copy assets.
    #
    return if ( $self->{ 'in-place' } );

    #
    #  The assets.
    #
    my @assets = $self->assets( directory => $self->{ 'input' } );

    #
    #  The files we're going to copy.
    #
    my @copy;


    #
    # We're going to build-up a command line to pass to tar
    #
    foreach my $asset (@assets)
    {

        #
        # Strip the input component of the filename(s).
        #
        my $src = $asset->source();
        $src =~ s/^$self->{'input'}//g;

        #
        # Store the destination file path
        #



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