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