Perl-tt

Simple perl Template Toolkit Script

Download .zip Download .tar.gz View on GitHub

perl-tt Template Toolkit Script

This module provides a simple script for using the perl Template Toolkit.

Build Status

Synopsys

The perl-tt script takes some template as input and additional structured information passed as JSON or configuration paramaters.

The script can be used in its self executable form perl-tt.x86_64 on x86_64 Linux systems for direct download and usage. Refer to the download section.

Usage

Use the perl-tt script with for instance an input json file_ and a perl Template Toolkit_ template. For instance:

perl-tt hello.txt.tt buddy.json
Hello World!

Where hello.txt.tt is:

Hello [% i.buddy %]!

And buddy.json is:

{ "buddy": "World" }

The buddy.json JSON object file is passed to the template under the i (for input) variable. Thus the buddy name is retrieved in the template with i.buddy as shown above.

Alternatively, multiple structured files can be passed with the -f KEY=FILE option and are then available under the KEY variable from within the template.

Some other variable values can be passed as configuration variables through the command line with the -c KEY=VALUE option and are available in the template under the c.KEY (for configuration) variable.

For instance a basic HTML_ page can be generated from the following template:

cat page.html.tt
<html>
  <head>
    <title> [% c.title %] </title>
  </head>
  <body>
  [% c.text %]
  </body>
</html>

With for instance:

perl-tt -c title="A title" -c text="A text" page.html.tt >page.html

Which gives:

cat page.html
<html>
  <head>
    <title> A title </title>
  </head>
  <body>
  A text
  </body>
</html>

Refer to some examples from the examples source directory at https://github.com/guillon/perl-tt/tree/master/examples

Download

Download the latest release artifacts from the https://github.com/guillon/perl-tt/releases/latest page:

  • get the self contained executable: perl-tt.x86_64
  • or get the released source archive: perl-tt.tar.gz
  • or get the git sources archive ,tar.gz or .zip.

Otherwise, clone the latest stable revision with:

git clone https://github.com/guillon/perl-tt.git

In order to use directly the self contained executable, download it make it avaiable in your executable path:

mv perl-tt.x86_64 ~/bin/perl-tt
chmod +x ~/bin/perl-tt
PATH=~/bin:$PATH

Install

Install from sources locally in ~/perl5 with:

./cpanm --notest .

Note that this will also download and install dependencies when not available on the system. Hence a correctly configured network and HTTP proxy in some cases is required.

Otherwise, be sure to have installed the dependencies first on the system, with the package manager for instance. Dependencies can be found in the Makefile.PL file: https://github.com/guillon/perl-tt/blob/master/Makefile.PL

Optionally install dependencies first and then build with:

./cpanm --installdeps --notest .
perl Makefile.PL PREFIX=~/perl5
make
make install

And use the script as:

PERL5LIB=~/perl5/lib/perl5 && export PERL5LIB
$PWD/devimage/bin/perl-tt

One may install in another directory with:

./cpanm -l $PWD/devimage --self-contained --notest .

And use the script as:

PERL5LIB=$PWD/devimage && export PERL5LIB
$PWD/devimage/bin/perl-tt

Optionally, one can then build the self contained executable with:

perl -I $PWD/devimage/lib/perl5 devimage/bin/pp -o perl-tt.x devimage/bin/perl-tt

An use the executable as:

./perl-tt.x

Build Status

The last build status for the stab;e master branch is available there: https://travis-ci.org/guillon/perl-tt/branches.

License

Refer to the COPYING and COPYRIGHT files for information:

References

Ref to json file: http://json.org/example

Ref to perl Template Toolkit: http://template-toolkit.org

Ref to HTML spec: http://www.w3.org/html