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. Files that reside in any of the "copy_dir"
177 directories are also copied. Remaining files that then match any of
178 the "accept" criteria are then processed via the Template Toolkit. If
179 no "accept" parameter is specified then all files will be accepted for
180 processing if not already copied or ignored.
181
182 # ignore these files
183 ignore = \b(CVS|RCS)\b
184 ignore = ^#
185 ignore = ~$
186
187 # copy these files
188 copy = \.(gif|png|jpg|pdf)$
189
190 # accept only .tt2 templates
191 accept = \.tt2$
192
193 The "suffix" option is used to define mappings between the file
194 extensions for source templates and the generated output files. The
195 following example specifies that source templates with a ".tt2" suffix
196 should be output as ".html" files:
197
198 suffix tt2=html
199
200 Or on the command line,
201
202 --suffix tt2=html
203
204 You can provide any number of different suffix mappings by repeating
205 this option.
206
207 The "binmode" option is used to set the encoding of the output file.
208 For example use "--binmode=:utf8" to set the output format to unicode.
209
210 Template Dependencies
211 The "depend" and "depend_file" options allow you to specify how any
212 given template file depends on another file or group of files. The
213 "depend" option is used to express a single dependency.
214
215 $ ttree --depend foo=bar,baz
216
217 This command line example shows the "--depend" option being used to
218 specify that the foo file is dependant on the bar and baz templates.
219 This option can be used many time on the command line:
220
221 $ ttree --depend foo=bar,baz --depend crash=bang,wallop
222
223 or in a configuration file:
224
225 depend foo=bar,baz
226 depend crash=bang,wallop
227
228 The file appearing on the left of the "=" is specified relative to the
229 "src" or "lib" directories. The file(s) appearing on the right can be
230 specified relative to any of these directories or as absolute file
231 paths.
232
233 For example:
234
235 $ ttree --depend foo=bar,/tmp/baz
236
237 To define a dependency that applies to all files, use "*" on the left
238 of the "=".
239
240 $ ttree --depend *=header,footer
241
242 or in a configuration file:
243
244 depend *=header,footer
245
246 Any templates that are defined in the "pre_process", "post_process",
247 "process" or "wrapper" options will automatically be added to the list
248 of global dependencies that apply to all templates.
249
250 The "depend_file" option can be used to specify a file that contains
251 dependency information.
252
253 $ ttree --depend_file=/home/abw/web/example/etc/ttree.dep
254
255 Here 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
269 Lines beginning with the "#" character are comments and are ignored.
270 Blank lines are also ignored. All other lines should provide a
271 filename followed by a colon and then a list of dependant files
272 separated by whitespace, commas or both. Whitespace around the colon
273 is also optional. Lines ending in the "\" character are continued onto
274 the following line.
275
276 Files that contain spaces can be quoted. That is only necessary for
277 files after the colon (':'). The file before the colon may be quoted if
278 it contains a colon.
279
280 As with the command line options, the "*" character can be used as a
281 wildcard to specify a dependency for all templates.
282
283 * : config,header
284
285 Template Toolkit Options
286 ttree also provides access to the usual range of Template Toolkit
287 options. For example, the "--pre_chomp" and "--post_chomp" ttree
288 options correspond to the "PRE_CHOMP" and "POST_CHOMP" options.
289
290 Run "ttree -h" for a summary of the options available.
291
293 Andy Wardley <abw@andywardley.com>
294
295 <http://www.andywardley.com/>
296
297 With contributions from Dylan William Hardison (support for
298 dependencies), Bryce Harrington ("absolute" and "relative" options),
299 Mark Anderson ("suffix" and "debug" options), Harald Joerg and Leon
300 Brocard who gets everywhere, it seems.
301
303 2.68, distributed as part of the Template Toolkit version 2.19,
304 released on 27 April 2007.
305
307 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
308
309 This module is free software; you can redistribute it and/or modify it
310 under the same terms as Perl itself.
311
313 tpage
314
315
316
317perl v5.34.0 2022-01-21 TTREE(1)