1 |
adcroft |
1.1 |
package Pod::HtmlPsPdf::Book; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
|
5 |
|
|
use File::Copy; |
6 |
|
|
|
7 |
|
|
use Pod::HtmlPsPdf::Config (); |
8 |
|
|
use Pod::HtmlPsPdf::Common (); |
9 |
|
|
use Pod::HtmlPsPdf::RunTime (); |
10 |
|
|
use Pod::HtmlPsPdf::Chapter (); |
11 |
|
|
|
12 |
|
|
my $config = Pod::HtmlPsPdf::Config->new(); |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
######## |
16 |
|
|
sub new{ |
17 |
|
|
my $class = shift; |
18 |
|
|
|
19 |
|
|
# create the build directories if they are needed and missing |
20 |
|
|
my $rel_root = $config->get_param('rel_root'); |
21 |
|
|
my $split_root = $config->get_param('split_root'); |
22 |
|
|
my $ps_root = $config->get_param('ps_root'); |
23 |
|
|
my $dir_mode = $config->get_param('dir_mode'); |
24 |
|
|
|
25 |
|
|
mkdir $rel_root,$dir_mode unless -e $rel_root; |
26 |
|
|
|
27 |
|
|
mkdir $split_root, $dir_mode |
28 |
|
|
if $Pod::HtmlPsPdf::RunTime::options{split_html} and !-e $split_root ; |
29 |
|
|
|
30 |
|
|
mkdir $ps_root, $dir_mode |
31 |
|
|
if $Pod::HtmlPsPdf::RunTime::options{generate_ps} and !-e $ps_root ; |
32 |
|
|
|
33 |
|
|
my $rh_main_toc = ''; |
34 |
|
|
my $toc_file = $config->get_param('toc_file'); |
35 |
|
|
|
36 |
|
|
# it just saves me time when I change only a few files and don't |
37 |
|
|
# want to wait for everything to get rebuilt |
38 |
|
|
$rh_main_toc = ( |
39 |
|
|
Pod::HtmlPsPdf::RunTime::has_storable_module() |
40 |
|
|
and !$Pod::HtmlPsPdf::RunTime::options{makefile_mode} |
41 |
|
|
and -e $toc_file) |
42 |
|
|
? Storable::retrieve($toc_file) |
43 |
|
|
: {}; |
44 |
|
|
|
45 |
|
|
# when we will finish to parse the pod files, %valid_anchors will |
46 |
|
|
# include all the valid anchors |
47 |
|
|
# $valid_anchors{target_page#anchor} = "title"; |
48 |
|
|
|
49 |
|
|
# when we will finish to parse the pod files, %links_to_check will |
50 |
|
|
# include all the crossreference links |
51 |
|
|
# $links_to_check{srcpage}[3] = "target_page#anchor"; |
52 |
|
|
|
53 |
|
|
my $self = bless { |
54 |
|
|
rh_valid_anchors => {}, |
55 |
|
|
rh_links_to_check => {}, |
56 |
|
|
some_modified => {}, # keep track of which type (html, split, ps) was modified. |
57 |
|
|
|
58 |
|
|
rh_main_toc => $rh_main_toc, # Main Table of Contents for index.html |
59 |
|
|
}, ref($class)||$class; |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
return $self; |
63 |
|
|
|
64 |
|
|
} # end of sub new |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
# |
68 |
|
|
############## |
69 |
|
|
sub get_param{ |
70 |
|
|
my $self = shift; |
71 |
|
|
|
72 |
|
|
return () unless @_; |
73 |
|
|
return unless defined wantarray; |
74 |
|
|
my @values = map {defined $self->{$_} ? $self->{$_} : ''} @_; |
75 |
|
|
|
76 |
|
|
return wantarray ? @values : $values[0]; |
77 |
|
|
|
78 |
|
|
} # end of sub get_param |
79 |
|
|
|
80 |
|
|
################### |
81 |
|
|
|
82 |
|
|
# These are used to check last modified times and determine when an action is required |
83 |
|
|
# Where these still fail is in checking for modified template files |
84 |
|
|
|
85 |
|
|
sub pod_newer { |
86 |
|
|
my ( $file, $dir_root, $tmpl ) = @_; |
87 |
|
|
|
88 |
|
|
my $src = $config->get_param('src_root') . "/$file.pod"; |
89 |
|
|
my $dest = $config->get_param( $dir_root ) . "/$file.html"; |
90 |
|
|
|
91 |
|
|
return "F:$dest" if $Pod::HtmlPsPdf::RunTime::options{rebuild_all}; |
92 |
|
|
return "C:$dest" unless -e $dest; |
93 |
|
|
return "U:$dest" if -M $src < -M $dest; |
94 |
|
|
|
95 |
|
|
# Check for template dependency |
96 |
|
|
my $template = $config->get_param( $tmpl ); |
97 |
|
|
if ( -M $template < -M $src ) { |
98 |
|
|
my $time = time; |
99 |
|
|
utime $time, $time, $src; |
100 |
|
|
return "T:$dest"; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
return; |
104 |
|
|
|
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
sub pod_newer_split { |
108 |
|
|
my $file = shift; |
109 |
|
|
|
110 |
|
|
my $src = $config->get_param('src_root') . "/$file.pod"; |
111 |
|
|
my $split_root = $config->get_param('split_root'); |
112 |
|
|
|
113 |
|
|
my $dest = "$split_root/$file"; |
114 |
|
|
|
115 |
|
|
return "F:$dest" if $Pod::HtmlPsPdf::RunTime::options{rebuild_all}; |
116 |
|
|
|
117 |
|
|
# Hack -- assumes index.html is same date as everything else |
118 |
|
|
return "C:$dest" unless -e "$dest/index.html"; |
119 |
|
|
return "U:$dest" if -M $src < -M "$dest/index.html"; |
120 |
|
|
|
121 |
|
|
# Check for template dependency |
122 |
|
|
my $template = $config->get_param( 'tmpl_page_split_html' ); |
123 |
|
|
if ( -M $template < -M $src ) { |
124 |
|
|
my $time = time; |
125 |
|
|
utime $time, $time, $src; |
126 |
|
|
return "T:$dest"; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
return; |
131 |
|
|
|
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
sub index_out_of_date { |
135 |
|
|
my ($self, $type, $root ) = @_; |
136 |
|
|
|
137 |
|
|
# Index file(s) get created if any pod file was built |
138 |
|
|
return 'Pod created: Updating' if $self->{some_modified}{$type}; |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
# or if the destination doesn't exist |
143 |
|
|
my $rel_root = $config->get_param( $root ); |
144 |
|
|
return 'Create' if !-e "$rel_root/index.html"; |
145 |
|
|
return 'Create' if $type ne 'ps' && !-e "$rel_root/index_long.html"; |
146 |
|
|
|
147 |
|
|
|
148 |
|
|
# or if the version file is newer than the index file(s) |
149 |
|
|
# since the index file can print [VERSION] |
150 |
|
|
my $version_file = $config->get_param('version_file'); |
151 |
|
|
return 'Version changed: Updating' if -M $version_file < -M "$rel_root/index.html"; |
152 |
|
|
return 'Version changed: Updating' if $type ne 'ps' && -M $version_file < -M "$rel_root/index_long.html"; |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
# Check for template dependency |
156 |
|
|
my $template = $config->get_param( $type eq 'ps' ? 'tmpl_index_ps' : 'tmpl_index_html' ); |
157 |
|
|
return 'Template changed: Updating' if -M $template < -M "$rel_root/index.html"; |
158 |
|
|
return 'Template changed: Updating' if $type ne 'ps' && -M $template < -M "$rel_root/index_long.html"; |
159 |
|
|
|
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
|
163 |
|
|
#################### |
164 |
|
|
sub create_html_version { |
165 |
|
|
my $self = shift; |
166 |
|
|
|
167 |
|
|
print "+++ Processing the pod files \n"; |
168 |
|
|
|
169 |
|
|
my $src_root = $config->get_param('src_root'); |
170 |
|
|
my $verbose = $Pod::HtmlPsPdf::RunTime::options{verbose}; |
171 |
|
|
my $ra_ordered_srcs = $config->get_param('pod_files'); |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
# strip the .pod extension |
175 |
|
|
my @basenames = map { s/\.pod$//; $_} @{$ra_ordered_srcs}; |
176 |
|
|
|
177 |
|
|
# Process each pod |
178 |
|
|
for (my $i=0; $i < @basenames; $i++) { |
179 |
|
|
|
180 |
|
|
my $file = "$basenames[$i].pod"; |
181 |
|
|
my $src_file = "$src_root/$file"; |
182 |
|
|
|
183 |
|
|
|
184 |
|
|
my $generate_ps = pod_newer( $basenames[$i], 'ps_root', 'tmpl_ps_html' ) if $Pod::HtmlPsPdf::RunTime::options{generate_ps}; |
185 |
|
|
my $generate_html = pod_newer( $basenames[$i], 'rel_root', 'tmpl_page_html' ); |
186 |
|
|
|
187 |
|
|
my $generate_split = pod_newer_split( $basenames[$i] ) if $Pod::HtmlPsPdf::RunTime::options{split_html}; |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
unless ( $generate_ps || $generate_split || $generate_html ) { |
191 |
|
|
printf("--- %-22s: skipping (not modified)\n",$file); |
192 |
|
|
next; |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
$self->{some_modified}{html}++ if $generate_html; # to know if index needs to be rebuilt. |
197 |
|
|
$self->{some_modified}{ps}++ if $generate_ps; |
198 |
|
|
$self->{some_modified}{split}++ if $generate_split; |
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
my $rebuild_reason = join ', ', grep { $_ } $generate_ps, $generate_split, $generate_html; |
203 |
|
|
|
204 |
|
|
printf "+++ %-22s: processing ($rebuild_reason)\n",$file; |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
# prev/next linking |
208 |
|
|
my $prev_page = ($i and defined $basenames[$i-1]) ? "$basenames[$i-1].html" : ''; |
209 |
|
|
my $next_page = ( defined $basenames[$i+1]) ? "$basenames[$i+1].html" : ''; |
210 |
|
|
|
211 |
|
|
my $curr_page = "$basenames[$i].html"; |
212 |
|
|
my $curr_page_index = $i+1; |
213 |
|
|
|
214 |
|
|
my $doc_root = "./"; |
215 |
|
|
$curr_page =~ s|^\./||; # strip the leading './' |
216 |
|
|
$doc_root .= "../" x ($curr_page =~ tr|/|/|); |
217 |
|
|
$doc_root =~ s|/$||; # remove the last '/' |
218 |
|
|
|
219 |
|
|
|
220 |
|
|
# adjust the links for prev/next for sources files relative to the |
221 |
|
|
# current doc |
222 |
|
|
|
223 |
|
|
if ($prev_page) { |
224 |
|
|
$prev_page =~ s|^\./||; # strip the leading './' |
225 |
|
|
$prev_page = "$doc_root/$prev_page"; |
226 |
|
|
} |
227 |
|
|
if ($next_page) { |
228 |
|
|
$next_page =~ s|^\./||; # strip the leading './' |
229 |
|
|
$next_page = "$doc_root/$next_page"; |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
# convert pod to html -- huh? When would this ever not be .pod? |
233 |
|
|
if ($file =~ /\.pod/) { |
234 |
|
|
|
235 |
|
|
my $chapter = Pod::HtmlPsPdf::Chapter->new( |
236 |
|
|
$self, |
237 |
|
|
$file, |
238 |
|
|
$src_root, |
239 |
|
|
$src_file, |
240 |
|
|
$verbose, |
241 |
|
|
$doc_root, |
242 |
|
|
$curr_page, |
243 |
|
|
$curr_page_index, |
244 |
|
|
$prev_page, |
245 |
|
|
$next_page, |
246 |
|
|
); |
247 |
|
|
|
248 |
|
|
# podify |
249 |
|
|
$chapter->podify_items() if $Pod::HtmlPsPdf::RunTime::options{podify_items}; |
250 |
|
|
|
251 |
|
|
# pod2html |
252 |
|
|
$chapter->pod2html(); |
253 |
|
|
$chapter->parse_html(); |
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
$chapter->write_html_file() if $generate_html; |
258 |
|
|
|
259 |
|
|
|
260 |
|
|
# html for ps creation |
261 |
|
|
$chapter->write_ps_html_file() if $generate_ps; |
262 |
|
|
|
263 |
|
|
|
264 |
|
|
# html 2 split html -- this destroys the title/body/index |
265 |
|
|
# structures! Therefore it MUST come last, when we won't need |
266 |
|
|
# them anymore. Othewise you should revise this function to |
267 |
|
|
# use copy instead. |
268 |
|
|
|
269 |
|
|
$chapter->write_split_html_files() if $generate_split; |
270 |
|
|
|
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
} # end of for (my $i=0; $i<@$ra_ordered_srcs; $i++) |
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
my $rel_root = $config->get_param('rel_root'); |
280 |
|
|
|
281 |
|
|
# create the index.html files based on the toc from each pod file. |
282 |
|
|
|
283 |
|
|
$self->write_index_html_file(); |
284 |
|
|
|
285 |
|
|
|
286 |
|
|
# copy non-pod files like images and stylesheets (if any are modified) |
287 |
|
|
|
288 |
|
|
$self->copy_the_rest($rel_root); |
289 |
|
|
|
290 |
|
|
|
291 |
|
|
} # end of sub create_html_version |
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
#################### |
296 |
|
|
sub copy_the_rest{ |
297 |
|
|
my $self = shift; |
298 |
|
|
my $target_root = shift; |
299 |
|
|
|
300 |
|
|
print "+++ Copying the non-pod files to $target_root\n"; |
301 |
|
|
|
302 |
|
|
my ($nonpod_files,$src_root) |
303 |
|
|
= $config->get_param(qw(nonpod_files src_root)); |
304 |
|
|
|
305 |
|
|
# Handle the rest of the files |
306 |
|
|
|
307 |
|
|
foreach my $file (@$nonpod_files) { |
308 |
|
|
|
309 |
|
|
# The nonpod files are relative to the current directory now. |
310 |
|
|
my $src = "$src_root/$file"; |
311 |
|
|
my $dst = "$target_root/$file"; |
312 |
|
|
|
313 |
|
|
my $base_name = File::Basename::basename $dst; |
314 |
|
|
|
315 |
|
|
|
316 |
|
|
my $forced = $Pod::HtmlPsPdf::RunTime::options{rebuild_all} |
317 |
|
|
? ' / forced' |
318 |
|
|
: ''; |
319 |
|
|
|
320 |
|
|
if ( !$forced && -e $dst && -M $src > -M $dst ) { |
321 |
|
|
printf("--- %-22s: skipping (not modified)\n",$base_name); |
322 |
|
|
|
323 |
|
|
} else { |
324 |
|
|
|
325 |
|
|
$forced ||= 'modified'; |
326 |
|
|
|
327 |
|
|
Pod::HtmlPsPdf::Common::copy_file( $src, $dst ); |
328 |
|
|
printf("+++ %-22s: processing (%s)\n",$base_name, $forced); |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
} |
332 |
|
|
|
333 |
|
|
} # end of sub copy_the_rest |
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
# generate the PS version |
338 |
|
|
#################### |
339 |
|
|
sub create_ps_version{ |
340 |
|
|
my $self = shift; |
341 |
|
|
|
342 |
|
|
print "+++ Starting the Generation of a PostScript Book version\n"; |
343 |
|
|
|
344 |
|
|
$self->make_indexps_file(); |
345 |
|
|
|
346 |
|
|
# copy non-pod files like images and stylesheets |
347 |
|
|
# must copy these before PS gets generated |
348 |
|
|
my $ps_root = $config->get_param('ps_root'); |
349 |
|
|
$self->copy_the_rest($ps_root); |
350 |
|
|
|
351 |
|
|
print "+++ Generating a PostScript Book version\n"; |
352 |
|
|
|
353 |
|
|
my $html2ps_exec = $config->get_param('html2ps_exec'); |
354 |
|
|
my $html2ps_conf = $config->get_param('html2ps_conf'); |
355 |
|
|
my $ra_ordered_srcs = $config->get_param('pod_files'); |
356 |
|
|
my $out_name = $config->get_param('out_name'); |
357 |
|
|
|
358 |
|
|
my $command = "$html2ps_exec -f $html2ps_conf -o $ps_root/${out_name}.ps "; |
359 |
|
|
$command .= join " ", map {"$ps_root/$_.html"} "index", @$ra_ordered_srcs; |
360 |
|
|
print "Doing $command\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
361 |
|
|
print "Doing $command\n"; |
362 |
|
|
system $command; |
363 |
|
|
|
364 |
|
|
} # end of sub create_ps_version |
365 |
|
|
|
366 |
|
|
# generate the PDF version |
367 |
|
|
#################### |
368 |
|
|
sub create_pdf_version{ |
369 |
|
|
|
370 |
|
|
my $self = shift; |
371 |
|
|
|
372 |
|
|
print "+++ Converting from PS format to PDF format\n"; |
373 |
|
|
my $ps_root = $config->get_param('ps_root'); |
374 |
|
|
my $out_name = $config->get_param('out_name'); |
375 |
|
|
my $command = "ps2pdf $ps_root/$out_name.ps $ps_root/$out_name.pdf"; |
376 |
|
|
print "Doing $command\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
377 |
|
|
system $command; |
378 |
|
|
|
379 |
|
|
} # end of sub create_pdf_version |
380 |
|
|
|
381 |
|
|
|
382 |
|
|
# generate the PDF version |
383 |
|
|
#################### |
384 |
|
|
sub create_split_html_version{ |
385 |
|
|
my $self = shift; |
386 |
|
|
|
387 |
|
|
print "+++ Completing the Split HTML version\n"; |
388 |
|
|
|
389 |
|
|
# copy non-pod files like images and stylesheets |
390 |
|
|
my $split_root = $config->get_param('split_root'); |
391 |
|
|
$self->copy_the_rest($split_root); |
392 |
|
|
|
393 |
|
|
$self->write_split_index_html_file() |
394 |
|
|
|
395 |
|
|
} # end of sub create_split_html_version |
396 |
|
|
|
397 |
|
|
|
398 |
|
|
# Using the same template file create the long and the short index |
399 |
|
|
# html files |
400 |
|
|
################### |
401 |
|
|
sub write_index_html_file{ |
402 |
|
|
my $self = shift; |
403 |
|
|
|
404 |
|
|
# Make sure there's something to do |
405 |
|
|
|
406 |
|
|
my $update_reason = $self->index_out_of_date( 'html', 'rel_root' ); |
407 |
|
|
unless ( $update_reason ) { |
408 |
|
|
print "--- HTML index files: (not modified)\n"; |
409 |
|
|
return; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
|
413 |
|
|
my $ra_ordered_srcs = $config->get_param('pod_files'); |
414 |
|
|
my @ordered_srcs = @$ra_ordered_srcs; |
415 |
|
|
|
416 |
|
|
# build a complete toc |
417 |
|
|
my $main_long_toc = join "\n", |
418 |
|
|
map { |
419 |
|
|
s/$/.html/; |
420 |
|
|
$self->{rh_main_toc}->{$_} ||= '' |
421 |
|
|
} @ordered_srcs; |
422 |
|
|
|
423 |
|
|
my $main_short_toc = join "\n", |
424 |
|
|
map { |
425 |
|
|
$self->{rh_main_toc}->{$_} =~ s|<UL>.*</UL>||ism; |
426 |
|
|
$self->{rh_main_toc}->{$_} =~ s|<B><FONT SIZE=\+1>([^<]+)</FONT></B></A></LI><P>|$1</A></LI>|ism; |
427 |
|
|
$self->{rh_main_toc}->{$_} =~ s^<P>^^gism; |
428 |
|
|
$self->{rh_main_toc}->{$_} |
429 |
|
|
} @ordered_srcs; |
430 |
|
|
|
431 |
|
|
# $self->{rh_main_toc}->{$_} =~ s^<B>|</B>|<P>^^gism; |
432 |
|
|
# $self->{rh_main_toc}->{$_} =~ s^<FONT.*?>|</FONT>^^gism; |
433 |
|
|
|
434 |
|
|
my %toc = ( |
435 |
|
|
long => $main_long_toc, |
436 |
|
|
short => $main_short_toc, |
437 |
|
|
); |
438 |
|
|
|
439 |
|
|
my $rel_root = $config->get_param('rel_root'); |
440 |
|
|
my %file = ( |
441 |
|
|
long => "$rel_root/index_long.html", |
442 |
|
|
short => "$rel_root/index.html", |
443 |
|
|
); |
444 |
|
|
|
445 |
|
|
my %toc_link = ( |
446 |
|
|
long => qq{[ <A HREF="#toc">TOC</A> ] [ <A HREF="index.html">Dense TOC</A> ]}, |
447 |
|
|
short => qq{[ <A HREF="#toc">TOC</A> ] [ <A HREF="index_long.html">Full TOC</A> ]}, |
448 |
|
|
); |
449 |
|
|
|
450 |
|
|
my ($mon,$day,$year) = (localtime ( time ) )[4,3,5]; |
451 |
|
|
my $time_stamp = sprintf "%02d/%02d/%04d", ++$mon,$day,1900+$year; |
452 |
|
|
my $date = sprintf "%s %d, %d", (split /\s+/, scalar localtime)[1,2,4]; |
453 |
|
|
|
454 |
|
|
my $template = $config->get_param('tmpl_index_html'); |
455 |
|
|
my @orig_content = (); |
456 |
|
|
Pod::HtmlPsPdf::Common::read_file($template,\@orig_content); |
457 |
|
|
|
458 |
|
|
use vars qw($VERSION); |
459 |
|
|
my $version_file = $config->get_param('version_file'); |
460 |
|
|
my $package_name = $config->get_param('package_name'); |
461 |
|
|
require $version_file; |
462 |
|
|
{ |
463 |
|
|
no strict 'refs'; |
464 |
|
|
$VERSION = ${$package_name."::VERSION"}; |
465 |
|
|
} |
466 |
|
|
|
467 |
|
|
my %replace_map = ( |
468 |
|
|
VERSION => $VERSION, |
469 |
|
|
DATE => $date, |
470 |
|
|
MODIFIED => $time_stamp, |
471 |
|
|
); |
472 |
|
|
|
473 |
|
|
for (qw(short long)) { |
474 |
|
|
|
475 |
|
|
$replace_map{MAIN_TOC} = $toc{$_}; |
476 |
|
|
$replace_map{TOC} = $toc_link{$_}; |
477 |
|
|
|
478 |
|
|
my @content = @orig_content; |
479 |
|
|
|
480 |
|
|
foreach (@content) { |
481 |
|
|
s/\[(\w+)\]/$replace_map{$1}/g; |
482 |
|
|
} |
483 |
|
|
|
484 |
|
|
print "+++ $update_reason $file{$_}\n"; |
485 |
|
|
Pod::HtmlPsPdf::Common::write_file($file{$_},\@content); |
486 |
|
|
} # end of for (qw(short long)) |
487 |
|
|
|
488 |
|
|
|
489 |
|
|
} # end of sub write_index_html_file |
490 |
|
|
|
491 |
|
|
# index html files for the split html version |
492 |
|
|
################### |
493 |
|
|
sub write_split_index_html_file{ |
494 |
|
|
my $self = shift; |
495 |
|
|
|
496 |
|
|
my $update_reason = $self->index_out_of_date( 'split', 'split_root' ); |
497 |
|
|
unless ( $update_reason ) { |
498 |
|
|
print "--- SPLIT index files: (not modified)\n"; |
499 |
|
|
return; |
500 |
|
|
} |
501 |
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
my $rel_root = $config->get_param('rel_root'); |
505 |
|
|
my $split_root = $config->get_param('split_root'); |
506 |
|
|
|
507 |
|
|
# we simply copy the index.html and index_long.html |
508 |
|
|
# from $rel_root and adjust the links |
509 |
|
|
|
510 |
|
|
for (qw(index index_long)) { |
511 |
|
|
my $index_file = "$rel_root/$_.html"; |
512 |
|
|
my @content = (); |
513 |
|
|
Pod::HtmlPsPdf::Common::read_file($index_file,\@content); |
514 |
|
|
|
515 |
|
|
foreach (@content) { |
516 |
|
|
|
517 |
|
|
# The =head1 NAME it the title, this become the index.html file for that section |
518 |
|
|
s|<LI><A HREF="(.+?)\.html"|<LI><A HREF="$1/index.html"|gsi; |
519 |
|
|
|
520 |
|
|
# Convert the sub-sections into links to their own pages |
521 |
|
|
s|<LI><A HREF="(.+?)\.html#([^\"]*)"|<LI><A HREF="$1/$2.html"|gsi; |
522 |
|
|
|
523 |
|
|
# I don't know which links this is suppose to catch... |
524 |
|
|
s|HREF="(.+?)\.html#([^\"]*)"|HREF="$1/$2.html"|gsi; |
525 |
|
|
} |
526 |
|
|
|
527 |
|
|
$index_file = "$split_root/$_.html"; |
528 |
|
|
print "+++ $update_reason $index_file\n"; |
529 |
|
|
Pod::HtmlPsPdf::Common::write_file($index_file,\@content); |
530 |
|
|
|
531 |
|
|
} # end of for (qw(index index_long)) |
532 |
|
|
|
533 |
|
|
} # end of sub write_split_index_html_file |
534 |
|
|
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
###################### |
538 |
|
|
sub make_indexps_file{ |
539 |
|
|
my $self = shift; |
540 |
|
|
|
541 |
|
|
my $update_reason = $self->index_out_of_date( 'ps', 'ps_root' ); |
542 |
|
|
unless ( $update_reason ) { |
543 |
|
|
print "--- PS index file: (not modified)\n"; |
544 |
|
|
return; |
545 |
|
|
} |
546 |
|
|
|
547 |
|
|
|
548 |
|
|
use vars qw($VERSION); |
549 |
|
|
my $version_file = $config->get_param('version_file'); |
550 |
|
|
my $package_name = $config->get_param('package_name'); |
551 |
|
|
require $version_file; |
552 |
|
|
{ |
553 |
|
|
no strict 'refs'; |
554 |
|
|
$VERSION = ${$package_name."::VERSION"}; |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
my ($mon,$day,$year) = (localtime ( time ) )[4,3,5]; |
558 |
|
|
$year = 1900 + $year; |
559 |
|
|
my $time_stamp = sprintf "%02d/%02d/%04d", ++$mon,$day,$year; |
560 |
|
|
|
561 |
|
|
my $date = sprintf "%s, %d %d", (split /\s+/, scalar localtime)[1,2,4]; |
562 |
|
|
|
563 |
|
|
my %replace_map = ( |
564 |
|
|
VERSION => $VERSION, |
565 |
|
|
DATE => $date, |
566 |
|
|
MODIFIED => $time_stamp, |
567 |
|
|
); |
568 |
|
|
|
569 |
|
|
my $tmpl_index_ps = $config->get_param('tmpl_index_ps'); |
570 |
|
|
my @content = (); |
571 |
|
|
Pod::HtmlPsPdf::Common::read_file($tmpl_index_ps,\@content); |
572 |
|
|
|
573 |
|
|
for (@content){ |
574 |
|
|
s/\[(\w+)\]/$replace_map{$1}/g; |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
my $ps_root = $config->get_param('ps_root'); |
578 |
|
|
print "+++ $update_reason $ps_root/index.html\n"; |
579 |
|
|
Pod::HtmlPsPdf::Common::write_file("$ps_root/index.html",\@content); |
580 |
|
|
|
581 |
|
|
} # end of sub make_indexps_file |
582 |
|
|
|
583 |
|
|
# Validate pod's L<> links |
584 |
|
|
################### |
585 |
|
|
sub validate_links{ |
586 |
|
|
my $self = shift; |
587 |
|
|
|
588 |
|
|
my %links_to_check = %{$self->{rh_links_to_check}}; |
589 |
|
|
|
590 |
|
|
print "+++ Validating anchors\n"; |
591 |
|
|
my $count = 0; |
592 |
|
|
foreach my $srcpage (sort keys %links_to_check) { |
593 |
|
|
foreach (@{$links_to_check{$srcpage}}) { |
594 |
|
|
$count++, |
595 |
|
|
print "!!! Broken $srcpage.pod: $_\n" |
596 |
|
|
unless exists $self->{rh_valid_anchors}->{$_}; |
597 |
|
|
} |
598 |
|
|
} |
599 |
|
|
|
600 |
|
|
print $count |
601 |
|
|
? "!!! $count anchors are broken\n" |
602 |
|
|
: "!!! Nothing broken\n"; |
603 |
|
|
|
604 |
|
|
} # end of sub validate_links |
605 |
|
|
|
606 |
|
|
# print the available target anchors by the pod's L<> fashion, to be |
607 |
|
|
# copied and pasted directly into a pod. |
608 |
|
|
################### |
609 |
|
|
sub print_anchors{ |
610 |
|
|
my $self = shift; |
611 |
|
|
|
612 |
|
|
my %valid_anchors = %{$self->{rh_valid_anchors}}; |
613 |
|
|
|
614 |
|
|
print "+++ Generating a list of available anchors\n"; |
615 |
|
|
foreach my $key (sort keys %valid_anchors) { |
616 |
|
|
print "L<$valid_anchors{$key}|$key>\n"; |
617 |
|
|
} |
618 |
|
|
|
619 |
|
|
} # end of sub print_anchors |
620 |
|
|
|
621 |
|
|
|
622 |
|
|
################ |
623 |
|
|
sub make_tar_gz{ |
624 |
|
|
my $self = shift; |
625 |
|
|
|
626 |
|
|
print "+++ Creating tar.gz version\n"; |
627 |
|
|
|
628 |
|
|
my $root = $config->get_param('root'); |
629 |
|
|
my $out_dir = $config->get_param('out_dir'); |
630 |
|
|
my $dir_mode = $config->get_param('dir_mode'); |
631 |
|
|
mkdir $out_dir, $dir_mode unless -d $out_dir; |
632 |
|
|
|
633 |
|
|
# copy all to an out dir |
634 |
|
|
my $rel_root = $config->get_param('rel_root'); |
635 |
|
|
system "cp -r $rel_root/* $out_dir"; |
636 |
|
|
|
637 |
|
|
my $ps_root = $config->get_param('ps_root'); |
638 |
|
|
my $out_name = $config->get_param('out_name'); |
639 |
|
|
|
640 |
|
|
# if we create pdf, we don't want the PS version, therefore it pdf |
641 |
|
|
# comes first in this if statement |
642 |
|
|
if ($Pod::HtmlPsPdf::RunTime::options{generate_pdf}) { |
643 |
|
|
my $file = "$ps_root/${out_name}.pdf"; |
644 |
|
|
print "gzip -9 $file\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
645 |
|
|
system("gzip -9 $file"); |
646 |
|
|
print "mv $file.gz $root/$out_name\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
647 |
|
|
move("$file.gz","$root/$out_name"); |
648 |
|
|
|
649 |
|
|
} elsif ($Pod::HtmlPsPdf::RunTime::options{generate_ps}) { |
650 |
|
|
my $file = "$ps_root/${out_name}.ps"; |
651 |
|
|
print "gzip -9 $file\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
652 |
|
|
system("gzip -9 $file"); |
653 |
|
|
print "mv $file.gz $root/$out_name\n" if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
654 |
|
|
move("$file.gz","$root/$out_name"); |
655 |
|
|
|
656 |
|
|
} else { |
657 |
|
|
# do nothing |
658 |
|
|
} |
659 |
|
|
|
660 |
|
|
chdir $root; |
661 |
|
|
|
662 |
|
|
print "mv $out_name.tar.gz $out_name.tar.gz.old\n" |
663 |
|
|
if -e "$out_name.tar.gz" and $Pod::HtmlPsPdf::RunTime::options{verbose}; |
664 |
|
|
rename "$out_name.tar.gz", "$out_name.tar.gz.old" if -e "$out_name.tar.gz"; |
665 |
|
|
system "tar cvf $out_name.tar $out_name"; |
666 |
|
|
system "gzip -9 $out_name.tar"; |
667 |
|
|
|
668 |
|
|
# Clean up |
669 |
|
|
system "rm -rf $out_name"; |
670 |
|
|
|
671 |
|
|
# print "*** Error: PDF did not enter the release package!\n" |
672 |
|
|
# unless $Pod::HtmlPsPdf::RunTime::options{generate_pdf} |
673 |
|
|
|
674 |
|
|
|
675 |
|
|
} # end of sub make_tar_gz |
676 |
|
|
|
677 |
|
|
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
# cleanup |
681 |
|
|
############ |
682 |
|
|
sub cleanup{ |
683 |
|
|
my $self = shift; |
684 |
|
|
|
685 |
|
|
if (Pod::HtmlPsPdf::RunTime::has_storable_module()){ |
686 |
|
|
# update TOC |
687 |
|
|
my $toc_file = $config->get_param('toc_file'); |
688 |
|
|
print "+++ Storing the TOC file $toc_file for a later reuse\n" |
689 |
|
|
if $Pod::HtmlPsPdf::RunTime::options{verbose}; |
690 |
|
|
Storable::store($self->{rh_main_toc},$toc_file); |
691 |
|
|
} |
692 |
|
|
} # end of sub cleanup |
693 |
|
|
|
694 |
|
|
|
695 |
|
|
1; |
696 |
|
|
__END__ |