1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<title>Template::Tools::ttree</title>
<link rel="stylesheet" type="text/css" href="../css/blue.css" title="Clear Blue">
<link rel="alternate stylesheet" type="text/css" href="../css/orange.css" title="Clear Orange">
<link rel="alternate stylesheet" type="text/css" href="../css/green.css" title="Clear Green">
<link rel="alternate stylesheet" type="text/css" href="../css/purple.css" title="Clear Purple">
<link rel="alternate stylesheet" type="text/css" href="../css/grey.css" title="Clear Grey">
<link rel="alternate stylesheet" type="text/css" href="../css/print.css" title="Print">
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="../css/ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="../css/ie7.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="../css/print.css" media="print">
<script type="text/javascript" src="../js/tt2.js"></script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="Andy Wardley">
</head>
<body id="body">
<div id="layout">
<div id="header">
<a href="../index.html" id="logo" alt="" title="Click for the Home Page"><span class="alt">TT2 Home Page</span></a>
<ul id="trail">
<li><a href="../tools/index.html">Tools</a></li>
<li class="last"><a href="../tools/ttree.html">ttree</a></li>
</ul>
<div class="controls">
<a href="#" class="menu show" onclick="widescreen_off(); return false" title="Show Menu">
<span class="about">Click to view the menu. It's very nice.</span>
</a>
<a href="#" class="menu hide" onclick="widescreen_on(); return false" title="Hide Menu">
<span class="about">Click to hide the menu and go all widescreen!</span>
</a>
<div class="pager">
<a href="../tools/tpage.html" title="Template::Tools::tpage" class="go back">Back<span class="about"><h4>Template::Tools::tpage</h4>Process templates from command line</span></a>
<a href="../tools/index.html" title="Template::Tools" class="go up">Up<span class="about"><h4>Template::Tools</h4>Command Line Tools for the Template Toolkit</span></a>
<span class="go next">Next<span class="about">Help! I'm stuck on this web page and I can't get off. Please don't go to the next page, help me!</span></span>
</div>
</div>
<h1 class="headline">Template::Tools::ttree</h1>
<h2 class="subhead">Process entire directory trees of templates</h1>
</div>
<div id="page">
<div id="sidebar">
<a href="../index.html" id="logo"></a>
<div id="menu">
<ul class="menu">
<li class="l0 first"><a href="../manual/index.html">Manual</a></li>
<li class="l0"><a href="../modules/index.html">Modules</a></li>
<li class="l0"><a href="../tools/index.html" class="warm">Tools</a></li>
<li class="l1"><a href="../tools/tpage.html">tpage</a></li>
<li class="l1"><a href="../tools/ttree.html" class="warm">ttree</a></li>
<li class="l0"><a href="../tutorial/index.html">Tutorial</a></li>
<li class="l0 last"><a href="../faq/index.html">FAQ</a></li>
</ul>
<div class="foot"></div>
</div>
</div>
<div id="content">
<div class="section">
<div class="head">
<h1 id="contents" onclick="switch_section(this)" title="Click title to show/hide section content.">Contents</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<ul class="toc">
<li class=""><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li class=""><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li class="sub"><a href="#section_The_i_ttreerc_i_Configuration_File">The <i>.ttreerc</i> Configuration File</a></li>
<li class="sub"><a href="#section_Directory_Options">Directory Options</a></li>
<li class="sub"><a href="#section_File_Options">File Options</a></li>
<li class="sub"><a href="#section_Template_Dependencies">Template Dependencies</a></li>
<li class="sub"><a href="#section_Template_Toolkit_Options">Template Toolkit Options</a></li>
<li class=""><a href="#AUTHORS">AUTHORS</a></li>
<li class=""><a href="#COPYRIGHT">COPYRIGHT</a></li>
<li class=""><a href="#SEE_ALSO">SEE ALSO</a></li>
</ul>
</div>
</div>
<div class="pod">
<div class="section">
<div class="head">
<h1 id="SYNOPSIS" onclick="switch_section(this)" title="Click title to show/hide section content.">SYNOPSIS</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<pre>ttree [options] [files]</pre>
</div>
</div>
<div class="section">
<div class="head">
<h1 id="DESCRIPTION" onclick="switch_section(this)" title="Click title to show/hide section content.">DESCRIPTION</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
The <i>ttree</i> 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.
</p>
<p>
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 <i>.ttreerc</i> 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 <code>-f</code> (file) option.
</p>
<div class="subsection">
<div class="head">
<h2 id="section_The_i_ttreerc_i_Configuration_File" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">The <i>.ttreerc</i> Configuration File</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
When you run <i>ttree</i> for the first time it will ask you if you want
it to create a <i>.ttreerc</i> file for you. This will be created in your
home directory.
</p>
<pre>$ ttree
Do you want me to create a sample '.ttreerc' file for you?
(file: /home/abw/.ttreerc) [y/n]: y
/home/abw/.ttreerc created. Please edit accordingly and re-run ttree</pre>
<p>
The purpose of this file is to set any <i>global</i> configuration
options that you want applied <i>every</i> time <i>ttree</i> is run. For
example, you can use the <code>ignore</code> and <code>copy</code> 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 <code>verbose</code> and
<code>recurse</code> according to your preference.
</p>
<p>
A minimal <i>.ttreerc</i>:
</p>
<pre># ignore these files
ignore = \b(CVS|RCS)\b
ignore = ^#
ignore = ~$
# copy these files
copy = \.(gif|png|jpg|pdf)$
# recurse into directories
recurse
# provide info about what's going on
verbose</pre>
<p>
In most cases, you'll want to create a different <i>ttree</i>
configuration file for each project you're working on. The
<code>cfg</code> option allows you to specify a directory where
<i>ttree</i> can find further configuration files.
</p>
<pre>cfg = /home/abw/.ttree</pre>
<p>
The <code>-f</code> 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:
</p>
<pre>$ ttree -f /home/abw/web/example/etc/ttree.cfg
$ ttree -f ./etc/ttree.cfg
$ ttree -f ../etc/ttree.cfg</pre>
<p>
If the configuration file does not begin with <code>/</code> or
<code>.</code> or something that looks like a MS-DOS absolute path (e.g.
<code>C:\\etc\\ttree.cfg</code>) then <i>ttree</i> will look for it in
the directory specified by the <code>cfg</code> option.
</p>
<pre>$ ttree -f test1 # /home/abw/.ttree/test1</pre>
<p>
The <code>cfg</code> option can only be used in the <i>.ttreerc</i> file.
All the other options can be used in the <i>.ttreerc</i> or any other
<i>ttree</i> configuration file. They can all also be specified as
command line options.
</p>
<p>
Remember that <i>.ttreerc</i> is always processed <i>before</i> any
configuration file specified with the <code>-f</code> option. Certain
options like <code>lib</code> can be used any number of times and
accumulate their values.
</p>
<p>
For example, consider the following configuration files:
</p>
<p>
<i>/home/abw/.ttreerc</i>:
</p>
<pre>cfg = /home/abw/.ttree
lib = /usr/local/tt2/templates</pre>
<p>
<i>/home/abw/.ttree/myconfig</i>:
</p>
<pre>lib = /home/abw/web/example/templates/lib</pre>
<p>
When <i>ttree</i> is invoked as follows:
</p>
<pre>$ ttree -f myconfig</pre>
<p>
the <code>lib</code> option will be set to the following directories:
</p>
<pre>/usr/local/tt2/templates
/home/abw/web/example/templates/lib</pre>
<p>
Any templates located under <i>/usr/local/tt2/templates</i> will be used
in preference to those located under
<i>/home/abw/web/example/templates/lib</i>. This may be what you want,
but then again, it might not. For this reason, it is good practice to
keep the <i>.ttreerc</i> as simple as possible and use different
configuration files for each <i>ttree</i> project.
</p>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="section_Directory_Options" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Directory Options</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
The <code>src</code> 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:
</p>
<pre>src = /home/abw/web/example/templates/src</pre>
<p>
Each template in this directory typically corresponds to a single web
page or other document.
</p>
<p>
The <code>dest</code> option is used to specify the destination directory
for the generated output.
</p>
<pre>dest = /home/abw/web/example/html</pre>
<p>
The <code>lib</code> 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.
</p>
<pre>lib = /home/abw/web/example/templates/lib
lib = /usr/local/tt2/templates</pre>
<p>
The <code>lib</code> option can be used repeatedly to add further
directories to the search path.
</p>
<p>
A list of templates can be passed to <i>ttree</i> as command line
arguments.
</p>
<pre>$ ttree foo.html bar.html</pre>
<p>
It looks for these templates in the <code>src</code> directory and
processes them through the Template Toolkit, using any additional
template components from the <code>lib</code> directories. The generated
output is then written to the corresponding file in the <code>dest</code>
directory.
</p>
<p>
If <i>ttree</i> is invoked without explicitly specifying any templates to
be processed then it will process every file in the <code>src</code>
directory. If the <code>-r</code> (recurse) option is set then it will
additionally iterate down through sub-directories and process and other
template files it finds therein.
</p>
<pre>$ ttree -r</pre>
<p>
If a template has been processed previously, <i>ttree</i> 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 <i>ttree</i> will not process it. The
<i>-a</i> (all) option can be used to force <i>ttree</i> to process all
files regardless of modification time.
</p>
<pre>$ tree -a</pre>
<p>
Any templates explicitly named as command line argument are always
processed and the modification time checking is bypassed.
</p>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="section_File_Options" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">File Options</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
The <code>ignore</code>, <code>copy</code> and <code>accept</code>
options are used to specify Perl regexen to filter file names. Files that
match any of the <code>ignore</code> options will not be processed.
Remaining files that match any of the <code>copy</code> regexen will be
copied to the destination directory. Remaining files that then match any
of the <code>accept</code> criteria are then processed via the Template
Toolkit. If no <code>accept</code> parameter is specified then all files
will be accepted for processing if not already copied or ignored.
</p>
<pre># ignore these files
ignore = \b(CVS|RCS)\b
ignore = ^#
ignore = ~$
# copy these files
copy = \.(gif|png|jpg|pdf)$
# accept only .tt2 templates
accept = \.tt2$</pre>
<p>
The <code>suffix</code> 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
<code>.tt2</code> suffix should be output as <code>.html</code> files:
</p>
<pre>suffix tt2=html</pre>
<p>
Or on the command line,
</p>
<pre>--suffix tt2=html</pre>
<p>
You can provide any number of different suffix mappings by repeating this
option.
</p>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="section_Template_Dependencies" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Template Dependencies</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
The <code>depend</code> and <code>depend_file</code> options allow you to
specify how any given template file depends on another file or group of
files. The <code>depend</code> option is used to express a single
dependency.
</p>
<pre>$ ttree --depend foo=bar,baz</pre>
<p>
This command line example shows the <code>--depend</code> option being
used to specify that the <i>foo</i> file is dependant on the <i>bar</i>
and <i>baz</i> templates. This option can be used many time on the
command line:
</p>
<pre>$ ttree --depend foo=bar,baz --depend crash=bang,wallop</pre>
<p>
or in a configuration file:
</p>
<pre>depend foo=bar,baz
depend crash=bang,wallop</pre>
<p>
The file appearing on the left of the <code>=</code> is specified
relative to the <code>src</code> or <code>lib</code> directories. The
file(s) appearing on the right can be specified relative to any of these
directories or as absolute file paths.
</p>
<p>
For example:
</p>
<pre>$ ttree --depend foo=bar,/tmp/baz</pre>
<p>
To define a dependency that applies to all files, use <code>*</code> on
the left of the <code>=</code>.
</p>
<pre>$ ttree --depend *=header,footer</pre>
<p>
or in a configuration file:
</p>
<pre>depend *=header,footer</pre>
<p>
Any templates that are defined in the <code>pre_process</code>,
<code>post_process</code>, <code>process</code> or <code>wrapper</code>
options will automatically be added to the list of global dependencies
that apply to all templates.
</p>
<p>
The <code>depend_file</code> option can be used to specify a file that
contains dependency information.
</p>
<pre>$ ttree --depend_file=/home/abw/web/example/etc/ttree.dep</pre>
<p>
Here is an example of a dependency file:
</p>
<pre># 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 \
sidebar searchform</pre>
<p>
Lines beginning with the <code>#</code> 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 <code>\</code> character are continued onto
the following line.
</p>
<p>
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.
</p>
<p>
As with the command line options, the <code>*</code> character can be
used as a wildcard to specify a dependency for all templates.
</p>
<pre>* : config,header</pre>
</div>
</div> <div class="subsection">
<div class="head">
<h2 id="section_Template_Toolkit_Options" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Template Toolkit Options</h2>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
<i>ttree</i> also provides access to the usual range of Template Toolkit
options. For example, the <code>--pre_chomp</code> and
<code>--post_chomp</code> <i>ttree</i> options correspond to the
<code>PRE_CHOMP</code> and <code>POST_CHOMP</code> options.
</p>
<p>
Run <code>ttree -h</code> for a summary of the options available.
</p>
</div>
</div>
</div>
</div>
<div class="section">
<div class="head">
<h1 id="AUTHORS" onclick="switch_section(this)" title="Click title to show/hide section content.">AUTHORS</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
Andy Wardley <abw@wardley.org>
</p>
<p>
<a href="http://www.wardley.org">http://www.wardley.org</a>
</p>
<p>
With contributions from Dylan William Hardison (support for
dependencies), Bryce Harrington (<code>absolute</code> and
<code>relative</code> options), Mark Anderson (<code>suffix</code> and
<code>debug</code> options), Harald Joerg and Leon Brocard who gets
everywhere, it seems.
</p>
</div>
</div>
<div class="section">
<div class="head">
<h1 id="COPYRIGHT" onclick="switch_section(this)" title="Click title to show/hide section content.">COPYRIGHT</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
</p>
<p>
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
</p>
</div>
</div>
<div class="section">
<div class="head">
<h1 id="SEE_ALSO" onclick="switch_section(this)" title="Click title to show/hide section content.">SEE ALSO</h1>
<a href="#body" class="top" title="Back up to the top of the page" >Top</a>
</div>
<div class="body">
<p>
<a href="#section_tpage">Template::Tools::tpage</a>
</p>
</div>
</div>
</div></div>
<br class="clear" />
<div class="pageinfo">
<a href="http://template-toolkit.org/docs/tools/ttree.html">http://template-toolkit.org/docs/tools/ttree.html</a>
</div>
</div>
<div id="footer">
<a href="http://opensource.org/" class="osi"></a>
<div class="controls">
<div class="pager">
<a href="../tools/tpage.html" title="Template::Tools::tpage" class="go back">Back<span class="about"><h4>Template::Tools::tpage</h4></span></a>
<a href="../tools/index.html" title="Template::Tools" class="go up">Up<span class="about"><h4>Template::Tools</h4></span></a>
<span class="go next">Next<span class="about"></span></span>
</div>
</div>
<div class="copyright">
Copyright © 1996-2012 <a href="http://wardley.org/">Andy Wardley</a>. All Rights Reserved.
</div>
<div class="licence">
The <a href="http://template-toolkit.org/">Template Toolkit</a> is <a href="http://opensource.org/">Open Source</a> software.
You can redistribute and/or modify it under the terms of the <a href="http://www.opensource.org/licenses/gpl-license.php">GNU Public Licence</a>
or the <a href="http://www.opensource.org/licenses/artistic-license.php">Perl Artistic Licence</a>.
</div>
</div>
<div id="palette">
<ul>
<li class="first"><a href="#" class="blue" onclick="set_style('Clear Blue')"></a></li>
<li><a href="#" class="orange" onclick="set_style('Clear Orange')"></a></li>
<li><a href="#" class="green" onclick="set_style('Clear Green')"></a></li>
<li><a href="#" class="purple" onclick="set_style('Clear Purple')"></a></li>
<li><a href="#" class="grey" onclick="set_style('Clear Grey')"></a></li>
</ul>
</div>
</div> </body>
</html>
|