App::TemplateServer - application to serve processed templates
template-server --docroot project/templates --data project/test_data.yml
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
Start the server. This method never returns.
The port to bind the server to. Defaults to 4000.
The directory containing templates. Defaults to the current directory.
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).
As of version 0.02, you can omit the
App::TemplateServer::Provider:: prefix if you prefer. The literal class you pass will be loaded first; if that fails then the
App::TemplateServer::Provider:: prefix is added. Failing that, an exception is thrown.
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
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.
Any key/value pair other than
instantiate is treated as a literal variable to make available in the template.
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.
Copyright (c) 2008 Jonathan Rockway. You may redistribute this module under the same terms as Perl itself.