Template::Teeny - Teeny-weeny templating system
Version 0.00_002
use Template::Teeny; my $tt = Template::Teeny->new({ include_path => ['foo/templates'] }); my $stash = Template::Teeny->new({ a => 1, b => 2, c => 3 }); $stash->add_section('items', $item1); $stash->add_section('items', $item2); $tt->process('foo.html', $stash);
Template::Teeny is a more perlish implementation of the concepts in googles ctemplate library. The template syntax does not have any conditionals or looping directly.
A basic template would look like so:
Hi [% name %], You ordered the following: [% SECTION items %] Title: [% title %] Date: [% date %] Identifier: [% id | uc %] [% INCLUDE 'full_description.txt' %] [% END %]
When processing the template, we supply a stash object which contains all the variables for processing.
This pulls variables directly from the current stash.
The current stash may have other stashes associated with it by name
$stash->add_section('foo', $other_stash);
This would then would run the SECTION block with $other_stash as its stash.
TODO - This still need implemented
This is a variable which will be run through the filter 'uc' before being output. These filters can be chained.
This will pull in the template from the file 'full_description.txt'
This simply marks the end of a section.
There are a multitude of different templating systems out there, so what makes this one so different? The aim of this system is to move all business logic out of the templates and back into the code where it belongs. This means that the templating becomes very lightweight and fast.
The Google CTemplate library is a great example of this approach, however I had attempted to bind this to perl and unfortunately was unable to make it work correctly enough for production use.
I aim to have a fully working perl version and further down the line implement a full C version with XS bindings. Other than that, I wanted to have a try at writing parsers/compilers for fun.
$tt->process('foo/bar/baz.tpl', $stash);
This method takes a template file name and a stash object to be processed.
$tt->parse('[% foo %]');
Takes a string representing the template. Returns an AST.
my $eval_string = $tt->compile( ...<AST>... );
This method take a generated AST and translates it into an eval-able string of perl code.
This is an accessor for the template include path.
Scott McWhirter, <konobi at cpan.org>
<konobi at cpan.org>
You can find documentation for this module with the perldoc command.
perldoc Template::Teeny
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Teeny
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Template-Teeny
CPAN Ratings
http://cpanratings.perl.org/d/Template-Teeny
Search CPAN
http://search.cpan.org/dist/Template-Teeny
Copyright 2008 Scott McWhirter, all rights reserved.
This program is released under the following license: BSD
To install Template::Teeny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Teeny
CPAN shell
perl -MCPAN -e shell install Template::Teeny
For more information on module installation, please visit the detailed CPAN module installation guide.