home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / ttree.pod < prev    next >
Encoding:
Text File  |  2004-01-30  |  11.1 KB  |  333 lines

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