ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
(Generate patch)

Comparing deliantra/www/generate (file contents):
Revision 1.3 by root, Thu Sep 13 20:17:30 2007 UTC vs.
Revision 1.4 by pippijn, Sat Sep 15 15:22:17 2007 UTC

9 9
10# Static variables 10# Static variables
11my $static = YAML::LoadFile "variables.yml"; 11my $static = YAML::LoadFile "variables.yml";
12 12
13my @files = <src/*.html>; 13my @files = <src/*.html>;
14my @monsters = <monsters/*.html>;
14 15
15# Directory listings 16# Directory listings
16my $list; 17my $list;
17 18
18sub list { 19sub list {
32 33
33# Directory listings 34# Directory listings
34list "doc", "user"; 35list "doc", "user";
35list "doc", "development"; 36list "doc", "development";
36 37
37for my $file (@files) { 38sub generate {
38 my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> }; 39 my ($indir, $outdir, @list) = @_;
39 my $subtitle = shift @contents;
40 chomp $subtitle;
41 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
42 my $tt = new Template { 46 my $tt = new Template {
43 INTERPOLATE => 1, 47 INTERPOLATE => 1,
44 POST_CHOMP => 1, 48 POST_CHOMP => 1,
45 EVAL_PERL => 1, 49 EVAL_PERL => 1,
46 } or die "$Template::ERROR\n"; 50 } or die "$Template::ERROR\n";
51
52 my $vars = { list => $list };
47 53
48 my $vars = { list => $list }; 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;
49 67
50 my $contents = "@contents"; 68 # Save the page to a html file
51 my $data = ''; # Variable to store processed templates 69 $file =~ s/$indir\/(.+\.html)$/$outdir\/$1/;
52 $tt->process (\$contents, $vars, \$data) 70 open HTML, ">$file";
53 or die $tt->error; 71 print HTML $output;
72 close HTML;
73 }
74}
54 75
55 # Re-initialised with static variables from YAML 76generate "src", "html", @files;
56 $vars = $static; 77generate "monsters", "html\/monsters", @monsters;
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}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines