ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.24
Committed: Mon Mar 22 20:36:18 2010 UTC (14 years, 3 months ago) by root
Branch: MAIN
Changes since 1.23: +8 -7 lines
Log Message:
*** empty log message ***

File Contents

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