Subversion Repositories DevTools

Rev

Rev 4779 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
        {
68
            print "Ignoring $in_file\n" if $args{verbose};
69
            next;
70
        }
71
 
72
        my $out_file = "$htmldir/$in_file";
73
        $out_file =~ s/\.[a-z]+\z|\z/.html/i;
74
        if ($args{force} || !-e $out_file || (stat $in_file)[9] > (stat $out_file)[9]) {
75
            print "Making $out_file from $in_file => $pods{$key}\n"
76
                if $args{verbose};
77
 
78
            unlink($out_file);
79
            my $out_dir = dirname($out_file);
80
            mkpath($out_dir);
81
 
82
            my $depth = $in_file =~ tr,/,,;
83
            pod2html(infile  => $in_file,
84
                     outfile => $out_file,
85
                     depth   => $depth,
86
                     podroot => ".",
87
                     podpath => $podpath,
88
                     cacheDir => $cacheDir,
89
                     index   => $index,
90
                     );
91
        }
92
        else {
93
            print "Skipping $out_file\n" if $args{verbose};
94
        }
95
    }
96
 
97
#    pod2html_remove_cache_files($cacheDir);
98
    chdir($starting_cwd) or die "Can't chdir back to '$starting_cwd': $!";
99
}
100
 
101
1;