ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/doc/gendocs
Revision: 1.5
Committed: Sun Sep 16 18:54:41 2007 UTC (16 years, 8 months ago) by pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
Log Message:
#defines to enum

File Contents

# Content
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use constant rcsid => '$Id: gendocs,v 1.4 2007-08-28 17:08:06 pippijn Exp $';
8
9 BEGIN {
10 unshift @INC, "lib";
11 }
12
13 use Template;
14 use YAML;
15 use Pod::POM;
16 use Pod::Man;
17
18 use PodHTML2;
19
20 $Pod::Man::ESCAPES{xa9} = "(C)";
21
22 # Static variables
23 my $static = YAML::LoadFile "variables.yml";
24 my $parser = new Pod::POM;
25
26 my @podfiles = <poddoc/*.pod>;
27 push @podfiles, '../wwwroot/lib/Ermyth.pm';
28 push @podfiles, '../wwwroot/lib/Ermyth/Accessor.pm';
29 my @servicenames = qw/ChanServ GameServ Global MemoServ NickServ OperServ SaslServ UserServ/;
30
31 my $toplevel = [];
32 for (@servicenames) {
33 push @$toplevel, {
34 href => "../" . lc $_ . ".html",
35 title => $_,
36 };
37 }
38
39 mkdir "ttdoc";
40 mkdir "ttdoc/Ermyth";
41 mkdir "man";
42 mkdir "man/Ermyth";
43 mkdir "html";
44 mkdir "html/Ermyth";
45
46 for my $file (@podfiles) {
47 my (undef, $name) = $file =~ /(poddoc|\.\.\/wwwroot\/lib)\/(.+)\.(pod|pm)$/;
48 my $man = new Pod::Man (
49 release => "Ermyth 2.3",
50 section => 7,
51 center => "Ermyth Documentation",
52 name => "$name",
53 );
54 my $text = do { local $/; open my $fh, "<$file" or die "$file: $!"; <$fh> };
55 $text =~ s/\$/\\\$/g; # XXX: hack because for some reason, the HTML
56 # generator loses all $variablenames
57 my $pom = $parser->parse_text ($text)
58 or die $parser->error();
59 open FH, ">", "ttdoc/$name.tt";
60 print FH $pom->present ("PodHTML2");
61 close FH;
62 $man->parse_from_file ($file, "man/$name.7");
63 }
64
65 my @files = <ttdoc/*.tt>;
66 push @files, <ttdoc/Ermyth/*.tt>;
67
68 for my $file (@files) {
69 my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> };
70 my $subtitle = shift @contents;
71 chomp $subtitle;
72
73 $file =~ s/Ermyth\///; # XXX: hack to get Accessor in the same directory as the rest
74
75 my $tt = Template->new({
76 INCLUDE_PATH => 'lib',
77 INTERPOLATE => 1,
78 POST_CHOMP => 1,
79 EVAL_PERL => 1,
80 }) or die "$Template::ERROR\n";
81
82 my $vars = { file => sub { return do { local $/; open my $fh, "<$_[0]" or die "$_[0]: $!\n"; <$fh> } if $_[0]; } };
83
84 my $contents = "@contents";
85 my $data = ''; # Variable to store processed templates
86 $tt->process(\$contents, $vars, \$data)
87 or die $tt->error();
88
89 # Generate sidemenu
90 my $sidemenu = '';
91 $vars = $static;
92 $tt->process('sidemenu.tt', $vars, \$sidemenu)
93 or die $tt->error(), "\n";
94
95 # Re-initialised with static variables from YAML
96 $vars->{subtitle} = $subtitle;
97 $vars->{contents} = $data;
98 $vars->{sidemenu} = $sidemenu;
99 $vars->{date} = localtime;
100
101 my $output = ''; # Variable to store the complete page
102 $tt->process('html.tt', $vars, \$output)
103 or die $tt->error(), "\n";
104
105 # Save the page to a html file
106 $file =~ s/ttdoc\/(.+)\.tt$/html\/$1.html/;
107 open HTML, ">$file";
108 print HTML $output;
109 close HTML;
110 }
111
112 =head1 AUTHOR
113
114 Copyright © 2007 Pippijn van Steenhoven
115
116 =head1 LICENSE
117
118 This library is free software, you can redistribute it and/or modify
119 it under the terms of the GNU General Public License as documented in COPYING.
120
121 =cut