Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Can I automatically generate documentation from HTML::Template?

by toma (Vicar)
on May 17, 2004 at 02:03 UTC ( [id://353876]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

toma has asked for the wisdom of the Perl Monks concerning the following question:

I have heard that a good reason for using templates is that they can be used to automatically generate documentation. I am using HTML::Template. I use templates within templates. Some templates are used by various different scripts.

I find that it can be difficult to track down how a particular piece of HTML output was generated.

I would like to read some of that autogenerated documentation. How do I create it?

I can imagine an HTML::Template subclass creating annotated HTML which illuminates the generation process. Does such a thing exist, or is there some reason why it doesn't?

It should work perfectly the first time! - toma
  • Comment on Can I automatically generate documentation from HTML::Template?

Replies are listed 'Best First'.
Re: Can I automatically generate documentation from HTML::Template?
by tachyon (Chancellor) on May 17, 2004 at 02:21 UTC

    You can do $t = HTML::Template->new( filename => 'file.tmpl', debug => 1  ); which will write to STDERR ie your server error logs.

    cheers

    tachyon

      This gives me a lot of lines that look something like:
      ### HTML::Template Debug ### /home/toma/audio/dyn6/perllib/EffectBlock /templates/Add.tmpl : line 2 : parsed VAR insig1
      (newlines added)
      but nothing I would consider to be documentation. Am I missing something?
      It should work perfectly the first time! - toma

        Probably have to hack source to take an extra options flag and print the debugging info you want I guess....

        cheers

        tachyon

Re: Can I automatically generate documentation from HTML::Template?
by hv (Prior) on May 17, 2004 at 08:55 UTC

    I'm not familiar with HTML::Template, but it should be trivial, either in code (probably with a minor subclassing) or by hand, to put a marker at the beginning and end of each template:

    <!-- path/to/template --> ... <!-- /path/to/template -->

    Hugo

      When I have templates within templates, this approach is not as useful as I hoped, for large documents at least.

      I would prefer documentation that summarizes the hierarchical HTML structure and the variables used, perhaps even automatically generating diagrams.

      It seems that most general-purpose things like this that I can easily imagine have already been written. Perhaps another templating system has such a feature? If not, I can take care of it.

      It should work perfectly the first time! - toma

        If I understand you correctly, you want a central repository that contains the variables used in each template file. I don't know of any current tools for this. It shouldn't be too difficult, though. HTML::Template->param() in list context returns the names of all variables in the template. This may suffice for your purposes.

        ----
        : () { :|:& };:

        Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://353876]
Approved by blokhead
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.