NAME

Plift - Designer friendly, safe, extensible HTML template engine.

SYNOPSIS

use Plift;

my $plift = Plift->new(
    path    => \@paths,                               # default ['.']
    plugins => [qw/ Script Blog Gallery GoogleMap /], # plugins not included
);

my $tpl = $plift->template("index");

# set render directives
$tpl->at({
    '#name' => 'fullname',
    '#contact' => [
        '.phone' => 'contact.phone',
        '.email' => 'contact.email'
    ]
});

# render render with data
my $document = $tpl->render({

    fullname => 'Carlos Fernando Avila Gratz',
    contact => {
        phone => '+55 27 1234-5678',
        email => 'cafe@example.com'
    }
});

# print
print $document->as_html;

DESCRIPTION

Plift is a HTML template engine which enforces strict separation of business logic from the view. It is designer friendly, safe, extensible and fast enough to be used as a web request renderer. This engine tries to follow the principles described in the paper Enforcing Strict Model-View Separation in Template Engines by Terence Parr of University of San Francisco. The goal is to provide suficient power without providing constructs that allow separation violations.

MANUAL

This document is the reference for the Plift class. The manual pages (not yet complete) are:

Plift::Manual::Tutorial

Step-by-step intruduction to Plift. "Hello World" style.

Plift::Manual::DesignerFriendly

Pure HTML5 template files makes everything easier to write and better to maintain. Designers can use their WYSIWYG editor, backend developers can unit test their element renderers.

Plift::Manual::Inception

Talks about the web framework that inspired Plift, and its 'View-First' approach to web request handling. (As opposed to the widespread 'Controller-First').

Plift::Manual::CustomHandler

Explains how Plift is just an engine for reading/parsing HTML files, and dispaching subroutine handlers bound to XPath expressions. You will learn how to write your custom handlers using the same dispaching loop as the builtin handlers.

METHODS

add_handler

Arguments: \%parameters

Binds a handler to one or more html tags, attributes, or xpath expression. Valid parameters are:

tag

Scalar or arrayref of HTML tags bound to this handler.

attribute

Scalar or arrayref of HTML attributes bound to this handler.

xpath

XPath expression matching the nodes bound this handler.

template

Arguments: $template_name

Creates a new Plift::Context instance, which will load, process and render template $template_name. See "at" in Plift::Context, "set" in Plift::Context and "render" in Plift::Context.

process

Arguments: $template_name, $data, $directives
Return Value: $document

A shortcut method. A new context is created via "template", rendering directives are set via "at" in Plift::Context and finally the template is rendered via "render" in Plift::Context.

my $data = {
    fullname => 'John Doe',
    contact => {
        phone => 123,
        email => 'foo@example'
    }
};

my $directives = [
    '#name' => 'fullname',
    '#name@title' => 'fullname',
    '#contact' => {
        'contact' => [
            '.phone' => 'phone',
            '.email' => 'email',
        ]
]

my $document = $plift->process('index', $data, $directives);

SIMILAR PROJECTS

This is a list of modules (that I know of) that pursue similar goals:

HTML::Template

Probably one of the first to use (almost) valid html files as templates, and encourage less business logic to be embedded in the templates.

Template::Pure

Perl reimplementation of Pure.js. This module inspired Plift's render directives.

Template::Semantic

Similar to Template::Pure, but mixes data with render directives.

LICENSE

Copyright (C) Carlos Fernando Avila Gratz.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Carlos Fernando Avila Gratz <cafe@kreato.com.br>