Plosurin - Perl 5 implementation of Closure Templates
For template example.soy with content:
example.soy
{namespace mytest} /** * Simple test */ {template .Hello} <h1>Foreach example</h1> {foreach $a in [1,2]} <p>Line: {$a}</p><br/> {/foreach} <p>Ok</p> {/template}
To get Perl 5 module (MyApp, for example), just run the following command:
plosurin.p5 -package MyApp < example.soy > MyApp.pm
Use template in your Perl 5 program:
use MyApp; print &MyApp::mytest_Hello();
or get help:
perldoc MyApp.pm
Plosurin - Perl implementation of Closure Templates.
Every Soy file should have these components, in this order:
A namespace declaration.
One or more template definitions.
Here is an example template:
{namespace examples.simple} /** * Says hello to a person. * @param name The name of the person to say hello to. */ {template .helloName} Hello {$name}! {/template}
Commands are instructions that you give the template compiler to create templates and add custom logic to templates. Put commands within Closure Template tags, which are delimited by braces ({}).
{}
The first token within a tag is the command name (the print command is implied if no command is specified), and the rest of the text within the tag (if any) is referred to as the command text. Within the template you can enclose other commands to evaluate conditional expressions, iterate over data objects, or print messages.
{/foreach} {if length($items) > 5} {msg desc="Says hello to the user."}
If a command has a corresponding end command, then the end command's name is a / followed by the name of the start command, e.g. foreach and /foreach.
/
/foreach
Return array of tempaltes
use Plosurin; my $p = new Plosurin::; my $in_fd = new IO::File:: "< $infile" or die "$infile: $!"; my $nodes = $p->parse( $in, "file_name.soy"); say $p->as_perl5( { package => "MyApp::Templates" }, $nodes );
Export nodes as perl5 package
Closure Templates Documentation http://code.google.com/closure/templates/docs/overview.html
Perl 6 implementation https://github.com/zag/plosurin
Zahatski Aliaksandr, <zag@cpan.org>
Copyright (C) 2011 by Zahatski Aliaksandr
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Plo::File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plo::File
CPAN shell
perl -MCPAN -e shell install Plo::File
For more information on module installation, please visit the detailed CPAN module installation guide.