NAME
Template::Mustache - Drawing Mustaches on Perl for fun and profit
VERSION
version 0.5.6
SYNOPSIS
use Template::Mustache;
print Template::Mustache->render(
"Hello {{planet}}", {planet => "World!"}), "\n";
DESCRIPTION
Template::Mustache is an implementation of the fabulous Mustache templating language for Perl 5.8 and later.
See http://mustache.github.com.
Functions
- build_pattern($otag, $ctag)
-
Constructs a new regular expression, to be used in the parsing of Mustache templates.
Returns a regular expression that will match tags with the specified delimiters.
- read_file($filename)
-
Reads a file into a string, returning the empty string if the file does not exist.
Returns the contents of the given filename, or the empty string.
- parse($tmpl, [$delims, [$section, $start]])
-
Can be called in one of three forms:
- parse($tmpl)
-
Creates an AST from the given template.
An array reference to the AST represented by the given template.
- parse($tmpl, $delims)
-
Creates an AST from the given template, with non-standard delimiters.
- $tmpl
-
The template to parse.
- $delims
-
An array reference to the delimiter pair with which to begin parsing.
Returns an array reference to the AST represented by the given template.
- parse($tmpl, $delims, $section, $start)
-
Parses out a section tag from the given template.
- $tmpl
-
The template to parse.
- $delims
-
An array reference to the delimiter pair with which to begin parsing.
- $section
-
The name of the section we're parsing.
- $start
-
The index of the first character of the section.
Returns an array reference to the raw text of the section (first element), and the index of the character immediately following the close section tag (last element).
- generate($parse_tree, $partials, @context)
-
Produces an expanded version of the template represented by the given parse tree.
- $parse_tree
-
The AST of a Mustache template.
- $partials
-
A subroutine that looks up partials by name.
- @context
-
The context stack to perform key lookups against.
Returns the fully rendered template as a string.
- lookup($field, @context)
-
Performs a lookup of a
$fieldin a context stack.Returns the context element and value for the given
$field.
Methods
- new(%args)
-
Standard hash constructor.
Returns A new
Template::Mustacheinstance. - template_path
-
Filesystem path for template and partial lookups.
Returns a string containing the template path (defaults to '.').
- template_extension
-
File extension for templates and partials.
Returns the file extension as a string (defaults to 'mustache').
- template_namespace
-
Package namespace to ignore during template lookups.
As an example, if you subclass
Template::Mustacheas the classMy::Heavily::Namepaced::Views::SomeView, calls torenderwill automatically try to load the template./My/Heavily/Namespaced/Views/SomeView.mustacheunder thetemplate_path. Since views will very frequently all live in a common namespace, you can override this method in your subclass, and save yourself some headaches.Setting template_namespace to: yields template name: My::Heavily::Namespaced::Views => SomeView.mustache My::Heavily::Namespaced => Views/SomeView.mustache Heavily::Namespaced => My/Heavily/Namespaced/Views/SomeView.mustacheAs noted by the last example, namespaces will only be removed from the beginning of the package name.
Returns the empty string.
- template_file
-
The template filename to read. The filename follows standard Perl module lookup practices (e.g.
My::ModulebecomesMy/Module.pm) with the following differences:Templates have the extension given by
template_extension('mustache' by default).Templates will have
template_namespaceremoved, if it appears at the beginning of the package name.Template filename resolution will short circuit if
$Template::Mustache::template_fileis set.Template filename resolution may be overriden in subclasses.
Template files will be resolved against
template_path, not$PERL5LIB.
Returns The path to the template file, relative to
template_pathas a string. See template. - template
-
Reads the template off disk.
Returns the contents of the
template_fileundertemplate_path. - partial($name)
-
Reads a named partial off disk.
Returns the contents of the partial (in
template_pathof typetemplate_extension), or the empty string, if the partial does not exist. - render
-
Render a class or instances data, in each case returning the fully rendered template as a string; can be called in one of the following forms:
- render()
-
Renders a class or instance's template with data from the receiver. The template will be retrieved by calling the
templatemethod. Partials will be fetched bypartial. - render($tmpl)
-
Renders the given template with data from the receiver. Partials will be fetched by
partial. - render($data)
-
Renders a class or instance's template with data from the receiver. The template will be retrieved by calling the
templatemethod. Partials will be fetched bypartial. - render($tmpl, $data)
-
Renders the given template with the given data. Partials will be fetched by
partial. - render($tmpl, $data, $partials)
-
Renders the given template with the given data. Partials will be looked up by calling the given code reference with the partial's name.
- render($tmpl, $data, $partials)
-
Renders the given template with the given data. Partials will be looked up by calling the partial's name as a method on the given class or object.
- render($tmpl, $data, $partials)
-
Renders the given template with the given data. Partials will be looked up in the given hash.
AUTHORS
Pieter van de Bruggen <pvande@cpan.org>
Yanick Champoux <yanick@cpan.org>
Ricardo Signes <rjbs@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Pieter van de Bruggen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.