#!/usr/bin/env perl use strict; use warnings; use utf8; use constant rcsid => '$Id: gendocs,v 1.4 2007/08/28 17:08:06 pippijn Exp $'; BEGIN { unshift @INC, "lib"; } use Template; use YAML; use Pod::POM; use Pod::Man; use PodHTML2; $Pod::Man::ESCAPES{xa9} = "(C)"; # Static variables my $static = YAML::LoadFile "variables.yml"; my $parser = new Pod::POM; my @podfiles = ; push @podfiles, '../wwwroot/lib/Ermyth.pm'; push @podfiles, '../wwwroot/lib/Ermyth/Accessor.pm'; my @servicenames = qw/ChanServ GameServ Global MemoServ NickServ OperServ SaslServ UserServ/; my $toplevel = []; for (@servicenames) { push @$toplevel, { href => "../" . lc $_ . ".html", title => $_, }; } mkdir "ttdoc"; mkdir "ttdoc/Ermyth"; mkdir "man"; mkdir "man/Ermyth"; mkdir "html"; mkdir "html/Ermyth"; for my $file (@podfiles) { my (undef, $name) = $file =~ /(poddoc|\.\.\/wwwroot\/lib)\/(.+)\.(pod|pm)$/; my $man = new Pod::Man ( release => "Ermyth 2.3", section => 7, center => "Ermyth Documentation", name => "$name", ); my $text = do { local $/; open my $fh, "<$file" or die "$file: $!"; <$fh> }; $text =~ s/\$/\\\$/g; # XXX: hack because for some reason, the HTML # generator loses all $variablenames my $pom = $parser->parse_text ($text) or die $parser->error(); open FH, ">", "ttdoc/$name.tt"; print FH $pom->present ("PodHTML2"); close FH; $man->parse_from_file ($file, "man/$name.7"); } my @files = ; push @files, ; for my $file (@files) { my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> }; my $subtitle = shift @contents; chomp $subtitle; $file =~ s/Ermyth\///; # XXX: hack to get Accessor in the same directory as the rest my $tt = Template->new({ INCLUDE_PATH => 'lib', INTERPOLATE => 1, POST_CHOMP => 1, EVAL_PERL => 1, }) or die "$Template::ERROR\n"; my $vars = { file => sub { return do { local $/; open my $fh, "<$_[0]" or die "$_[0]: $!\n"; <$fh> } if $_[0]; } }; my $contents = "@contents"; my $data = ''; # Variable to store processed templates $tt->process(\$contents, $vars, \$data) or die $tt->error(); # Generate sidemenu my $sidemenu = ''; $vars = $static; $tt->process('sidemenu.tt', $vars, \$sidemenu) or die $tt->error(), "\n"; # Re-initialised with static variables from YAML $vars->{subtitle} = $subtitle; $vars->{contents} = $data; $vars->{sidemenu} = $sidemenu; $vars->{date} = localtime; my $output = ''; # Variable to store the complete page $tt->process('html.tt', $vars, \$output) or die $tt->error(), "\n"; # Save the page to a html file $file =~ s/ttdoc\/(.+)\.tt$/html\/$1.html/; open HTML, ">$file"; print HTML $output; close HTML; } =head1 AUTHOR Copyright © 2007 Pippijn van Steenhoven =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the terms of the GNU General Public License. =cut