ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.15
Committed: Sun Sep 16 15:24:40 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.14: +10 -1 lines
Log Message:
concatenate runes and monsters for sidebars

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.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.15 my $rcsid = '$Id: generate,v 1.14 2007-09-16 12:25:35 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     "<?xml version='1.0' encoding='utf-8'?>\n",
198     "<rss version='2.0'>\n",
199     $item->content->present ($self),
200     "</rss>\n"
201     }
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     }