NAME
App::TemplateServer - application to serve processed templates
SYNOPSIS
template-server --docroot project/templates --data project/test_data.yml
DESCRIPTION
Occasionally you need to give HTML templates to someone to edit without setting up a full perl environment for them. You can use this application to serve templates to the browser and provide those templates with sample data to operate on. The template editor will need Perl, but not a database, Apache, Catalyst, etc. (You can build a PAR and then they won't need Perl either.)
It's also useful for experimenting with new templating engines. You can start writing templates right away, without having to setup Apache or a Catalyst application first. Interfacing App::TemplateServer
to a new templating system is a quick matter of writing a few lines of code. (See App::TemplateServer::Provider for details.)
As a user, you'll be interacting with App::TemplateServer
via the included template-server
script.
METHODS
run
Start the server. This method never returns.
ATTRIBUTES
port
The port to bind the server to. Defaults to 4000.
docroot
The directory containing templates. Defaults to the current directory.
provider_class
The class name of the Provider to use. Defaults to App::TemplateServer::Provider::TT
, but you can get others from the CPAN (for using templating systems other than TT).
datafile
The YAML file containing the package and variable definitions. For example:
---
foo: "bar"
packages:
Test:
constructors: ["new"]
methods:
map_foo_bar:
- ["foo"]
- "bar"
- ["bar"]
- "foo"
- "INVALID INPUT"
instantiate:
test_instance: "Test"
another_test_instance:
- Test: "new"
This makes the variables foo
, test_instance
, and another_test_instance
available in the templates. It also creates a package called Test
and adds a constructor called new
, and a method called map_foo_bar
that returns "bar" when the argument is "foo", "foo" when the argument is "bar", and "INVALID INPUT" otherwise.
DESCRIPTION
Any key/value pair other than packages
and instantiate
is treated as a literal variable to make available in the template.
packages
is passed to Package::FromData and is used to dynamically create data, methods, static methods, and constructors inside packages. See Package::FromData for more details.
instantiate
is a list of variables to populate with instantiated classes. The key is the variable name, the value is either a class name to call new on, or a hash containing a single key/value pair which is treated like class => method
. This allows you to use the constructors that Package::FromData made for you.
AUTHOR
Jonathan Rockway <jrockway@cpan.org>
COPYRIGHT
Copyright (c) 2008 Jonathan Rockway. You may redistribute this module under the same terms as Perl itself.