NAME

Plosurin - Perl 5 implementation of Closure Templates

SYNOPSIS

For template example.soy with content:

{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

DESCRIPTION

Plosurin - Perl implementation of Closure Templates.

Template Structure

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}

Command Syntax

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.

templates

Return array of tempaltes

Perl 5 code generator API

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 );

as_perl5 { package=>"MyApp::Tmpl" }, $node1[, $noden]

Export nodes as perl5 package

SEE ALSO

Closure Templates Documentation http://code.google.com/closure/templates/docs/overview.html

Perl 6 implementation https://github.com/zag/plosurin

AUTHOR

Zahatski Aliaksandr, <zag@cpan.org>

COPYRIGHT AND LICENSE

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.