.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Template::Tools::ttree 3" .TH Template::Tools::ttree 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Template::Tools::ttree \- Process entire directory trees of templates .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& ttree [options] [files] .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The \fIttree\fR script is used to process entire directory trees containing template files. The resulting output from processing each file is then written to a corresponding file in a destination directory. The script compares the modification times of source and destination files (where they already exist) and processes only those files that have been modified. In other words, it is the equivalent of 'make' for the Template Toolkit. .PP It supports a number of options which can be used to configure behaviour, define locations and set Template Toolkit options. The script first reads the \fI.ttreerc\fR configuration file in the HOME directory, or an alternative file specified in the TTREERC environment variable. Then, it processes any command line arguments, including any additional configuration files specified via the \f(CW\*(C`\-f\*(C'\fR (file) option. .SS "The \fI.ttreerc\fP Configuration File" .IX Subsection "The .ttreerc Configuration File" When you run \fIttree\fR for the first time it will ask you if you want it to create a \fI.ttreerc\fR file for you. This will be created in your home directory. .PP .Vb 4 \& $ ttree \& Do you want me to create a sample \*(Aq.ttreerc\*(Aq file for you? \& (file: /home/abw/.ttreerc) [y/n]: y \& /home/abw/.ttreerc created. Please edit accordingly and re\-run ttree .Ve .PP The purpose of this file is to set any \fIglobal\fR configuration options that you want applied \fIevery\fR time \fIttree\fR is run. For example, you can use the \f(CW\*(C`ignore\*(C'\fR and \f(CW\*(C`copy\*(C'\fR option to provide regular expressions that specify which files should be ignored and which should be copied rather than being processed as templates. You may also want to set flags like \f(CW\*(C`verbose\*(C'\fR and \f(CW\*(C`recurse\*(C'\fR according to your preference. .PP A minimal \fI.ttreerc\fR: .PP .Vb 4 \& # ignore these files \& ignore = \eb(CVS|RCS)\eb \& ignore = ^# \& ignore = ~$ \& \& # copy these files \& copy = \e.(gif|png|jpg|pdf)$ \& \& # recurse into directories \& recurse \& \& # provide info about what\*(Aqs going on \& verbose .Ve .PP In most cases, you'll want to create a different \fIttree\fR configuration file for each project you're working on. The \f(CW\*(C`cfg\*(C'\fR option allows you to specify a directory where \fIttree\fR can find further configuration files. .PP .Vb 1 \& cfg = /home/abw/.ttree .Ve .PP The \f(CW\*(C`\-f\*(C'\fR command line option can be used to specify which configuration file should be used. You can specify a filename using an absolute or relative path: .PP .Vb 3 \& $ ttree \-f /home/abw/web/example/etc/ttree.cfg \& $ ttree \-f ./etc/ttree.cfg \& $ ttree \-f ../etc/ttree.cfg .Ve .PP If the configuration file does not begin with \f(CW\*(C`/\*(C'\fR or \f(CW\*(C`.\*(C'\fR or something that looks like a MS-DOS absolute path (e.g. \f(CW\*(C`C:\e\eetc\e\ettree.cfg\*(C'\fR) then \&\fIttree\fR will look for it in the directory specified by the \f(CW\*(C`cfg\*(C'\fR option. .PP .Vb 1 \& $ ttree \-f test1 # /home/abw/.ttree/test1 .Ve .PP The \f(CW\*(C`cfg\*(C'\fR option can only be used in the \fI.ttreerc\fR file. All the other options can be used in the \fI.ttreerc\fR or any other \fIttree\fR configuration file. They can all also be specified as command line options. .PP Remember that \fI.ttreerc\fR is always processed \fIbefore\fR any configuration file specified with the \f(CW\*(C`\-f\*(C'\fR option. Certain options like \f(CW\*(C`lib\*(C'\fR can be used any number of times and accumulate their values. .PP For example, consider the following configuration files: .PP \&\fI/home/abw/.ttreerc\fR: .PP .Vb 2 \& cfg = /home/abw/.ttree \& lib = /usr/local/tt2/templates .Ve .PP \&\fI/home/abw/.ttree/myconfig\fR: .PP .Vb 1 \& lib = /home/abw/web/example/templates/lib .Ve .PP When \fIttree\fR is invoked as follows: .PP .Vb 1 \& $ ttree \-f myconfig .Ve .PP the \f(CW\*(C`lib\*(C'\fR option will be set to the following directories: .PP .Vb 2 \& /usr/local/tt2/templates \& /home/abw/web/example/templates/lib .Ve .PP Any templates located under \fI/usr/local/tt2/templates\fR will be used in preference to those located under \&\fI/home/abw/web/example/templates/lib\fR. This may be what you want, but then again, it might not. For this reason, it is good practice to keep the \fI.ttreerc\fR as simple as possible and use different configuration files for each \fIttree\fR project. .SS "Directory Options" .IX Subsection "Directory Options" The \f(CW\*(C`src\*(C'\fR option is used to define the directory containing the source templates to be processed. It can be provided as a command line option or in a configuration file as shown here: .PP .Vb 1 \& src = /home/abw/web/example/templates/src .Ve .PP Each template in this directory typically corresponds to a single web page or other document. .PP The \f(CW\*(C`dest\*(C'\fR option is used to specify the destination directory for the generated output. .PP .Vb 1 \& dest = /home/abw/web/example/html .Ve .PP The \f(CW\*(C`lib\*(C'\fR option is used to define one or more directories containing additional library templates. These templates are not documents in their own right and typically comprise of smaller, modular components like headers, footers and menus that are incorporated into pages templates. .PP .Vb 2 \& lib = /home/abw/web/example/templates/lib \& lib = /usr/local/tt2/templates .Ve .PP The \f(CW\*(C`lib\*(C'\fR option can be used repeatedly to add further directories to the search path. .PP A list of templates can be passed to \fIttree\fR as command line arguments. .PP .Vb 1 \& $ ttree foo.html bar.html .Ve .PP It looks for these templates in the \f(CW\*(C`src\*(C'\fR directory and processes them through the Template Toolkit, using any additional template components from the \f(CW\*(C`lib\*(C'\fR directories. The generated output is then written to the corresponding file in the \f(CW\*(C`dest\*(C'\fR directory. .PP If \fIttree\fR is invoked without explicitly specifying any templates to be processed then it will process every file in the \f(CW\*(C`src\*(C'\fR directory. If the \f(CW\*(C`\-r\*(C'\fR (recurse) option is set then it will additionally iterate down through sub-directories and process and other template files it finds therein. .PP .Vb 1 \& $ ttree \-r .Ve .PP If a template has been processed previously, \fIttree\fR will compare the modification times of the source and destination files. If the source template (or one it is dependant on) has not been modified more recently than the generated output file then \fIttree\fR will not process it. The \fI\-a\fR (all) option can be used to force \fIttree\fR to process all files regardless of modification time. .PP .Vb 1 \& $ ttree \-a .Ve .PP Any templates explicitly named as command line argument are always processed and the modification time checking is bypassed. .SS "File Options" .IX Subsection "File Options" The \f(CW\*(C`ignore\*(C'\fR, \f(CW\*(C`copy\*(C'\fR and \f(CW\*(C`accept\*(C'\fR options are used to specify Perl regexen to filter file names. Files that match any of the \f(CW\*(C`ignore\*(C'\fR options will not be processed. Remaining files that match any of the \&\f(CW\*(C`copy\*(C'\fR regexen will be copied to the destination directory. Remaining files that then match any of the \f(CW\*(C`accept\*(C'\fR criteria are then processed via the Template Toolkit. If no \f(CW\*(C`accept\*(C'\fR parameter is specified then all files will be accepted for processing if not already copied or ignored. .PP .Vb 4 \& # ignore these files \& ignore = \eb(CVS|RCS)\eb \& ignore = ^# \& ignore = ~$ \& \& # copy these files \& copy = \e.(gif|png|jpg|pdf)$ \& \& # accept only .tt2 templates \& accept = \e.tt2$ .Ve .PP The \f(CW\*(C`suffix\*(C'\fR option is used to define mappings between the file extensions for source templates and the generated output files. The following example specifies that source templates with a \f(CW\*(C`.tt2\*(C'\fR suffix should be output as \f(CW\*(C`.html\*(C'\fR files: .PP .Vb 1 \& suffix tt2=html .Ve .PP Or on the command line, .PP .Vb 1 \& \-\-suffix tt2=html .Ve .PP You can provide any number of different suffix mappings by repeating this option. .SS "Template Dependencies" .IX Subsection "Template Dependencies" The \f(CW\*(C`depend\*(C'\fR and \f(CW\*(C`depend_file\*(C'\fR options allow you to specify how any given template file depends on another file or group of files. The \f(CW\*(C`depend\*(C'\fR option is used to express a single dependency. .PP .Vb 1 \& $ ttree \-\-depend foo=bar,baz .Ve .PP This command line example shows the \f(CW\*(C`\-\-depend\*(C'\fR option being used to specify that the \fIfoo\fR file is dependant on the \fIbar\fR and \fIbaz\fR templates. This option can be used many time on the command line: .PP .Vb 1 \& $ ttree \-\-depend foo=bar,baz \-\-depend crash=bang,wallop .Ve .PP or in a configuration file: .PP .Vb 2 \& depend foo=bar,baz \& depend crash=bang,wallop .Ve .PP The file appearing on the left of the \f(CW\*(C`=\*(C'\fR is specified relative to the \f(CW\*(C`src\*(C'\fR or \f(CW\*(C`lib\*(C'\fR directories. The file(s) appearing on the right can be specified relative to any of these directories or as absolute file paths. .PP For example: .PP .Vb 1 \& $ ttree \-\-depend foo=bar,/tmp/baz .Ve .PP To define a dependency that applies to all files, use \f(CW\*(C`*\*(C'\fR on the left of the \f(CW\*(C`=\*(C'\fR. .PP .Vb 1 \& $ ttree \-\-depend *=header,footer .Ve .PP or in a configuration file: .PP .Vb 1 \& depend *=header,footer .Ve .PP Any templates that are defined in the \f(CW\*(C`pre_process\*(C'\fR, \f(CW\*(C`post_process\*(C'\fR, \&\f(CW\*(C`process\*(C'\fR or \f(CW\*(C`wrapper\*(C'\fR options will automatically be added to the list of global dependencies that apply to all templates. .PP The \f(CW\*(C`depend_file\*(C'\fR option can be used to specify a file that contains dependency information. .PP .Vb 1 \& $ ttree \-\-depend_file=/home/abw/web/example/etc/ttree.dep .Ve .PP Here is an example of a dependency file: .PP .Vb 1 \& # This is a comment. It is ignored. \& \& index.html: header footer menubar \& \& header: titlebar hotlinks \& \& menubar: menuitem \& \& # spanning multiple lines with the backslash \& another.html: header footer menubar \e \& sidebar searchform .Ve .PP Lines beginning with the \f(CW\*(C`#\*(C'\fR character are comments and are ignored. Blank lines are also ignored. All other lines should provide a filename followed by a colon and then a list of dependant files separated by whitespace, commas or both. Whitespace around the colon is also optional. Lines ending in the \f(CW\*(C`\e\*(C'\fR character are continued onto the following line. .PP Files that contain spaces can be quoted. That is only necessary for files after the colon (':'). The file before the colon may be quoted if it contains a colon. .PP As with the command line options, the \f(CW\*(C`*\*(C'\fR character can be used as a wildcard to specify a dependency for all templates. .PP .Vb 1 \& * : config,header .Ve .SS "Template Toolkit Options" .IX Subsection "Template Toolkit Options" \&\fIttree\fR also provides access to the usual range of Template Toolkit options. For example, the \f(CW\*(C`\-\-pre_chomp\*(C'\fR and \f(CW\*(C`\-\-post_chomp\*(C'\fR \fIttree\fR options correspond to the \f(CW\*(C`PRE_CHOMP\*(C'\fR and \f(CW\*(C`POST_CHOMP\*(C'\fR options. .PP Run \f(CW\*(C`ttree \-h\*(C'\fR for a summary of the options available. .SH AUTHORS .IX Header "AUTHORS" Andy Wardley .PP .PP With contributions from Dylan William Hardison (support for dependencies), Bryce Harrington (\f(CW\*(C`absolute\*(C'\fR and \f(CW\*(C`relative\*(C'\fR options), Mark Anderson (\f(CW\*(C`suffix\*(C'\fR and \f(CW\*(C`debug\*(C'\fR options), Harald Joerg and Leon Brocard who gets everywhere, it seems. .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (C) 1996\-2007 Andy Wardley. All Rights Reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" Template::Tools::tpage