#!/usr/bin/env perl use strict; use warnings; use utf8; use constant rcsid => '$Id: gendocs,v 1.2 2007/07/21 13:23:18 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 = ; my @servicenames = qw/ChanServ GameServ Global MemoServ NickServ OperServ SaslServ UserServ/; my $toplevel = []; for (@servicenames) { push @$toplevel, { href => "../" . lc $_ . ".html", title => $_, }; } mkdir "ttdoc"; mkdir "man"; mkdir "html"; for my $file (@podfiles) { my ($name) = $file =~ /poddoc\/(.+)\.pod$/; my $man = new Pod::Man ( release => "Ermyth 2.3", section => 7, center => "Ermyth Documentation", name => "$name", ); $man->parse_from_file ($file, "man/$name.7"); my $pom = $parser->parse ($file) or die $parser->error(); open FH, ">", "ttdoc/$name.tt"; print FH $pom->present ("PodHTML2"); close FH; } my @files = ; for my $file (@files) { my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> }; my $subtitle = shift @contents; chomp $subtitle; 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; 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; }