ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.4
Committed: Sat Sep 15 15:22:17 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.3: +34 -26 lines
Log Message:
reworked some of the website

File Contents

# Content
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use Template;
8 use YAML;
9
10 # Static variables
11 my $static = YAML::LoadFile "variables.yml";
12
13 my @files = <src/*.html>;
14 my @monsters = <monsters/*.html>;
15
16 # Directory listings
17 my $list;
18
19 sub list {
20 my ($a, $b) = @_;
21 my $tmp = "<ul>\n";
22
23 my @listing = <$a/$b/*.html>;
24 for (@listing) {
25 my ($file) = $_ =~ /\/([^\/]+)$/;
26 $tmp .= " <li><a href=\"$a/$b/$file\">$file</a><br/>\n ";
27 $tmp .= do { local $/; open my $fh, "<$_.desc" or die "$_.desc: $!\n"; <$fh> };
28 $tmp .= " </li>\n";
29 }
30 $tmp .= "</ul>\n";
31 $list->{$a}->{$b} = $tmp;
32 }
33
34 # Directory listings
35 list "doc", "user";
36 list "doc", "development";
37
38 sub generate {
39 my ($indir, $outdir, @list) = @_;
40
41 for my $file (@list) {
42 my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> };
43 my $subtitle = shift @contents;
44 chomp $subtitle;
45
46 my $tt = new Template {
47 INTERPOLATE => 1,
48 POST_CHOMP => 1,
49 EVAL_PERL => 1,
50 } or die "$Template::ERROR\n";
51
52 my $vars = { list => $list };
53
54 my $contents = "@contents";
55 my $data = ''; # Variable to store processed templates
56 $tt->process (\$contents, $vars, \$data)
57 or die $tt->error;
58
59 # Re-initialised with static variables from YAML
60 $vars = $static;
61 $vars->{subtitle} = $subtitle;
62 $vars->{contents} = $data;
63
64 my $output = ''; # Variable to store the complete page
65 $tt->process ('template.html', $vars, \$output)
66 or die $tt->error;
67
68 # Save the page to a html file
69 $file =~ s/$indir\/(.+\.html)$/$outdir\/$1/;
70 open HTML, ">$file";
71 print HTML $output;
72 close HTML;
73 }
74 }
75
76 generate "src", "html", @files;
77 generate "monsters", "html\/monsters", @monsters;