ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.22
Committed: Sun Apr 5 21:02:51 2009 UTC (15 years, 3 months ago) by root
Branch: MAIN
Changes since 1.21: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

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