ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.19
Committed: Sun Oct 14 14:24:33 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.18: +4 -11 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 Pod::POM;
8 use Template;
9 use YAML;
10
11 my $parser = new Pod::POM meta => 1;
12
13 my ($pom, $html);
14
15 $pom = $parser->parse ("src/news.pod")
16 or die $parser->error;
17 $html = $pom->present ("PodHTML");
18 $html =~ s/\[/</g;
19 $html =~ s/\]/>/g;
20 open FH, ">", "src/news.html";
21 print FH "News\n\n";
22 print FH $html;
23 close FH;
24
25 %PodRSS::metadata = %{ $pom->metadata };
26 $html = $pom->present ("PodRSS");
27 open FH, ">", "html/news.rss";
28 print FH $html;
29 close FH;
30
31 # Static variables
32 my $static = YAML::LoadFile "variables.yml";
33
34 my @files = <src/*.html>;
35 my @monsters = <monsters/*.html>;
36
37 # Directory listings
38 my $list;
39
40 sub list {
41 my ($a, $b) = @_;
42 my $tmp = "<ul>\n";
43
44 my @listing = <$a/$b/*.html>;
45 for (@listing) {
46 my ($file) = $_ =~ /\/([^\/]+)$/;
47 $tmp .= " <li><a href=\"$a/$b/$file\">$file</a><br/>\n ";
48 $tmp .= do { local $/; open my $fh, "<$_.desc" or die "$_.desc: $!\n"; <$fh> };
49 $tmp .= " </li>\n";
50 }
51 $tmp .= "</ul>\n";
52 $list->{$a}->{$b} = $tmp;
53 }
54
55 # Directory listings
56 list "doc", "user";
57 list "doc", "development";
58
59 sub generate {
60 my ($indir, $outdir, @list) = @_;
61
62 for my $file (@list) {
63 my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> };
64 my $subtitle = shift @contents;
65 chomp $subtitle;
66
67 my $curfile = $file;
68 $curfile =~ s/$indir\/(.+\.html)$/$1/;
69
70 my $tt = new Template {
71 INTERPOLATE => 1,
72 POST_CHOMP => 1,
73 EVAL_PERL => 1,
74 } or die "$Template::ERROR\n";
75
76 my $vars = { list => $list };
77
78 my $contents = "@contents";
79 my $data = ''; # Variable to store processed templates
80 $tt->process (\$contents, $vars, \$data)
81 or die $tt->error;
82
83 # Re-initialised with static variables from YAML
84 $vars = $static;
85 $vars->{subtitle} = $subtitle;
86 $vars->{contents} = $data;
87 $vars->{curfile} = $curfile;
88
89 my $output = ''; # Variable to store the complete page
90 $tt->process ('template.html', $vars, \$output)
91 or die $tt->error;
92
93 # Save the page to a html file
94 $file =~ s/$indir\/(.+\.html)$/$outdir\/$1/;
95 open HTML, ">$file";
96 print HTML $output;
97 close HTML;
98 }
99 }
100
101 my @rightbar;
102 push @rightbar, "src/images/monsters/$_.png"
103 for @{ $static->{rightbar} };
104 my @leftbar;
105 push @leftbar, "src/images/runes/$_.png"
106 for @{ $static->{leftbar} };
107
108 generate "src", "html", @files;
109 generate "monsters", "html\/monsters", @monsters;
110
111 system "montage", "-background", "none", "+frame", "+shadow", "+label", "-geometry", "+0+0", "-tile", "1x15", @rightbar, "html/images/monsters-trans.png";
112 system "montage", "-background", "none", "+frame", "+shadow", "+label", "-geometry", "+0+0", "-tile", "1x15", @leftbar, "html/images/runes-trans.png";
113
114 package PodHTML;
115
116 use strict;
117 use warnings;
118 use utf8;
119
120 my $rcsid = '$Id: generate,v 1.18 2007-09-19 14:30:53 pippijn Exp $';
121
122 use base "Pod::POM::View";
123
124 our $subdir;
125 our $dir;
126 our $menu;
127
128 sub view_pod {
129 my ($self, $item) = @_;
130 $item->content->present ($self)
131 }
132
133 sub view_head1 {
134 my ($self, $item) = @_;
135 $item->content->present ($self)
136 }
137
138 sub view_head2 {
139 my ($self, $item) = @_;
140 "<p><em><span class=\"date\">", $item->title, "</span> ", $item->content->present ($self), "</em></p>"
141 }
142
143 sub view_textblock {
144 my ($self, $item) = @_;
145 $item, "<br />"
146 }
147
148 sub view_seq_bold {
149 my ($self, $item) = @_;
150 "<b>$item</b>"
151 }
152
153 sub view_seq_file {
154 my ($self, $item) = @_;
155 "<tt>$item</tt>"
156 }
157
158 sub view_seq_link {
159 my ($self, $item) = @_;
160 my ($name, $href) = split /\|/, $item, 2;
161 "<a href=\"$href\">$name</a>"
162 }
163
164 =head1 AUTHOR
165
166 Copyright © 2007 Pippijn van Steenhoven
167
168 =head1 LICENSE
169
170 This library is free software, you can redistribute it and/or modify
171 it under the terms of the GNU General Public License.
172
173 =cut
174
175 1;
176
177
178 package PodRSS;
179
180 use strict;
181 use warnings;
182 use utf8;
183
184 use base "Pod::POM::View";
185
186 our %metadata;
187
188 sub view_pod {
189 my ($self, $item) = @_;
190 "<?xml version='1.0' encoding='utf-8'?>\n"
191 . "<rss version='2.0'>\n"
192 . $item->content->present ($self)
193 . "</rss>\n"
194 }
195
196 sub view_head1 {
197 my ($self, $item) = @_;
198 my $title = $item->title->present ($self);
199 " <channel>\n",
200 " <link>$metadata{link}</link>\n",
201 " <language>$metadata{language}</language>\n",
202 " <title>$title</title>\n",
203 $item->content->present ($self),
204 " </channel>\n"
205 }
206
207 sub view_head2 {
208 my ($self, $item) = @_;
209 my $title = $item->title->present ($self);
210 " <item>\n",
211 " <title>$title</title>\n",
212 $item->content->present ($self),
213 " </item>\n"
214 }
215
216 sub view_textblock {
217 my ($self, $item) = @_;
218 " <description><![CDATA[$item]]></description>\n"
219 }