1 |
pippijn |
1.1 |
#!/usr/bin/env perl |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
use utf8; |
6 |
|
|
|
7 |
pippijn |
1.5 |
use constant rcsid => '$Id: gendocs,v 1.4 2007-08-28 17:08:06 pippijn Exp $'; |
8 |
pippijn |
1.2 |
|
9 |
pippijn |
1.1 |
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 |
pippijn |
1.4 |
my $static = YAML::LoadFile "variables.yml"; |
24 |
pippijn |
1.1 |
my $parser = new Pod::POM; |
25 |
|
|
|
26 |
|
|
my @podfiles = <poddoc/*.pod>; |
27 |
pippijn |
1.4 |
push @podfiles, '../wwwroot/lib/Ermyth.pm'; |
28 |
|
|
push @podfiles, '../wwwroot/lib/Ermyth/Accessor.pm'; |
29 |
pippijn |
1.1 |
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 |
pippijn |
1.4 |
mkdir "ttdoc/Ermyth"; |
41 |
pippijn |
1.1 |
mkdir "man"; |
42 |
pippijn |
1.4 |
mkdir "man/Ermyth"; |
43 |
pippijn |
1.1 |
mkdir "html"; |
44 |
pippijn |
1.4 |
mkdir "html/Ermyth"; |
45 |
pippijn |
1.1 |
|
46 |
|
|
for my $file (@podfiles) { |
47 |
pippijn |
1.4 |
my (undef, $name) = $file =~ /(poddoc|\.\.\/wwwroot\/lib)\/(.+)\.(pod|pm)$/; |
48 |
pippijn |
1.1 |
my $man = new Pod::Man ( |
49 |
|
|
release => "Ermyth 2.3", |
50 |
|
|
section => 7, |
51 |
|
|
center => "Ermyth Documentation", |
52 |
|
|
name => "$name", |
53 |
|
|
); |
54 |
pippijn |
1.4 |
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 |
pippijn |
1.1 |
or die $parser->error(); |
59 |
|
|
open FH, ">", "ttdoc/$name.tt"; |
60 |
|
|
print FH $pom->present ("PodHTML2"); |
61 |
|
|
close FH; |
62 |
pippijn |
1.4 |
$man->parse_from_file ($file, "man/$name.7"); |
63 |
pippijn |
1.1 |
} |
64 |
|
|
|
65 |
|
|
my @files = <ttdoc/*.tt>; |
66 |
pippijn |
1.4 |
push @files, <ttdoc/Ermyth/*.tt>; |
67 |
pippijn |
1.1 |
|
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 |
pippijn |
1.4 |
|
73 |
|
|
$file =~ s/Ermyth\///; # XXX: hack to get Accessor in the same directory as the rest |
74 |
pippijn |
1.1 |
|
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 |
pippijn |
1.4 |
$vars->{date} = localtime; |
100 |
pippijn |
1.1 |
|
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 |
pippijn |
1.3 |
|
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 |
pippijn |
1.5 |
it under the terms of the GNU General Public License as documented in COPYING. |
120 |
pippijn |
1.3 |
|
121 |
|
|
=cut |