ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.12
Committed: Sun Sep 16 12:02:47 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.11: +13 -2 lines
Log Message:
bold

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.1 # Static variables
14     my $static = YAML::LoadFile "variables.yml";
15    
16     my @files = <src/*.html>;
17 pippijn 1.4 my @monsters = <monsters/*.html>;
18 pippijn 1.1
19     # Directory listings
20     my $list;
21    
22     sub list {
23     my ($a, $b) = @_;
24     my $tmp = "<ul>\n";
25    
26 root 1.3 my @listing = <$a/$b/*.html>;
27 pippijn 1.1 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 pippijn 1.4 sub generate {
42     my ($indir, $outdir, @list) = @_;
43 pippijn 1.1
44 pippijn 1.4 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 pippijn 1.1 INTERPOLATE => 1,
51     POST_CHOMP => 1,
52     EVAL_PERL => 1,
53     } or die "$Template::ERROR\n";
54 pippijn 1.4
55     my $vars = { list => $list };
56 pippijn 1.1
57 pippijn 1.4 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 pippijn 1.1
79 pippijn 1.4 generate "src", "html", @files;
80     generate "monsters", "html\/monsters", @monsters;
81 pippijn 1.5
82     my $pom = $parser->parse ("src/news.pod")
83     or die $parser->error;
84 pippijn 1.9 my $html = $pom->present ("PodHTML");
85     $html =~ s/\[/</g;
86     $html =~ s/\]/>/g;
87 pippijn 1.5 open FH, ">", "html/news.html";
88 pippijn 1.9 print FH $html;
89 pippijn 1.5 close FH;
90    
91 pippijn 1.8 %PodRSS::metadata = %{ $pom->metadata };
92 pippijn 1.9 $html = $pom->present ("PodRSS");
93     $html =~ s/\[/</g;
94     $html =~ s/\]/>/g;
95     open FH, ">", "html/news.rss";
96     print FH $html;
97 pippijn 1.7 close FH;
98    
99    
100 pippijn 1.5 $pom = $parser->parse ("src/news-archive.pod")
101     or die $parser->error;
102 pippijn 1.10 $html = $pom->present ("PodHTML");
103     $html =~ s/\[/</g;
104     $html =~ s/\]/>/g;
105 pippijn 1.5 open FH, ">", "html/news-archive.html";
106 pippijn 1.10 print FH $html;
107 pippijn 1.5 close FH;
108    
109    
110     package PodHTML;
111    
112     use strict;
113     use warnings;
114     use utf8;
115    
116 pippijn 1.12 my $rcsid = '$Id: generate,v 1.11 2007-09-16 09:10:13 pippijn Exp $';
117 pippijn 1.5
118     use base "Pod::POM::View";
119    
120     our $subdir;
121     our $dir;
122     our $menu;
123    
124     sub view_pod {
125     my ($self, $item) = @_;
126     $item->content->present ($self)
127     }
128    
129     sub view_head1 {
130     my ($self, $item) = @_;
131 pippijn 1.6 $item->content->present ($self)
132     }
133    
134     sub view_head2 {
135     my ($self, $item) = @_;
136 pippijn 1.12 "<p><em><span class=\"date\">", $item->title, "</span> ", $item->content->present ($self), "</em></p>"
137     }
138    
139     sub view_seq_bold {
140     my ($self, $item) = @_;
141     "<b>$item</b>"
142     }
143    
144     sub view_seq_link {
145     my ($self, $item) = @_;
146     my ($name, $href) = split "|", $item, 2;
147     "<a href=\"$href\">$name</a>"
148 pippijn 1.5 }
149    
150     =head1 AUTHOR
151    
152     Copyright © 2007 Pippijn van Steenhoven
153    
154     =head1 LICENSE
155    
156     This library is free software, you can redistribute it and/or modify
157     it under the terms of the GNU General Public License.
158    
159     =cut
160    
161 pippijn 1.6 1;
162    
163    
164     package PodRSS;
165    
166     use strict;
167     use warnings;
168     use utf8;
169    
170     use base "Pod::POM::View";
171    
172     our %metadata;
173    
174     sub view_pod {
175     my ($self, $item) = @_;
176     "<?xml version='1.0' encoding='utf-8'?>\n",
177     "<rss version='2.0'>\n",
178     $item->content->present ($self),
179     "</rss>\n"
180     }
181    
182     sub view_head1 {
183     my ($self, $item) = @_;
184     my $title = $item->title->present ($self);
185     " <channel>\n",
186     " <link>$metadata{link}</link>\n",
187     " <language>$metadata{language}</language>\n",
188     " <title>$title</title>\n",
189     $item->content->present ($self),
190     " </channel>\n"
191     }
192    
193     sub view_head2 {
194     my ($self, $item) = @_;
195     my $title = $item->title->present ($self);
196     " <item>\n",
197     " <title>$title</title>\n",
198     $item->content->present ($self),
199     " </item>\n"
200     }
201    
202     sub view_textblock {
203     my ($self, $item) = @_;
204     " <description><![CDATA[$item]]></description>\n"
205     }