ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.8
Committed: Sun Sep 16 07:59:39 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.7: +4 -3 lines
Log Message:
completed 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 open FH, ">", "html/news.html";
85 print FH $pom->present ("PodHTML");
86 close FH;
87
88 %PodRSS::metadata = %{ $pom->metadata };
89 open FH, ">", "html/news.xml";
90 print FH $pom->present ("PodRSS");
91 close FH;
92
93
94 $pom = $parser->parse ("src/news-archive.pod")
95 or die $parser->error;
96 open FH, ">", "html/news-archive.html";
97 print FH $pom->present ("PodHTML");
98 close FH;
99
100
101 package PodHTML;
102
103 use strict;
104 use warnings;
105 use utf8;
106
107 my $rcsid = '$Id: generate,v 1.7 2007-09-16 07:57:19 pippijn Exp $';
108
109 use base "Pod::POM::View";
110
111 our $subdir;
112 our $dir;
113 our $menu;
114
115 sub view_pod {
116 my ($self, $item) = @_;
117 $item->content->present ($self)
118 }
119
120 sub view_head1 {
121 my ($self, $item) = @_;
122 $item->content->present ($self)
123 }
124
125 sub view_head2 {
126 my ($self, $item) = @_;
127 "<p><em>", $item->title, " ", $item->content, "</em></p>"
128 }
129
130 =head1 AUTHOR
131
132 Copyright © 2007 Pippijn van Steenhoven
133
134 =head1 LICENSE
135
136 This library is free software, you can redistribute it and/or modify
137 it under the terms of the GNU General Public License.
138
139 =cut
140
141 1;
142
143
144 package PodRSS;
145
146 use strict;
147 use warnings;
148 use utf8;
149
150 use base "Pod::POM::View";
151
152 our %metadata;
153
154 sub view_pod {
155 my ($self, $item) = @_;
156 "<?xml version='1.0' encoding='utf-8'?>\n",
157 "<rss version='2.0'>\n",
158 $item->content->present ($self),
159 "</rss>\n"
160 }
161
162 sub view_head1 {
163 my ($self, $item) = @_;
164 my $title = $item->title->present ($self);
165 " <channel>\n",
166 " <link>$metadata{link}</link>\n",
167 " <language>$metadata{language}</language>\n",
168 " <title>$title</title>\n",
169 $item->content->present ($self),
170 " </channel>\n"
171 }
172
173 sub view_head2 {
174 my ($self, $item) = @_;
175 my $title = $item->title->present ($self);
176 " <item>\n",
177 " <title>$title</title>\n",
178 $item->content->present ($self),
179 " </item>\n"
180 }
181
182 sub view_textblock {
183 my ($self, $item) = @_;
184 " <description><![CDATA[$item]]></description>\n"
185 }