NAME Template::Flute - Modern designer-friendly HTML templating Engine VERSION Version 0.0009 SYNOPSIS use Template::Flute; my ($cart, $flute, %values); $cart = [{...},{...}]; $values{cost} = ... $flute = new Template::Flute(specification_file => 'cart.xml', template_file => 'cart.html', iterators => {cart => $cart}, values => \%values, ); print $flute->process(); DESCRIPTION Template::Flute enables you to completely separate web design and programming tasks for dynamic web applications. Templates are designed to be designer-friendly; there's no inline code or mini templating language for your designers to learn - instead, standard HTML and CSS classes are used, leading to HTML that can easily be understood and edited by WYSIWYG editors and hand-coding designers alike. An example is easier than a wordy description: Given the following template snippet:
Mr A Test
someone@example.com
and the following specification: Processing the above as follows: $flute = Template::Flute->new( template_file => 'template.html', specification_file => 'spec.xml', ); $flute->set_values({ customer_name => 'Bob McTest', email => 'bob@example.com', });; print $flute->process; The resulting output would be:
Bob McTest
bob@example.com
In other words, rather than including a templating language within your templates which your designers must master and which could interfere with previews in WYSWYG tools, CSS selectors in the template are tied to your data structures or objects by a specification provided by the programmer. Workflow The easiest way to use Template::Flute is to pass all necessary parameters to the constructor and call the process method to generate the HTML. You can also break it down in separate steps: 1. Parse specification Parse specification based on your specification format (e.g with Template::Flute::Specification::XML or Template::Flute::Specification::Scoped.). $xml_spec = new Template::Flute::Specification::XML; $spec = $xml_spec->parse(q{ }); 2. Parse template Parse template with Template::Flute::HTML object. $template = new Template::Flute::HTML; $template->parse(q{ Cart Example
Name Quantity Price
Sample Book $1
Total
$10
}, $spec); 3. Produce HTML output $flute = new Template::Flute(template => $template, iterators => {cart => $cart}, values => {cost => '84.94'}); $flute->process(); CONSTRUCTOR new Create a Template::Flute object with the following parameters: specification_file Specification file name. specification_parser Select specification parser. This can be either the full class name like MyApp::Specification::Parser or the last part for classes residing in the Template::Flute::Specification namespace. specification Specification object or specification as string. template_file HTML template file. template Template::Flute::HTML object or template as string. database Template::Flute::Database::Rose object. filters Hash reference of filter functions. i18n Template::Flute::I18N object. iterators Hash references of iterators. values Hash reference of values to be used by the process method. auto_iterators Builds iterators automatically from values. METHODS process [HASHREF] Processes HTML template, manipulates the HTML tree based on the specification, values and iterators. Returns HTML output. process_template Processes HTML template and returns Template::Flute::HTML object. filter FILTER VALUE Runs the filter named FILTER on VALUE and returns the result. value NAME Returns the value for NAME. set_values HASHREF Sets hash reference of values to be used by the process method. Same as passing the hash reference as values argument to the constructor. template Returns HTML template object. specification Returns specification object. SPECIFICATION The specification ties the elements in the HTML template to the data (variables, lists, forms) which is added to the template. The default format for the specification is XML implemented by the Template::Flute::Specification::XML module. You can use the Config::Scoped format implemented by Template::Flute::Specification::Scoped module or write your own specification parser class. Possible elements in the specification are: container This container is only shown in the output if the value billing_address is set: list param value Value elements are replaced with a single value present in the values hash passed to the constructor of this class or later set with the set_values method. The following operations are supported for value elements: hook Insert HTML residing in value as subtree of the corresponding HTML element. HTML will be parsed with XML::Twig. toggle Only shows corresponding HTML element if value is set. input filter sort i18n ITERATORS Template::Flute uses iterators to retrieve list elements and insert them into the document tree. This abstraction relieves us from worrying about where the data actually comes from. We basically just need an array of hash references and an iterator class with a next and a count method. For your convenience you can create an iterator from Template::Flute::Iterator class very easily. LIST Template::Flute::List FORMS Template::Flute::Form AUTHOR Stefan Hornburg (Racke), BUGS Please report any bugs or feature requests to `bug-template-flute at rt.cpan.org', or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Flute. SUPPORT You can find documentation for this module with the perldoc command. perldoc Template::Flute You can also look for information at: * RT: CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Flute * AnnoCPAN: Annotated CPAN documentation http://annocpan.org/dist/Template-Flute * CPAN Ratings http://cpanratings.perl.org/d/Template-Flute * Search CPAN http://search.cpan.org/dist/Template-Flute/ ACKNOWLEDGEMENTS Thanks to David Previous (bigpresh) for writing a much clearer introduction for Template::Flute. Thanks to Ton Verhagen for being a big supporter of my projects in all aspects. Thanks to Terrence Brannon for spotting a documentation mix-up. HISTORY Template::Flute was initially named Template::Zoom. I renamed the module because of a request from Matt S. Trout, author of the HTML::Zoom module. LICENSE AND COPYRIGHT Copyright 2010-2011 Stefan Hornburg (Racke) . This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information.