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