NAME

Mustache::Simple - A simple Mustach Renderer

See http://mustache.github.com/.

VERSION

This document describes Mustache::Simple version 1.2.0

SYNOPSIS

A typical Mustache template:

    my $template = <<EOT;
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}
EOT

Given the following hashref:

my $context = {
    name => "Chris",
    value => 10000,
    taxed_value => 10000 - (10000 * 0.4),
    in_ca => 1
};

Will produce the following:

Hello Chris
You have just won $10000!
Well, $6000, after taxes.

using the following code:

my $tache = new Mustache::Simple(
    throw => 1
);
my $output = $tache->render($template, $context);

DESCRIPTION

Mustache can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.

There are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.

This is a simple perl implementation of the Mustache rendering. It has a single class method, new() to obtain an object and a single instance method render() to convert the template and the hashref into the final output.

As of version 1.2.0, it has support for nested contexts, for the dot notation and for the implicit iterator.

Rationale

I wanted a simple rendering tool for Mustache that did not require any subclassing.

METHODS

Creating a new Mustache::Simple object

Parameters:

Configuration Methods

The configuration methods match the %options array thay may be passed to new().

Each option may be called with a non-false value to set the option and will return the new value. If called without a value, it will return the current value.

Instance methods

COMPLIANCE WITH THE STANDARD

The original standard for Mustache was defined at the Mustache Manual and this version of Mustache::Simple was designed to comply with just that. Since then, the standard for Mustache seems to be defined by the Mustache Spec.

The test suite on this version skips a number of tests in the Spec, all of which relate to Decimals or White Space. It passes all the other tests. The YAML from the Spec is built into the test suite.

BUGS

EXPORTS

Nothing.

SEE ALSO

Template::Mustache - a much more complex module that is designed to be subclassed for each template.

AUTHOR INFORMATION

Cliff Stanford <cliff@may.be>

SOURCE REPOSITORY

The source is maintained at a public Github repository at https://github.com/CliffS/mustache-simple. Feel free to fork it and to help me fix some of the above issues. Please leave any bugs or issues on the Issues page and I will be notified.

LICENCE AND COPYRIGHT

Copyright © 2014, Cliff Stanford <cliff@may.be>. All rights reserved.

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