ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.14
Committed: Sun Sep 16 12:25:35 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.13: +30 -28 lines
Log Message:
news archive

File Contents

# User Rev Content
1 pippijn 1.1 #!/usr/bin/env perl
2    
3     use strict;
4     use warnings;
5     use utf8;
6    
7 pippijn 1.5 use Pod::POM;
8 pippijn 1.1 use Template;
9     use YAML;
10    
11 pippijn 1.8 my $parser = new Pod::POM meta => 1;
12    
13 pippijn 1.14 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 pippijn 1.1 # Static variables
43     my $static = YAML::LoadFile "variables.yml";
44    
45     my @files = <src/*.html>;
46 pippijn 1.4 my @monsters = <monsters/*.html>;
47 pippijn 1.1
48     # Directory listings
49     my $list;
50    
51     sub list {
52     my ($a, $b) = @_;
53     my $tmp = "<ul>\n";
54    
55 root 1.3 my @listing = <$a/$b/*.html>;
56 pippijn 1.1 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 pippijn 1.4 sub generate {
71     my ($indir, $outdir, @list) = @_;
72 pippijn 1.1
73 pippijn 1.4 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 $tt = new Template {
79 pippijn 1.1 INTERPOLATE => 1,
80     POST_CHOMP => 1,
81     EVAL_PERL => 1,
82     } or die "$Template::ERROR\n";
83 pippijn 1.4
84     my $vars = { list => $list };
85 pippijn 1.1
86 pippijn 1.4 my $contents = "@contents";
87     my $data = ''; # Variable to store processed templates
88     $tt->process (\$contents, $vars, \$data)
89     or die $tt->error;
90    
91     # Re-initialised with static variables from YAML
92     $vars = $static;
93     $vars->{subtitle} = $subtitle;
94     $vars->{contents} = $data;
95    
96     my $output = ''; # Variable to store the complete page
97     $tt->process ('template.html', $vars, \$output)
98     or die $tt->error;
99    
100     # Save the page to a html file
101     $file =~ s/$indir\/(.+\.html)$/$outdir\/$1/;
102     open HTML, ">$file";
103     print HTML $output;
104     close HTML;
105     }
106     }
107 pippijn 1.1
108 pippijn 1.4 generate "src", "html", @files;
109     generate "monsters", "html\/monsters", @monsters;
110 pippijn 1.5
111    
112     package PodHTML;
113    
114     use strict;
115     use warnings;
116     use utf8;
117    
118 pippijn 1.14 my $rcsid = '$Id: generate,v 1.13 2007-09-16 12:13:23 pippijn Exp $';
119 pippijn 1.5
120     use base "Pod::POM::View";
121    
122     our $subdir;
123     our $dir;
124     our $menu;
125    
126     sub view_pod {
127     my ($self, $item) = @_;
128     $item->content->present ($self)
129     }
130    
131     sub view_head1 {
132     my ($self, $item) = @_;
133 pippijn 1.6 $item->content->present ($self)
134     }
135    
136     sub view_head2 {
137     my ($self, $item) = @_;
138 pippijn 1.12 "<p><em><span class=\"date\">", $item->title, "</span> ", $item->content->present ($self), "</em></p>"
139     }
140    
141 pippijn 1.13 sub view_textblock {
142     my ($self, $item) = @_;
143     $item, "<br />"
144     }
145    
146 pippijn 1.12 sub view_seq_bold {
147     my ($self, $item) = @_;
148     "<b>$item</b>"
149     }
150    
151 pippijn 1.13 sub view_seq_file {
152     my ($self, $item) = @_;
153     "<tt>$item</tt>"
154     }
155    
156 pippijn 1.12 sub view_seq_link {
157     my ($self, $item) = @_;
158 pippijn 1.13 my ($name, $href) = split /\|/, $item, 2;
159 pippijn 1.12 "<a href=\"$href\">$name</a>"
160 pippijn 1.5 }
161    
162     =head1 AUTHOR
163    
164     Copyright © 2007 Pippijn van Steenhoven
165    
166     =head1 LICENSE
167    
168     This library is free software, you can redistribute it and/or modify
169     it under the terms of the GNU General Public License.
170    
171     =cut
172    
173 pippijn 1.6 1;
174    
175    
176     package PodRSS;
177    
178     use strict;
179     use warnings;
180     use utf8;
181    
182     use base "Pod::POM::View";
183    
184     our %metadata;
185    
186     sub view_pod {
187     my ($self, $item) = @_;
188     "<?xml version='1.0' encoding='utf-8'?>\n",
189     "<rss version='2.0'>\n",
190     $item->content->present ($self),
191     "</rss>\n"
192     }
193    
194     sub view_head1 {
195     my ($self, $item) = @_;
196     my $title = $item->title->present ($self);
197     " <channel>\n",
198     " <link>$metadata{link}</link>\n",
199     " <language>$metadata{language}</language>\n",
200     " <title>$title</title>\n",
201     $item->content->present ($self),
202     " </channel>\n"
203     }
204    
205     sub view_head2 {
206     my ($self, $item) = @_;
207     my $title = $item->title->present ($self);
208     " <item>\n",
209     " <title>$title</title>\n",
210     $item->content->present ($self),
211     " </item>\n"
212     }
213    
214     sub view_textblock {
215     my ($self, $item) = @_;
216     " <description><![CDATA[$item]]></description>\n"
217     }