| 361 |
dpurdie |
1 |
package JatsDocTools::Tree::HTML;
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use warnings;
|
|
|
5 |
|
|
|
6 |
use Cwd qw(cwd);
|
|
|
7 |
use File::Basename qw(dirname);
|
|
|
8 |
use File::Path qw(mkpath);
|
|
|
9 |
use Pod::Find qw(pod_find);
|
|
|
10 |
|
|
|
11 |
use JatsDocTools::Pod qw(pod2html pod2html_remove_cache_files);
|
|
|
12 |
|
|
|
13 |
sub _relative_path {
|
|
|
14 |
my($path, $prefix) = @_;
|
|
|
15 |
$path =~ s,\\,/,g if $^O eq "MSWin32";
|
|
|
16 |
$path =~ s,/\z,, unless $path =~ m,^([A-Za-z]:)?/\z,;
|
|
|
17 |
|
|
|
18 |
if (defined $prefix && length $prefix) {
|
|
|
19 |
$prefix =~ s,\\,/,g if $^O eq "MSWin32";
|
|
|
20 |
$prefix =~ s,/\z,, unless $prefix =~ m,^([A-Za-z]:)?/\z,;
|
|
|
21 |
|
|
|
22 |
my @path_parts = split('/', $path);
|
|
|
23 |
my @prefix_parts = split('/', $prefix);
|
|
|
24 |
return $path if @path_parts < @prefix_parts;
|
|
|
25 |
|
|
|
26 |
while (@prefix_parts) {
|
|
|
27 |
my $path_part = shift(@path_parts);
|
|
|
28 |
my $prefix_part = shift(@prefix_parts);
|
|
|
29 |
if ($^O eq "MSWin32") {
|
|
|
30 |
$_ = lc for $path_part, $prefix_part;
|
|
|
31 |
}
|
|
|
32 |
return $path unless $path_part eq $prefix_part;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
$path = join('/', @path_parts) || ".";
|
|
|
36 |
}
|
|
|
37 |
return $path;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
sub Update {
|
|
|
41 |
my %args = @_;
|
|
|
42 |
|
|
|
43 |
my $prefix = $args{prefix} || croak("Required prefix argument missing");
|
|
|
44 |
my $htmldir = $args{htmldir} || croak("Required htmldir argument missing");
|
|
|
45 |
my $podpath = $args{podpath} || croak("Required podpath argument missing");
|
|
|
46 |
my $cacheDir = $args{cacheDir} || croak("Required cacheDir argument missing");
|
|
|
47 |
my $index = $args{index} || 0;
|
|
|
48 |
|
|
|
49 |
my $starting_cwd = cwd();
|
|
|
50 |
unless (chdir($prefix)) {
|
|
|
51 |
warn "Can't chdir to root of target installation: $!\n";
|
|
|
52 |
return;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
print "Building HTML tree at $htmldir, cwd is $prefix\n" if $args{verbose};
|
|
|
56 |
|
|
|
57 |
pod2html_remove_cache_files($cacheDir)
|
|
|
58 |
if ( $args{force} );
|
|
|
59 |
|
|
|
60 |
my %pods = pod_find(@$podpath);
|
|
|
61 |
@$podpath = map { _relative_path($_, $prefix) } @$podpath;
|
|
|
62 |
|
|
|
63 |
foreach my $key (sort keys %pods) {
|
|
|
64 |
|
|
|
65 |
my $in_file = _relative_path($key, $prefix);
|
|
|
66 |
if ( $in_file =~ m~TOOLS/LIB~ )
|
|
|
67 |
{
|
| 4779 |
dpurdie |
68 |
unless ( isaJatsKeyPod($in_file) ) {
|
|
|
69 |
print "Ignoring $in_file\n" if $args{verbose};
|
|
|
70 |
next;
|
|
|
71 |
}
|
| 361 |
dpurdie |
72 |
}
|
|
|
73 |
|
|
|
74 |
my $out_file = "$htmldir/$in_file";
|
|
|
75 |
$out_file =~ s/\.[a-z]+\z|\z/.html/i;
|
|
|
76 |
if ($args{force} || !-e $out_file || (stat $in_file)[9] > (stat $out_file)[9]) {
|
|
|
77 |
print "Making $out_file from $in_file => $pods{$key}\n"
|
|
|
78 |
if $args{verbose};
|
|
|
79 |
|
|
|
80 |
unlink($out_file);
|
|
|
81 |
my $out_dir = dirname($out_file);
|
|
|
82 |
mkpath($out_dir);
|
|
|
83 |
|
|
|
84 |
my $depth = $in_file =~ tr,/,,;
|
|
|
85 |
pod2html(infile => $in_file,
|
|
|
86 |
outfile => $out_file,
|
|
|
87 |
depth => $depth,
|
|
|
88 |
podroot => ".",
|
|
|
89 |
podpath => $podpath,
|
|
|
90 |
cacheDir => $cacheDir,
|
|
|
91 |
index => $index,
|
|
|
92 |
);
|
|
|
93 |
}
|
|
|
94 |
else {
|
|
|
95 |
print "Skipping $out_file\n" if $args{verbose};
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
# pod2html_remove_cache_files($cacheDir);
|
|
|
100 |
chdir($starting_cwd) or die "Can't chdir back to '$starting_cwd': $!";
|
|
|
101 |
}
|
|
|
102 |
|
| 4779 |
dpurdie |
103 |
#-------------------------------------------------------------------------------
|
|
|
104 |
# Function : isaJatsKeyPod
|
|
|
105 |
#
|
|
|
106 |
# Description : Test a specified file to see if its a Jats Key Documentation file
|
|
|
107 |
# Used to filter in POD inn cases where it might outherwise be excluded
|
|
|
108 |
#
|
|
|
109 |
# The test is simple
|
|
|
110 |
# If the file contains a POD section and that section contains the keyword
|
|
|
111 |
# =for htmltoc
|
|
|
112 |
# Then it is assumed that this file conatins JATS POD
|
|
|
113 |
#
|
|
|
114 |
# Inputs : $fname - Path to file to examine
|
|
|
115 |
#
|
|
|
116 |
# Returns : True - Include this file
|
|
|
117 |
#
|
|
|
118 |
|
|
|
119 |
sub isaJatsKeyPod
|
|
|
120 |
{
|
|
|
121 |
my ($fname) = @_;
|
|
|
122 |
my $podSeen;
|
|
|
123 |
my $jatsKeyPod = 0;
|
|
|
124 |
|
|
|
125 |
open (my $file, '<', $fname) || return 0;
|
|
|
126 |
while (<$file>)
|
|
|
127 |
{
|
|
|
128 |
if ( ! $podSeen) {
|
|
|
129 |
if (m~^=pod~) {
|
|
|
130 |
$podSeen = 1;
|
|
|
131 |
}
|
|
|
132 |
next;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
if (m~^=head~) {
|
|
|
136 |
last;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
if ( m~^=for\s+htmltoc~ )
|
|
|
140 |
{
|
|
|
141 |
$jatsKeyPod = 1;
|
|
|
142 |
last;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
close $file;
|
|
|
147 |
return $jatsKeyPod;
|
|
|
148 |
}
|
|
|
149 |
|
| 361 |
dpurdie |
150 |
1;
|