App-Templer

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

> **TIP**:  If your images are numbered numerically you can ensure their correct order by doing this:

    Title:  This is my title
    images: file_glob( img/[0-9].jpg img/1[0-9].jpg )
    ----
    <p>My gallery is now included in ascending numerical order:</p>


This facility is implemented in the `Templer::Plugin::FileGlob` [plugin](PLUGINS.md).

The file glob is primarily designed for handling image-galleries, which is why it will set the `height` and `width` attributes if your glob matches `*.jpg`, `*.png`, etc.  However it can also be used for non-images.

If your glob matches files which are not images it will populate the member `content`, being the text-content of the matching files.  This allows you to include files easily.  For example:


    Title: This is my news-page
    news: file_glob( news-*.txt )
    ----
    <p>Here are the recent events:</p>
    <!-- tmpl_loop name='news' -->
    <p><!-- tmpl_var name='content' --></p>

lib/Templer/Plugin/FileGlob.pm  view on Meta::CPAN

                #
                my ( $basename, $dirname, $extension ) = fileparse($file);
                ( $meta{ 'dirname' }  = $dirname ) =~ s{/$}{};
                ( $meta{ 'basename' } = $basename ) =~ s{(.*)\.([^.]*)$}{$1};
                $meta{ 'extension' } = $2;

                #
                # If the file is an image AND we have Image::Size
                # then populate the height/width too.
                #
                if ( $file =~ /\.(jpe?g|png|gif)$/i )
                {
                    my $module = "use Image::Size;";
                    ## no critic (Eval)
                    eval($module);
                    ## use critic
                    if ( !$@ )
                    {
                        if ( -e $file )
                        {
                            ( $meta{ 'width' }, $meta{ 'height' } ) =

t/test-templer-asset-copying.t  view on Meta::CPAN

#
#  Make the input-subdirectory
#
File::Path::mkpath( $tmp . "/input", { verbose => 0, mode => oct(755) } );
ok( -d $tmp, "We created an input/ directory" );

#
#  Create some assets.
#
createFile( $tmp . "/input/index.skx" );
createFile( $tmp . "/input/logo.png" );
createFile( $tmp . "/input/.htaccess" );
createFile( $tmp . "/input/it's ugly.png" );
createFile( $tmp . '/input/it' . "'" . 's ugly\.png' );
createFile( $tmp . '/input/it' . "'" . 's ugly".png' );
createFile( $tmp . '/input/it' . "'" . 's ugly$.png' );
createFile( $tmp . '/input/it' . "'" . 's ugly`.png' );
createFile( $tmp . '/input/it"s ugly.png' );

#
#  Now create the Templer::Site object.
#
my $site = Templer::Site->new( input  => "$tmp/input/",
                               output => "$tmp/output",
                               suffix => ".skx",
                             );


t/test-templer-asset-copying.t  view on Meta::CPAN

#
$site->init();
ok( -d "$tmp/output", "The output directory was created" );

#
# Copy the assets from input/ to output/
#
$site->copyAssets();


ok( -e $tmp . "/output/logo.png",                 "Asset copied successfully" );
ok( -e $tmp . "/output/.htaccess",                "Asset copied successfully" );
ok( -e $tmp . "/output/it's ugly.png",            "Asset copied successfully" );
ok( -e $tmp . '/output/it' . "'" . 's ugly\.png', "Asset copied successfully" );
ok( -e $tmp . '/output/it' . "'" . 's ugly".png', "Asset copied successfully" );
ok( -e $tmp . '/output/it' . "'" . 's ugly$.png', "Asset copied successfully" );
ok( -e $tmp . '/output/it' . "'" . 's ugly`.png', "Asset copied successfully" );
ok( -e $tmp . '/output/it"s ugly.png',            "Asset copied successfully" );
ok( !-e $tmp . "/output/index.skx",               "Page source not copied" );


sub createFile
{
    my ($file) = (@_);

    ok( !-e $file, "The file didn't exist prior to creation" );

    note("File to be created is : $file");

t/test-templer-synchronization.t  view on Meta::CPAN

Title: This is my page title.
----
This is my page content.
EOF
close($handle);
ok( -f $tmp . "/input/index.skx", "We created a source page" );

#
# Create some assets
#
createFile( $tmp . "/input/logo.png" );
createFile( $tmp . "/input/.htaccess" );

#
#  Now create the Templer::Site object.
#
my %data = ( "in-place"     => 0,
             "include-path" => "$tmp/includes",
             "input"        => "$tmp/input/",
             "layout"       => "default.layout",
             "layout-path"  => "$tmp/layouts",

t/test-templer-synchronization.t  view on Meta::CPAN

#
# Create garbage directory
#
File::Path::mkpath( $tmp . "/output/garbage",
                    { verbose => 0, mode => oct(755) } );
ok( -d $tmp, "We created an output/garbage empty directory" );

#
# Create garbage file
#
createFile( $tmp . "/output/garbage.png" );
ok( -e $tmp . "/output/garbage.png", "We created an output/garbage file" );

#
# Generate everything
#
$site->build();
$site->copyAssets();
$site->sync();

ok( -e $tmp . "/output/index.html", "Page generated correctly" );
ok( -e $tmp . "/output/logo.png",   "Asset copied successfully" );
ok( -e $tmp . "/output/.htaccess",  "Asset copied successfully" );
ok( !-e $tmp . "/garbage.png",      "Garbage file removed correctly" );
ok( !-e $tmp . "/garbage",          "Garbage directory removed correctly" );


sub createFile
{
    my ($file) = (@_);

    ok( !-e $file, "The file didn't exist prior to creation" );

    note("File to be created is : $file");



( run in 1.327 second using v1.01-cache-2.11-cpan-df04353d9ac )