Subversion Repositories DevTools

Rev

Rev 361 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package JatsDocTools::TOC::HTML;

use strict;
use warnings;

use base 'JatsDocTools::TOC';
use Data::Dumper;

sub text {
    my $text =  join("\n", @_, "");
    return sub { $text };
}

my $genTail = '';
sub genHeader
{
    my ($title, $tip, $class, $open) = @_;
    my @tail;
    my @head;

    push @head, '<hr>',
                '<span title="' . $tip . '">',
                '<a id="clasp_'. $class . '" class="clasp" onclick="javascript:lunchboxToggle(\''. $class . '\');">',
                '<img border="1" width="9" height="9" src="images/plus.gif">',
                '<strong>'. $title . '</strong><br />',
                '</a>',
                '<ul>',
                '<div id="lunch_'. $class . '" class="lunchbox">';

    push @tail, '</ul></span></div>';
    if ( $open )
    {
        push @tail, '<script>',
                    'window.onload=lunchboxToggle(\''. $class .'\');',
                    '</script>';
    }

    $genTail = text(@tail);
    return text (@head);

}


# extra info is tedious to collect -- is done in a subclass or something.
sub extra { '' };

*header = text(''); # text ("<hr>","<strong>JATS Core Documentation</strong><br />",);
*footer = text("\n\n</div>\n</body>\n</html>");

*before_faq = genHeader( 'JATS FAQ',
                         'Selected Frequently Asked Questions on building with JATS as well as the JATS Utilities',
                         'faq', 0 );
*after_faq = $genTail;

sub faq_section {
    my($self, $file, $heading) = @_;
    my $ref = $self->{Faqs}->{$heading}{$file};
    my $tip = $file;
    $file =~ s~\s~&nbsp;~g;
    return (qq'  <li>' . _page($self->{faq}->{$ref}, $file, $self->extra($file), $tip) );
}

# Create a Hash of headings
sub preProcFaq
{
     my($self) = @_;
     my %Faqs;
     foreach my $faq ( keys %{$self->{faq}})
     {
        my $data = $faq;
        $faq =~ s~.*FAQ::~~;
        my @data = split ('::', $faq );
        if ( $data[1] ) {
            $Faqs{$data[0]}{$data[-1]} = $data;
        } else {
            $Faqs{''}{$data[0]} = $data;
        }
     }
    $self->{Faqs} = \%Faqs;
#print Dumper($self->{Faqs});
#print Dumper($self->{faq});
}

sub after_faq_section { '';}
sub before_faq_section
{
    my($self, $header) = @_;
    if ( $header )
    {
        return ('<div class="tocsubheading">' . $header . '</div>');
    }
}


*before_Jats = genHeader( 'Build and Make',
                          'Utilities to build and make JATS packages',
                          'Jats',1 );
*after_Jats = $genTail;
sub Jats {
    my($self, $file) = @_;
    return (qq'  <li>' . _page($self->{Jats}->{$file}, $file, $self->extra($file)));
}

*before_Deploy = genHeader( 'Deployment Utilities',
                            'Utilities to assist in the deployment process',
                            'Deploy' );
*after_Deploy = $genTail;
sub Deploy {
    my($self, $file) = @_;
    return (qq'  <li>' . _page($self->{Deploy}->{$file}, $file, $self->extra($file)));
}

*before_Core = genHeader( 'Core Documentation',
                          'Information about the JATS environment',
                          'core', 1 );
*after_Core = $genTail;
sub Core {
    my($self, $file) = @_;
    return (qq'  <li>' . _page($self->{Core}->{$file}, $file, $self->extra($file)));
}


*before_sutil = genHeader( 'System Utilities',
                           'Utilities used by the JATS build system. These utilities are not normally used directly by users.',
                           'sutil' );
*after_sutil = $genTail;
sub sutil {
    my($self, $file) = @_;
    return (qq'  <li>' . _page($self->{sutil}->{$file}, $file, $self->extra($file)));
}

*before_general = genHeader(
                    'User Utilities',
                    'Command line utilities available to users.',
                    'General', 1
                    );
*after_general = $genTail;

# Create a Hash of headings
sub preProcGeneral
{
     my($self) = @_;
     my %GenSec;
     foreach my $entry ( keys %{$self->{General}})
     {
        my $data = $entry;

        $entry =~ s~GENERAL::~~;
        $entry =~ s~TOOLS::(.+::)*~~;
        my @data = split ('::', $entry );
        if ( $data[1] ) {
            $GenSec{$data[0]}{$data[-1]} = $data;
        } else {
            $GenSec{''}{$data[0]} = $data;
        }
     }
    $self->{GenSec} = \%GenSec;
#print Dumper($self->{GenSec});
#print Dumper($self->{General});
}
sub after_general_section { '';}
sub before_general_section
{
    my($self, $header) = @_;
    if ( $header )
    {
        return ('<div class="tocsubheading">' . $header . '</div>');
    }
}
sub general_section {
    my($self, $file, $heading) = @_;
    my $ref = $self->{GenSec}->{$heading}{$file};
    my $tip = $file;
    $file =~ s~\s~&nbsp;~g;
    return (qq'  <li>' . _page($self->{General}->{$ref}, $file, $self->extra($file), $tip) );
}




*before_mutil = genHeader( 'Make Utilities',
                           'Utilities used by makefiles to assist in the build process. These are not normally used by CLI users.',
                           'mutil' );
*after_mutil = $genTail;
sub mutil {
    my($self, $file) = @_;
    return (qq'  <li>' . _page($self->{mutil}->{$file}, $file, $self->extra($file)));
}


sub _page {
    my($href, $text, $extra, $tip) = @_;
    die "bad arguments to _page: ($href, $text, $extra)" unless defined $href and defined $text;
    $extra ||= '';
    $extra = " $extra" if $extra;  # just to make it EXACTLY identical to the old way.
    $text =~ s~.*::~~;

    my $inner = "class=\"doc\"";
    if ( $tip )
    {
        $inner .= " title=\"$tip\"";
    }
    return qq'<a $inner href="$href">$text</a>$extra</li>\n';
}


sub boilerplate {
    return boiler_header() . boiler_links();
}

sub boiler_header {
    return <<'HERE';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<!-- Generated file. Edits will be lost -->
<title>JATS User Guide - Table of Contents</title>
<base target="JatsDoc">
<link rel="STYLESHEET" href="JatsToc.css" type="text/css">
<script type="text/javascript" src="displayToc.js"></script>
</head>


<body>
<h1>Table of Contents</h1>
HERE
}


sub boiler_links {
    my $retval = <<HERE;
<div nowrap>

<strong>Getting Started</strong><br />
<ul>
  <li><a class="doc" href="JatsWelcome.html">Welcome To JATS</a></li>
  <li><a class="doc" href="release.html">Release Notes</a></li>
  <li><a class="doc" href="TOOLS/jats.html">Introduction</a></li>
</ul>
HERE

#
#   ToDo
#  <li><a class="doc" href="install.html">Installation Guide</a></li>
#  <li><a class="doc" href="readme.html">Getting Started</a></li>
#  <li><a class="doc" href="JatsChangeLog.html">Jats Change Log</a></li>
#  <li><a class="doc" href="resources.html">More Resources</a></li>
#  <li><a class="doc" href="Copyright.html">License and Copyright</a></li>

#$retval .= <<HERE;
#<strong>JATS Components</strong><br />
#<ul>
#  <li><a class="doc" href="Components/Descriptions.html">Overview</a></li>
#</ul>
#HERE
#
    return $retval;
}

1;