Build Status Coverage Status

NAME

Plift - HTML Template Engine + Custom HTML Elements

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:

METHODS

add_handler

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

See Plift::Manual::CustomHandler.

template

$context = $plift->template($template_name, \%options)

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

$document = $plift->process($template_name, \%data, \@directives)

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. Returns a XML::LibXML::jQuery object representing the final processed document.

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

print $document->as_html;

render

$html = $plift->render($template_name, \%data, \@directives)

A shortcut for $plift->process()->as_html.

load_components

$plift = $plift->load_components(@components)

Loads one or more Plift components. For each component, we build a class name by prepending Plift:: to the component name, then load the class, instantiate a new object and call $component->register($self).

See Plift::Manual::CustomHandler.

SIMILAR PROJECTS

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

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>