ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.17
Committed: Wed Sep 19 14:23:27 2007 UTC (16 years, 9 months ago) by pippijn
Branch: MAIN
Changes since 1.16: +4 -4 lines
Log Message:
fixed rss

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