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