Write index page

Previous: Weave: Write documentation pages ] [ Top: xmlp alpha ] [ Next: Process arguments and open source file ]

Writing the index file is quite simple; we use <project>_index.html as our template, and we have the following tags available: First, the code which will build our item and object indices. Each of these is hardwired to be a bullet point list at the moment; that would be a nice thing to open up to configuration but that sort of enhancement will come later.

The use of the tags hash has to do with the way I do template printing.

The item list has a variable $level which keeps track of the table of contents level. Subitems are indented under their parents. When a non-subitem is encountered and the $level is 1, then we have to terminate the sublevel.
 
$level = 0;
$tags{itemlist} = "<ul>\n";
foreach $item (@items) {
   if (!$level && $parent{$item} ne '') {
      $level = 1;
      $tags{itemlist} .= "<ul>\n";
   }
   if ($level && $parent{$item} eq '') {
      $level = 0;
      $tags{itemlist} .= "</ul>\n";
   }
   $tags{itemlist} .= "<li> <a href=\"$url{$item}\">$label{$item}</a>\n";
}
$tags{itemlist} .= "</ul>\n";
$tags{objectlist} = "<ul>\n";
foreach $obj (@objects) {
   $tags{objectlist} .= "<li> <code>$obj</code>:";
   $tags{objectlist} .= "<a href=\"$url{$starter{$obj}}\">$label{$starter{$obj}}</a>\n";
}
$tags{objectlist} .= "</ul>\n";
Now, to use the bits of HTML we just built, we'll do a template application operation. This looks for tags delimited by [## and ##] and uses the tag name to reference into the %tags hash we used above to store our lists. We'll do the same thing again for writing out our item pages.
 
open OUT, ">index.html";
open TEM, $index_html;
while (<TEM>) {
   while (/\[##(.*?)##\]/) {
      $tag=$1;
      s/\[##$tag##\]/$tags{$tag}/e;
   }
   print OUT;
}
close TEM;
close OUT;

Previous: Weave: Write documentation pages ] [ Top: xmlp alpha ] [ Next: Process arguments and open source file ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.