… | |
… | |
9 | |
9 | |
10 | # Static variables |
10 | # Static variables |
11 | my $static = YAML::LoadFile "variables.yml"; |
11 | my $static = YAML::LoadFile "variables.yml"; |
12 | |
12 | |
13 | my @files = <src/*.html>; |
13 | my @files = <src/*.html>; |
|
|
14 | my @monsters = <monsters/*.html>; |
14 | |
15 | |
15 | # Directory listings |
16 | # Directory listings |
16 | my $list; |
17 | my $list; |
17 | |
18 | |
18 | sub list { |
19 | sub list { |
… | |
… | |
32 | |
33 | |
33 | # Directory listings |
34 | # Directory listings |
34 | list "doc", "user"; |
35 | list "doc", "user"; |
35 | list "doc", "development"; |
36 | list "doc", "development"; |
36 | |
37 | |
37 | for my $file (@files) { |
38 | sub 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 |
76 | generate "src", "html", @files; |
56 | $vars = $static; |
77 | generate "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 | } |
|
|