ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/www/generate
Revision: 1.6
Committed: Sun Sep 16 07:55:13 2007 UTC (16 years, 10 months ago) by pippijn
Branch: MAIN
Changes since 1.5: +51 -2 lines
Log Message:
cosmetic changes

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     # Static variables
12     my $static = YAML::LoadFile "variables.yml";
13    
14     my @files = <src/*.html>;
15 pippijn 1.4 my @monsters = <monsters/*.html>;
16 pippijn 1.1
17     # Directory listings
18     my $list;
19    
20     sub list {
21     my ($a, $b) = @_;
22     my $tmp = "<ul>\n";
23    
24 root 1.3 my @listing = <$a/$b/*.html>;
25 pippijn 1.1 for (@listing) {
26     my ($file) = $_ =~ /\/([^\/]+)$/;
27     $tmp .= " <li><a href=\"$a/$b/$file\">$file</a><br/>\n ";
28     $tmp .= do { local $/; open my $fh, "<$_.desc" or die "$_.desc: $!\n"; <$fh> };
29     $tmp .= " </li>\n";
30     }
31     $tmp .= "</ul>\n";
32     $list->{$a}->{$b} = $tmp;
33     }
34    
35     # Directory listings
36     list "doc", "user";
37     list "doc", "development";
38    
39 pippijn 1.4 sub generate {
40     my ($indir, $outdir, @list) = @_;
41 pippijn 1.1
42 pippijn 1.4 for my $file (@list) {
43     my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> };
44     my $subtitle = shift @contents;
45     chomp $subtitle;
46    
47     my $tt = new Template {
48 pippijn 1.1 INTERPOLATE => 1,
49     POST_CHOMP => 1,
50     EVAL_PERL => 1,
51     } or die "$Template::ERROR\n";
52 pippijn 1.4
53     my $vars = { list => $list };
54 pippijn 1.1
55 pippijn 1.4 my $contents = "@contents";
56     my $data = ''; # Variable to store processed templates
57     $tt->process (\$contents, $vars, \$data)
58     or die $tt->error;
59    
60     # Re-initialised with static variables from YAML
61     $vars = $static;
62     $vars->{subtitle} = $subtitle;
63     $vars->{contents} = $data;
64    
65     my $output = ''; # Variable to store the complete page
66     $tt->process ('template.html', $vars, \$output)
67     or die $tt->error;
68    
69     # Save the page to a html file
70     $file =~ s/$indir\/(.+\.html)$/$outdir\/$1/;
71     open HTML, ">$file";
72     print HTML $output;
73     close HTML;
74     }
75     }
76 pippijn 1.1
77 pippijn 1.4 generate "src", "html", @files;
78     generate "monsters", "html\/monsters", @monsters;
79 pippijn 1.5
80     my $parser = new Pod::POM;
81    
82     my $pom = $parser->parse ("src/news.pod")
83     or die $parser->error;
84     open FH, ">", "html/news.html";
85     print FH $pom->present ("PodHTML");
86     close FH;
87    
88     $pom = $parser->parse ("src/news-archive.pod")
89     or die $parser->error;
90     open FH, ">", "html/news-archive.html";
91     print FH $pom->present ("PodHTML");
92     close FH;
93    
94    
95     package PodHTML;
96    
97     use strict;
98     use warnings;
99     use utf8;
100    
101 pippijn 1.6 my $rcsid = '$Id: generate,v 1.5 2007-09-16 07:44:24 pippijn Exp $';
102 pippijn 1.5
103     use base "Pod::POM::View";
104    
105     our $subdir;
106     our $dir;
107     our $menu;
108    
109     sub view_pod {
110     my ($self, $item) = @_;
111     $item->content->present ($self)
112     }
113    
114     sub view_head1 {
115     my ($self, $item) = @_;
116 pippijn 1.6 $item->content->present ($self)
117     }
118    
119     sub view_head2 {
120     my ($self, $item) = @_;
121 pippijn 1.5 "<p><em>", $item->title, " ", $item->content, "</em></p>"
122     }
123    
124     =head1 AUTHOR
125    
126     Copyright © 2007 Pippijn van Steenhoven
127    
128     =head1 LICENSE
129    
130     This library is free software, you can redistribute it and/or modify
131     it under the terms of the GNU General Public License.
132    
133     =cut
134    
135 pippijn 1.6 1;
136    
137    
138     package PodRSS;
139    
140     use strict;
141     use warnings;
142     use utf8;
143    
144     use base "Pod::POM::View";
145    
146     our %metadata;
147    
148     sub view_pod {
149     my ($self, $item) = @_;
150     "<?xml version='1.0' encoding='utf-8'?>\n",
151     "<rss version='2.0'>\n",
152     $item->content->present ($self),
153     "</rss>\n"
154     }
155    
156     sub view_head1 {
157     my ($self, $item) = @_;
158     my $title = $item->title->present ($self);
159     " <channel>\n",
160     " <link>$metadata{link}</link>\n",
161     " <language>$metadata{language}</language>\n",
162     " <title>$title</title>\n",
163     $item->content->present ($self),
164     " </channel>\n"
165     }
166    
167     sub view_head2 {
168     my ($self, $item) = @_;
169     my $title = $item->title->present ($self);
170     " <item>\n",
171     " <title>$title</title>\n",
172     $item->content->present ($self),
173     " </item>\n"
174     }
175    
176     sub view_textblock {
177     my ($self, $item) = @_;
178     " <description><![CDATA[$item]]></description>\n"
179     }