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