ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.18
Committed: Wed Sep 19 14:30:53 2007 UTC (16 years, 9 months ago) by pippijn
Branch: MAIN
Changes since 1.17: +2 -6 lines
Log Message:
we don't need these anymore

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