Zucchini::Template - process templates and output static files
# create a new templater object $templater = Zucchini::Template->new( { config => $self->get_config } ); # process the site $templater->process_site;
This module handles the processing of the template files into the website source files.
The solution uses Template::Toolkit and tries to Be Smart - only process that which has changed.
An exception to this is when a globally included file, for example header.tt, has been modified. To apply this change to the site, one must either "touch" all the templates, or use the 'force' option.
# force all html files to be regenerated $ find . -name \*html -exec touch {} \; $ zucchini # brute force approach to regenerate all files $ zucchini --force
Creates a new instance of the top-level Zucchini object:
# create a new templater object $templater = Zucchini::Template->new( { config => $zucchini->get_config, } );
Gets appropriate site-config, and initiates the template-processing.
# start the templating... $templater->process_site;
Returns/sets an object representing the current configuration.
# get the current configuration $self->get_config; # get the source_dir from the configuration object $directory = $self->get_config->get_siteconfig->{source_dir};
Returns/sets the Template Toolkit object:
# process the current item $self->get_ttobject->process( $template, \%data, $output_file );
Perform the appropriate action for each item in the given directory: template or copy files; recurse directories. Ignore anything that should be ignored, as per the site-config.
# set off a cascading processing of the templates $templater->process_directory( $template_root_directory );
Get a list of everything (except . and ..) in the given directory.
# get items in the site root @list = $templater->directory_contents( $template_root_directory );
Calculate an MD5 checksum for a given file.
# get a checksum $checksum = $templater->file_checksum( $file );
Given two files - a template file and its templated output - determine if the template has been modified since the output was last generated.
# do something with a changed template if ($self->file_modified($template, $output)) { # do stuff }
Given a directory, determine if it should be ignored; useful for CVS/ and .svn/ directories. Uses 'ignored_dirs' from site-config.
# don't do anything with ignored directories if ($self->ignore_directory($dir)) { # next }
Given a file, determine if it should be ignored; useful for editor swap files. Uses 'ignore_files' from site-config.
# don't do anything with ignored files if ($self->ignore_file($file)) { # next }
Returns a filename, optionally formatted to include the full (destination) path if 'showpath' option is active.
# tell the user where we're putting something print "Writing: " . $self->item_name($dir, $file) . "\n";
Given a file take one of the following actions: template it, copy it, ignore it.
# process the current file $self->process_file($dir, $file)
This catchily named function returns the relative path to a directory, from the template source dir; 'source_dir' in the site-config.
# get the relative path ... $relpath = $self->relative_path_from_full( $dir );
Determine if two files are the same. Primarily used to avoid copying unchanged files.
if(not $self->same_file($file1, $file2)) { # do stuff }
If the 'showdestination' option is active, output where we are writing a file to.
# let user know where we're putting the item $self->show_destination($directory, $item);
Detemine if the file should be treated as a template. Template files are specified by the 'template_files' variable in the site-config.
if ($self->template_file($item)) { # do some templating magic }
Zucchini, Zucchini::Config
Chisel Wright <chiselwright@users.berlios.de>
<chiselwright@users.berlios.de>
Copyright 2008 by Chisel Wright
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
To install Zucchini, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Zucchini
CPAN shell
perl -MCPAN -e shell install Zucchini
For more information on module installation, please visit the detailed CPAN module installation guide.