ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.3
Committed: Thu Sep 13 20:17:30 2007 UTC (16 years, 10 months ago) by root
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

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
15 # Directory listings
16 my $list;
17
18 sub list {
19 my ($a, $b) = @_;
20 my $tmp = "<ul>\n";
21
22 my @listing = <$a/$b/*.html>;
23 for (@listing) {
24 my ($file) = $_ =~ /\/([^\/]+)$/;
25 $tmp .= " <li><a href=\"$a/$b/$file\">$file</a><br/>\n ";
26 $tmp .= do { local $/; open my $fh, "<$_.desc" or die "$_.desc: $!\n"; <$fh> };
27 $tmp .= " </li>\n";
28 }
29 $tmp .= "</ul>\n";
30 $list->{$a}->{$b} = $tmp;
31 }
32
33 # Directory listings
34 list "doc", "user";
35 list "doc", "development";
36
37 for my $file (@files) {
38 my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> };
39 my $subtitle = shift @contents;
40 chomp $subtitle;
41
42 my $tt = new Template {
43 INTERPOLATE => 1,
44 POST_CHOMP => 1,
45 EVAL_PERL => 1,
46 } or die "$Template::ERROR\n";
47
48 my $vars = { list => $list };
49
50 my $contents = "@contents";
51 my $data = ''; # Variable to store processed templates
52 $tt->process (\$contents, $vars, \$data)
53 or die $tt->error;
54
55 # Re-initialised with static variables from YAML
56 $vars = $static;
57 $vars->{subtitle} = $subtitle;
58 $vars->{contents} = $data;
59
60 my $output = ''; # Variable to store the complete page
61 $tt->process ('template.html', $vars, \$output)
62 or die $tt->error;
63
64 # Save the page to a html file
65 $file =~ s/src\/(.+)\.html$/html\/$1.html/;
66 open HTML, ">$file";
67 print HTML $output;
68 close HTML;
69 }