Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / Template / Tools / ttree.pod
CommitLineData
3fea05b9 1=head1 NAME
2
3Template::Tools::ttree - Process entire directory trees of templates
4
5=head1 SYNOPSIS
6
7 ttree [options] [files]
8
9=head1 DESCRIPTION
10
11The F<ttree> script is used to process entire directory trees containing
12template files. The resulting output from processing each file is then
13written to a corresponding file in a destination directory. The script
14compares the modification times of source and destination files (where
15they already exist) and processes only those files that have been modified.
16In other words, it is the equivalent of 'make' for the Template Toolkit.
17
18It supports a number of options which can be used to configure
19behaviour, define locations and set Template Toolkit options. The
20script first reads the F<.ttreerc> configuration file in the HOME
21directory, or an alternative file specified in the TTREERC environment
22variable. Then, it processes any command line arguments, including
23any additional configuration files specified via the C<-f> (file)
24option.
25
26=head2 The F<.ttreerc> Configuration File
27
28When you run F<ttree> for the first time it will ask you if you want
29it to create a F<.ttreerc> file for you. This will be created in your
30home directory.
31
32 $ ttree
33 Do you want me to create a sample '.ttreerc' file for you?
34 (file: /home/abw/.ttreerc) [y/n]: y
35 /home/abw/.ttreerc created. Please edit accordingly and re-run ttree
36
37The purpose of this file is to set any I<global> configuration options
38that you want applied I<every> time F<ttree> is run. For example, you
39can use the C<ignore> and C<copy> option to provide regular expressions
40that specify which files should be ignored and which should be copied
41rather than being processed as templates. You may also want to set
42flags like C<verbose> and C<recurse> according to your preference.
43
44A minimal F<.ttreerc>:
45
46 # ignore these files
47 ignore = \b(CVS|RCS)\b
48 ignore = ^#
49 ignore = ~$
50
51 # copy these files
52 copy = \.(gif|png|jpg|pdf)$
53
54 # recurse into directories
55 recurse
56
57 # provide info about what's going on
58 verbose
59
60In most cases, you'll want to create a different F<ttree> configuration
61file for each project you're working on. The C<cfg> option allows you
62to specify a directory where F<ttree> can find further configuration
63files.
64
65 cfg = /home/abw/.ttree
66
67The C<-f> command line option can be used to specify which configuration
68file should be used. You can specify a filename using an absolute or
69relative path:
70
71 $ ttree -f /home/abw/web/example/etc/ttree.cfg
72 $ ttree -f ./etc/ttree.cfg
73 $ ttree -f ../etc/ttree.cfg
74
75If the configuration file does not begin with C</> or C<.> or something
76that looks like a MS-DOS absolute path (e.g. C<C:\\etc\\ttree.cfg>) then
77F<ttree> will look for it in the directory specified by the C<cfg> option.
78
79 $ ttree -f test1 # /home/abw/.ttree/test1
80
81The C<cfg> option can only be used in the F<.ttreerc> file. All the
82other options can be used in the F<.ttreerc> or any other F<ttree>
83configuration file. They can all also be specified as command line
84options.
85
86Remember that F<.ttreerc> is always processed I<before> any
87configuration file specified with the C<-f> option. Certain options
88like C<lib> can be used any number of times and accumulate their values.
89
90For example, consider the following configuration files:
91
92F</home/abw/.ttreerc>:
93
94 cfg = /home/abw/.ttree
95 lib = /usr/local/tt2/templates
96
97F</home/abw/.ttree/myconfig>:
98
99 lib = /home/abw/web/example/templates/lib
100
101When F<ttree> is invoked as follows:
102
103 $ ttree -f myconfig
104
105the C<lib> option will be set to the following directories:
106
107 /usr/local/tt2/templates
108 /home/abw/web/example/templates/lib
109
110Any templates located under F</usr/local/tt2/templates> will be used
111in preference to those located under
112F</home/abw/web/example/templates/lib>. This may be what you want,
113but then again, it might not. For this reason, it is good practice to
114keep the F<.ttreerc> as simple as possible and use different
115configuration files for each F<ttree> project.
116
117=head2 Directory Options
118
119The C<src> option is used to define the directory containing the
120source templates to be processed. It can be provided as a command
121line option or in a configuration file as shown here:
122
123 src = /home/abw/web/example/templates/src
124
125Each template in this directory typically corresponds to a single
126web page or other document.
127
128The C<dest> option is used to specify the destination directory for the
129generated output.
130
131 dest = /home/abw/web/example/html
132
133The C<lib> option is used to define one or more directories containing
134additional library templates. These templates are not documents in
135their own right and typically comprise of smaller, modular components
136like headers, footers and menus that are incorporated into pages templates.
137
138 lib = /home/abw/web/example/templates/lib
139 lib = /usr/local/tt2/templates
140
141The C<lib> option can be used repeatedly to add further directories to
142the search path.
143
144A list of templates can be passed to F<ttree> as command line arguments.
145
146 $ ttree foo.html bar.html
147
148It looks for these templates in the C<src> directory and processes them
149through the Template Toolkit, using any additional template components
150from the C<lib> directories. The generated output is then written to
151the corresponding file in the C<dest> directory.
152
153If F<ttree> is invoked without explicitly specifying any templates
154to be processed then it will process every file in the C<src> directory.
155If the C<-r> (recurse) option is set then it will additionally iterate
156down through sub-directories and process and other template files it finds
157therein.
158
159 $ ttree -r
160
161If a template has been processed previously, F<ttree> will compare the
162modification times of the source and destination files. If the source
163template (or one it is dependant on) has not been modified more
164recently than the generated output file then F<ttree> will not process
165it. The F<-a> (all) option can be used to force F<ttree> to process
166all files regardless of modification time.
167
168 $ tree -a
169
170Any templates explicitly named as command line argument are always
171processed and the modification time checking is bypassed.
172
173=head2 File Options
174
175The C<ignore>, C<copy> and C<accept> options are used to specify Perl
176regexen to filter file names. Files that match any of the C<ignore>
177options will not be processed. Remaining files that match any of the
178C<copy> regexen will be copied to the destination directory. Remaining
179files that then match any of the C<accept> criteria are then processed
180via the Template Toolkit. If no C<accept> parameter is specified then
181all files will be accepted for processing if not already copied or
182ignored.
183
184 # ignore these files
185 ignore = \b(CVS|RCS)\b
186 ignore = ^#
187 ignore = ~$
188
189 # copy these files
190 copy = \.(gif|png|jpg|pdf)$
191
192 # accept only .tt2 templates
193 accept = \.tt2$
194
195The C<suffix> option is used to define mappings between the file
196extensions for source templates and the generated output files. The
197following example specifies that source templates with a C<.tt2>
198suffix should be output as C<.html> files:
199
200 suffix tt2=html
201
202Or on the command line,
203
204 --suffix tt2=html
205
206You can provide any number of different suffix mappings by repeating
207this option.
208
209=head2 Template Dependencies
210
211The C<depend> and C<depend_file> options allow you to specify
212how any given template file depends on another file or group of files.
213The C<depend> option is used to express a single dependency.
214
215 $ ttree --depend foo=bar,baz
216
217This command line example shows the C<--depend> option being used to
218specify that the F<foo> file is dependant on the F<bar> and F<baz>
219templates. This option can be used many time on the command line:
220
221 $ ttree --depend foo=bar,baz --depend crash=bang,wallop
222
223or in a configuration file:
224
225 depend foo=bar,baz
226 depend crash=bang,wallop
227
228The file appearing on the left of the C<=> is specified relative to
229the C<src> or C<lib> directories. The file(s) appearing on the right
230can be specified relative to any of these directories or as absolute
231file paths.
232
233For example:
234
235 $ ttree --depend foo=bar,/tmp/baz
236
237To define a dependency that applies to all files, use C<*> on the
238left of the C<=>.
239
240 $ ttree --depend *=header,footer
241
242or in a configuration file:
243
244 depend *=header,footer
245
246Any templates that are defined in the C<pre_process>, C<post_process>,
247C<process> or C<wrapper> options will automatically be added to the
248list of global dependencies that apply to all templates.
249
250The C<depend_file> option can be used to specify a file that contains
251dependency information.
252
253 $ ttree --depend_file=/home/abw/web/example/etc/ttree.dep
254
255Here is an example of a dependency file:
256
257 # This is a comment. It is ignored.
258
259 index.html: header footer menubar
260
261 header: titlebar hotlinks
262
263 menubar: menuitem
264
265 # spanning multiple lines with the backslash
266 another.html: header footer menubar \
267 sidebar searchform
268
269Lines beginning with the C<#> character are comments and are ignored.
270Blank lines are also ignored. All other lines should provide a
271filename followed by a colon and then a list of dependant files
272separated by whitespace, commas or both. Whitespace around the colon
273is also optional. Lines ending in the C<\> character are continued
274onto the following line.
275
276Files that contain spaces can be quoted. That is only necessary
277for files after the colon (':'). The file before the colon may be
278quoted if it contains a colon.
279
280As with the command line options, the C<*> character can be used
281as a wildcard to specify a dependency for all templates.
282
283 * : config,header
284
285=head2 Template Toolkit Options
286
287F<ttree> also provides access to the usual range of Template Toolkit
288options. For example, the C<--pre_chomp> and C<--post_chomp> F<ttree>
289options correspond to the C<PRE_CHOMP> and C<POST_CHOMP> options.
290
291Run C<ttree -h> for a summary of the options available.
292
293=head1 AUTHORS
294
295Andy Wardley E<lt>abw@wardley.orgE<gt>
296
297L<http://www.wardley.org>
298
299With contributions from Dylan William Hardison (support for
300dependencies), Bryce Harrington (C<absolute> and C<relative> options),
301Mark Anderson (C<suffix> and C<debug> options), Harald Joerg and Leon
302Brocard who gets everywhere, it seems.
303
304=head1 COPYRIGHT
305
306Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
307
308This module is free software; you can redistribute it and/or
309modify it under the same terms as Perl itself.
310
311=head1 SEE ALSO
312
313L<Template::Tools::tpage|tpage>
314