Subversion Repositories DevTools

Rev

Rev 379 | Rev 5709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
361 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2011 Vix Technology, All rights reserved
3
#
4
# Module name   : TOC.pm
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Create a table of contents
10
#
11
#......................................................................#
12
package JatsDocTools::TOC;
13
 
14
use strict;
15
use warnings;
16
 
17
use Config qw(%Config);
18
use File::Basename qw(fileparse);
19
use File::Find qw(find);
20
use Data::Dumper;
21
 
22
# This should be set by user.
23
our $dirbase = 'html';
24
our $cacheDir = '';
25
 
26
#
27
#   Categorise many known PODS
28
#   Used mainly by '=for htmltoc' constructs
29
#
30
my %TocCats = (
31
    CORE            => 'Core',
32
    JATS            => 'Jats',
33
    DEPLOY          => 'Deploy',
34
    MAKEUTIL        => 'mutil',
35
    SYSUTIL         => 'sutil',
36
    FAQ             => 'faq',
37
);
38
 
39
sub new {
40
    my($class, $options) = @_;
41
    my $self = $options ? $options : {};
42
 
43
    _ReadPodToc($self);
44
    _BuildHashes($self);
45
    return bless($self, $class);
46
}
47
 
48
#-------------------------------------------------------------------------------
49
# Function        : _ReadPodToc
50
#
51
# Description     : Read in the Toc data from PODS
52
#                   The file is maintained by the pos2html portion
53
#                   Conatins results of the '=for htmltoc' meta data
54
#                   ie: The Pod specifies the TOC category
55
#
56
# Inputs          : None
57
#
58
# Returns         : Populates $self->{Toc}
59
#
60
sub _ReadPodToc()
61
{
62
    my($self) = @_;
63
    if ( $cacheDir )
64
    {
65
        my $toccache = "$cacheDir/pod2htmt.tmp";
66
        open(CACHE, "<$toccache") ||
4386 dpurdie 67
            die "$0: error opening(toccache) $toccache for reading: $!\n";
361 dpurdie 68
        $/ = "\n";
69
 
70
        #
71
        #   Skip first two lines
72
        #       PodPath
73
        #       PodRoot
74
        $_ = <CACHE>;
75
        $_ = <CACHE>;
76
 
77
        #
78
        #   Read in TOC
79
        #       Meta data => File Path
80
        #
81
        my %Toc;
82
        while (<CACHE>) {
83
            /(.*?) (.*)$/;
84
            $Toc{$1} = $2;
85
        }
86
        $self->{Toc} = \%Toc;
87
        close(CACHE);
88
    }
89
}
90
 
91
 
92
 
93
# generic structure for the website, HTML help, RDF
94
sub TOC {
95
    my($self) = @_;
96
 
97
    # generic header stuff
98
    my $output = $self->boilerplate;
99
    $output .= $self->header;
100
 
101
    # FAQ
102
    $output .= $self->before_faq;
103
    $self->preProcFaq();
104
    foreach my $heading ( sort keys %{$self->{Faqs}} )
105
    {
106
        $output .= $self->before_faq_section($heading);
107
        $output .= $self->faq_section($_, $heading) for sort {uc($a) cmp uc($b)} keys %{$self->{Faqs}{$heading}};
108
        $output .= $self->after_faq_section;
109
    }
110
    $output .= $self->after_faq;
111
 
112
    # Core Documentstion
113
    $output .= $self->before_Core;
114
    $output .= $self->Core($_) for sort {uc($a) cmp uc($b)} keys %{$self->{Core}};
115
    $output .= $self->after_Core;
116
 
117
    # Build and Make Documentstion
118
    $output .= $self->before_Jats;
119
    $output .= $self->Jats($_) for sort {uc($a) cmp uc($b)} keys %{$self->{Jats}};
120
    $output .= $self->after_Jats;
121
 
122
    # Make utilities
123
    $output .= $self->before_mutil;
124
    $output .= $self->mutil($_) for sort {uc($a) cmp uc($b)} keys %{$self->{mutil}};
125
    $output .= $self->after_mutil;
126
 
127
    # Deployment Utilities
128
    $output .= $self->before_Deploy;
129
    $output .= $self->Deploy($_) for sort {uc($a) cmp uc($b)} keys %{$self->{Deploy}};
130
    $output .= $self->after_Deploy;
131
 
132
 
133
    # User Utilities
134
    $output .= $self->before_general;
135
    $self->preProcGeneral();
136
    foreach my $heading ( sort keys %{$self->{GenSec}} )
137
    {
138
        $output .= $self->before_general_section($heading);
139
        $output .= $self->general_section($_, $heading) for sort {uc($a) cmp uc($b)} keys %{$self->{GenSec}{$heading}};
140
        $output .= $self->after_general_section;
141
    }
142
    $output .= $self->after_general;
143
 
144
    # System Utils
145
    $output .= $self->before_sutil;
146
    $output .= $self->sutil($_) for sort keys %{$self->{sutil}};
147
    $output .= $self->after_sutil;
148
 
149
    $output .= $self->footer;
150
 
151
    return $output;
152
}
153
 
154
 
155
sub _BuildHashes {
156
    my $self = shift;
157
 
158
    die "htmldir not found at: $dirbase" unless -d $dirbase;
159
 
160
    my @checkdirs = qw(TOOLS);
161
    my (%files, %General, %Local);
162
 
163
    my $Process = sub {
164
        return if -d;
165
        my $parsefile = $_;
166
 
167
        my($filename,$dir,$suffix) = fileparse($parsefile,'\.html');
168
 
169
        if ($suffix !~ m#\.html#) { return; }
170
 
171
        my $TOCdir = $dir;
172
 
173
        $filename =~ s/(.*)\..*/$1/;
174
 
175
        $TOCdir =~ s#/#::#g;
176
        $TOCdir =~ s#.*?::TOOLS::#TOOLS::#;
177
        $dir =~ s~^\Q$dirbase\E/~~;
178
        $dir =~ s~/*$~~;
179
 
180
        my $TOCName = $filename;
181
        $TOCName =~ s~^jats_~~;
182
 
183
        if ( exists $self->{Toc}{"$dir/$filename.html"} )
184
        {
185
            $TOCdir = delete $self->{Toc}{"$dir/$filename.html"};
186
            unless ( $TOCdir =~ m~::$~ )
187
            {
188
                $TOCdir =~ m~(.+::)(.+)$~;
189
                $TOCName = $2;
190
                $TOCdir = $1;
191
            }
192
        }
193
        if ($files{"$TOCdir$TOCName"}) {
194
            warn "$parsefile: REPEATED!\n"
195
                unless ( $files{"$TOCdir$TOCName"} eq "$dir/$filename.html"  );
196
        }
197
        $files{"$TOCdir$TOCName"} = "$dir/$filename.html";
198
        return 1;
199
    };
200
 
201
    foreach my $dir (@checkdirs) {
202
 
203
    next unless -d "$dirbase/$dir";
204
    find({ wanted => $Process, no_chdir => 1 }, "$dirbase/$dir");
205
    }
206
 
207
    #
208
    #   Process user specified Toc entries
209
    #
210
    foreach  ( keys %{$self->{Toc}} )
211
    {
212
        warn "Unused Toc entry: $_\n";
213
    }
214
 
215
 
216
    foreach my $file (keys %files) {
217
#print "$file\n";
218
 
219
        # Hard coded Toc categories
220
        $file =~ m~(.*?)::~;
221
        if ( exists $TocCats{uc($1)} ) {
222
            my $cat = $TocCats{uc($1)};
223
            $self->{$cat}{$file} =  delete $files{$file};
224
        }
225
        elsif ($file =~ /::LOCAL::/i ) {
226
            $Local{$file} =  delete $files{$file};
227
        }
228
        elsif ($file =~ /POD::FAQ::/i ) {
229
            my $name = $file;
230
            $name =~ s~_~ ~g;
231
            $self->{faq}{$file} {$name} =  delete $files{$file};
232
        }
233
        elsif ($file =~ /::LIB::Pod::/           ||
234
               $file =~ /::cvs2cl$/              ||
235
               $file =~ /::POD::Template$/       ||
236
               $file =~ /::LIB::DeployUtils::/
237
               ) {
238
            # these files are internal and support files
239
            delete $files{$file};
240
        }
241
        else
242
        {
243
            $General{$file} =  delete $files{$file};
244
        }
245
    }
246
 
247
    $self->{General} = \%General;
248
    $self->{Local}   = \%Local;
249
#print Dumper($self);
250
}
251
 
252
1;