App-Templer

 view release on metacpan or  search on metacpan

bin/templer  view on Meta::CPAN



#
#  If we're running a HTTP-server do it now, since we've got
# all the data we need.
#
runHTTPD() if ( $CONFIG{ 'serve' } );


#
#  Now we've setup the defaults, and updated them via the configuration
# file we're ready to actually build/rebuild the templer-site.
#
#  We'll create the Templer::Site object to do that, the init method
# will ensure we have the input directory, and create the output directory
# if it is missing and required.
#
my $site = Templer::Site->new(%DEFAULTS);
$site->init();


bin/templer  view on Meta::CPAN

#
runCommands("post-build");




#
# All done.
#
my $duration = $timer->elapsed();
print "\nAll done: $rebuilt page(s) updated in $duration.\n"
  unless ( $CONFIG{ 'quiet' } );

exit(0);




#
#  Parse the command line
#

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



        #
        #  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 =~ /^(.*)\/(.*)$/ )
        {

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

        {
            rmdir $_;
        }
    }
}

=head2 set

Store/update a key/value pair in our internal store.

This allows the values passed in the constructor to be updated/added to.

=cut

sub set
{
    my ( $self, $key, $values ) = (@_);
    $self->{ $key } = $values;
}


t/test-templer-page-expansion.t  view on Meta::CPAN

    "This is the page title.",
    "The page title matches what we expect" );

#
#  Get the fields - which will be expanded by our plugin.
#
my %original = $page->fields();

my $plugin  = Templer::Plugin::Factory->new();
my $ref     = $plugin->expand_variables( $site, $page, \%original );
my %updated = %$ref;

is( $updated{ 'title' },
    "This is the page title.BOO",
    "The field was expanded"
  );
is( $updated{ 'foo' }, "barBOO", "The field was expanded" );

t/test-templer-plugin-filecontents.t  view on Meta::CPAN

#
is( $page->field("title"),
    "This is my page title.",
    "The page has the correct title" );

#
#  Get the data, after plugin-expansion
#
my %original = $page->fields();
my $ref      = $factory->expand_variables( $site, $page, \%original );
my %updated  = %$ref;

ok( %updated,               "Fetching the fields of the page succeeded" );
ok( $updated{ 'password' }, "The fields contain a file reference" );
ok( $updated{ 'foo' },      "The fields contain the self-file reference" );

#
# Do the file contents look sane?
#
ok( $updated{ 'password' } =~ /root:/,  "The password file looks sane" );
ok( $updated{ 'foo' }      =~ /passwd/, "The self-file looks sane" );

t/test-templer-plugin-fileglob.t  view on Meta::CPAN

#
is( $page->field("title"),
    "This is my page title.",
    "The page has the correct title" );

#
#  Get the data, after plugin-expansion
#
my %original = $page->fields();
my $ref      = $factory->expand_variables( $site, $page, \%original );
my %updated  = %$ref;

ok( %updated,            "Fetching the fields of the page succeeded" );
ok( $updated{ 'files' }, "The fields contain a file reference" );

foreach my $obj ( @{ $updated{ 'files' } } )
{
    my $file = $obj->{ 'file' };
    ok( $obj->{ 'file' }, "The file reference has a name : $obj->{ 'file' }" );
    ok( $obj->{ 'file' } =~ m{^foo/}, "    file reference is sane" );
    if ( $file eq "foo/foo.txt" )
    {
        is( $obj->{ 'contents' },  "something", "    content is propagated" );
        is( $obj->{ 'dirname' },   'foo',       "    dirname is captured" );
        is( $obj->{ 'basename' },  'foo',       "    basename is captured" );
        is( $obj->{ 'extension' }, 'txt',       "    extension is captured" );

t/test-templer-plugin-fileglob.t  view on Meta::CPAN

    }
    elsif ( $file eq "foo/input.skx" )
    {
        is( $obj->{ 'variable' },
            'Value', "    input variables are propagated" );
        is( $obj->{ 'dirname' },   'foo',   "    dirname is captured" );
        is( $obj->{ 'basename' },  'input', "    basename is captured" );
        is( $obj->{ 'extension' }, 'skx',   "    extension is captured" );
    }
}
is( scalar( @{ $updated{ 'files' } } ),
    5, "We received the number of files we expected" );

#
# All done.
#




#

t/test-templer-plugin-redis.t  view on Meta::CPAN

        "This is my redis-page title.",
        "The page has the correct title"
      );

    #
    #  Get the data, after plugin-expansion, which should mean that the
    # count is populated to something.
    #
    my %original = $page->fields();
    my $ref      = $factory->expand_variables( $site, $page, \%original );
    my %updated  = %$ref;

    ok( %updated,            "Fetching the fields of the page succeeded" );
    ok( $updated{ 'count' }, "The fields contain a count reference" );
    is( $updated{ 'count' }, "is.me", "The field has the correct value" );

    #
    #  If there was previously a value, reset it.
    #
    if ($val)
    {
        $redis->set( "steve.kemp", $val );
    }
    else
    {

t/test-templer-plugin-rootpath.t  view on Meta::CPAN

my $page0 = Templer::Site::Page->new( file => $dir . "/input.skx" );
ok( $page0, "We created a page object at root level" );
isa_ok( $page0, "Templer::Site::Page", "  Which has the correct type:" );
is( $page0->field("title"), "a title", "  ...and the correct title" );

#
#  Get the data, after plugin-expansion for page at root level
#
my %original = $page0->fields();
my $ref      = $factory->expand_variables( $site, $page0, \%original );
my %updated  = %$ref;

ok( %updated,          "Fetching the fields of the first page succeeded" );
ok( $updated{ 'css' }, "There is a path_to(css) variable" );
is( $updated{ 'css' }, "./css", "  Which has the right value" );
ok( $updated{ 'root' }, "There is a path_to web root" );
is( $updated{ 'root' }, ".", "  Which has the right value" );

#
#  Create second page and ensure title is there
#
my $page1 = Templer::Site::Page->new( file => $dir . "/1/input.skx" );
ok( $page1, "We created a page object at level 1 from root" );
isa_ok( $page1, "Templer::Site::Page", "  Which has the correct type:" );

#
#  Get the data, after plugin-expansion for page at level 1
#
%original = $page1->fields();
$ref      = $factory->expand_variables( $site, $page1, \%original );
%updated  = %$ref;

ok( %updated,          "Fetching the fields of the second page succeeded" );
ok( $updated{ 'css' }, "There is a path_to(css) variable" );
is( $updated{ 'css' }, "../css", "  Which has the right value" );
ok( $updated{ 'root' }, "There is a path_to web root" );
is( $updated{ 'root' }, "..", "  Which has the right value" );

#
# All done.
#

t/test-templer-plugin-shellcommand.t  view on Meta::CPAN

{
    skip "/bin/ls was not found." unless ( -x "/bin/ls" );

    #
    #  Expand the variables
    #
    my $ref = $factory->expand_variables( $site, undef, \%input );
    ok( $ref, "Calling the plugin returned something sane." );

    #
    #  Get the updated values which we expect to be unchanged.
    #
    is( $ref->{ 'title' },
        "This is my page title.",
        "After calling the plugin the sane value is unchanged." );

    is( $ref->{ 'bar' },
        "baz", "After calling the plugin the sane value is unchanged." );

    #
    #  Now see if our "foo" value was replaced by the output of the shell

t/test-templer-plugin-timestamp.t  view on Meta::CPAN

#
is( $page->field("title"),
    "This is my page title.",
    "The page has the correct title" );

#
#  Get the data, after plugin-expansion
#
my %original = $page->fields();
my $ref      = $factory->expand_variables( $site, $page, \%original );
my %updated  = %$ref;

ok( %updated,            "Fetching the fields of the page succeeded" );
ok( $updated{ 'myear' }, "The fields contain a year-reference" );
ok( $updated{ 'mmon' },  "The fields contain a year-reference" );

#
#  The year + month from the expanded template
#
my $myear = $updated{ 'myear' };
my $mmon  = $updated{ 'mmon' };
$mmon =~ s/^0//g;


#
#  Get the current year/month/day, etc, to compare with the
# plugin-found values.
#
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
  localtime(time);
$year += 1900;



( run in 0.364 second using v1.01-cache-2.11-cpan-05444aca049 )