[Templates] TT and dependencies

Andy Wardley abw@andywardley.com
Tue, 14 Oct 2003 10:11:36 +0100


Perrin Harkins wrote:
> I think the INLCUDE/PROCESS stuff is covered by the recent work, 
> although I haven't been watching it closely.  

Just to clarify, the recent enhancements to ttree allow it to now check
a whole list of dependant templates to see if any have changed rather 
than just checking the single page template.

However, it's up to you to tell it which templates depend on which other
templates, either through the --depend or --depend_file options.

  $ ttree --depend index.html=header,footer,menu

What it can't do it work out for itself which templates are dependant on
which other files.  The reason is that the language is dynamically 
interpreted:

  [% INCLUDE "$dir/$file" %]

Without processing the template with live data, there's no way of knowing 
which template that INCLUDE directive will end up including.

The depend options will accept absolute filenames, and the targets don't
have to be templates.  So you can do something like this:

  $ ttree --depend_file ttree.dep

ttree.dep:
  *          : header,footer,menu
  index.html : headlines
  news.html  : news/header, news/menu, \
               /home/abw/web/example/xml/news.rdf \
               /home/abw/web/example/plugin/News.pm 

Any pre_process, process, post_process or wrapper templates are automatically 
added to the list of dependants, as of course is the source page template.
But apart from that, it's up to you to generate dependencies.

It would be nice if you could run ttree through once and have TT keep 
track of all the templates used, and then generate a dependency file for
you.  Of course, it wouldn't work in those dynamic cases like that shown
above and the results might need to be tweaked by hand, but at least most
of the grunt work would have been done.

This could probably be bodged onto TT2.  I'm looking into it.  And 
it's definately something that will be in TT3.

But for now, although you have to build the dependency file by hand, 
there is at least a way of specify dependencies, even down to individual
non-template files.

Kudos to Dylan William Hardison who provided the enhancements to ttree.

A