Towards generic table.
[irspy-moved-to-github.git] / web / htdocs / details / doc.mc
1 %# $Id: doc.mc,v 1.1 2006-09-28 16:48:20 mike Exp $
2 <%once>
3 use Pod::Html;
4 use IO::Dir;
5 </%once>
6 <%perl>
7 my $module = $r->param("module");
8 if (!defined $module) {
9     print "     <ul>\n";
10     render_doc_links($LIBDIR, "ZOOM", 6);
11     print "     </ul>\n";
12 } else {
13     print "<b>Documentation for '$module'</b>\n";
14     { my $dir = "/tmp/pod2html"; mkdir $dir; chdir $dir || die $!; }
15     # For some reason, output to standard output doesn't appear
16     my $name = "ZOOM.html";
17     pod2html("$LIBDIR/$module", "--outfile=$name");
18     open F, "<$name" or die "can't open '$name': $!";
19     my $text = join("", <F>);
20     close F;
21     $text =~ s/.*?<body.*?>//gs;
22     $text =~ s/<\/body.*//gs;
23     print $text;
24 }
25
26 sub render_doc_links {
27     my($base, $dir, $level) = @_;
28
29     my $dh = new IO::Dir("$base/$dir")
30         or die "can't open directory handle for '$base/$dir'";
31
32     print " " x $level, "<li><b>$dir</b></li>\n";
33     print " " x $level, "<ul>\n";
34
35     my(@files, @dirs);
36     while (my $file = $dh->read()) {
37         if ($file eq "." || $file eq ".." || $file eq "CVS") {
38             next;
39         } elsif (-d "$base/$dir/$file") {
40             push @dirs, $file;
41         } else {
42             push @files, $file;
43         }
44     }
45
46     foreach my $file (sort @files) {
47         print(" " x $level,
48               qq[ <li><a href="?module=$dir/$file">$file</a></li>\n]);
49     }
50
51     foreach my $file (sort @dirs) {
52         render_doc_links($base, "$dir/$file", $level+1);
53     }
54
55     print " " x $level, "</ul>\n";
56     undef $dh;
57 }
58 </%perl>