package Subs::HTMLPage;
##############################################################################
#
# DESCRIPTION: This is a superclass for a subroutine which generates an
# DESCRIPTION: HTML page.
#
# HISTORY
# HISTORY: $Log: HTMLPage.pm,v $
# HISTORY: Revision 1.3 2014/02/27 06:38:16 apsop
# HISTORY: VERSION header now shows CVS Revision
# HISTORY:
# HISTORY: Revision 1.2 2006/08/01 20:35:34 apsop
# HISTORY: Add in CVS history indicator.
# HISTORY:
# HISTORY: 0.0 created 2003-04-18
#
# VERSION: $Revision: 1.3 $
#
##############################################################################
use Subs::Sub;
@ISA = ("Subs::Sub");
use strict;
#########################################
# constructor
#########################################
sub new {
my $proto=shift;
my $self=$proto->SUPER::new();
$self->{DESCRIPTION}="Creating HTML header page";
########################
# HTML file name
########################
$self->{FILE} = shift;
$self->{TITLE}= shift;
return $self;
}
#####################
# ACESSORS:
#####################
#############################################################################
# returns a block of explanatory text which should go just under the title
#############################################################################
sub top_text {
my $self = shift;
return "";
}
#####################
# METHODS:
#####################
############################################
# first inherit init stuff and then
# generate the header file top
############################################
sub init {
my $self = shift;
###########################
# inherit the usual stuff
###########################
$self->SUPER::init();
###################################
# write the top of the header page
###################################
open HTML, ">$self->{FILE}";
print HTML "<HTML>\n";
print HTML "<HEAD>\n";
print HTML "<TITLE>$self->{TITLE}</TITLE>\n";
print HTML "</HEAD>\n";
print HTML "<BODY>\n";
print HTML "<CENTER><H1>$self->{TITLE}</H1></CENTER>\n";
print HTML $self->top_text();
close HTML;
} # end of init method
######################################################################
# empty body - specific missions should over-ride this
# to fill in the contents of the header page.
######################################################################
sub body {
}
#######################################################################
# first put the closing HTML tags in the header page, then
# record the name of the header page in the job.par
# and finally do inherited cleanup stuff
#######################################################################
sub cleanup {
my $self = shift;
##############################
# finish the file
##############################
open HTML, ">>$self->{FILE}";
print HTML "</BODY>\n";
print HTML "</HTML>\n";
close HTML;
#############################
# do any inherited stuff
#############################
$self->SUPER::cleanup();
} # end of cleanup method
#######################################################
# begin a document section with the given heading
#######################################################
sub begin_section {
my $self=shift;
my $heading=shift;
open HTML, ">>$self->{FILE}";
print HTML "<H2>$heading</H2>\n";
print HTML "<UL>\n";
close HTML;
}
###########################################################################
# end a document section. This doesn't actually do anything,
# but you should use it in case a subclass wanted to do something special
# here.
###########################################################################
sub end_section {
my $self=shift;
open HTML, ">>$self->{FILE}";
print HTML "</UL>\n";
close HTML;
}
###################################################
# begin a bulleted list
###################################################
sub begin_list {
my $self=shift;
open HTML, ">>$self->{FILE}";
print HTML "<UL>\n";
close HTML;
}
###################################################
# end a bulleted list
###################################################
sub end_list {
my $self=shift;
open HTML, ">>$self->{FILE}";
print HTML "</UL>\n";
close HTML;
}
######################################################################
# add an element to a bulleted list.
# Each item is a set of name-value pairs which will appear
# on the same line. Usually there is only one name-value pair,
# but sometimes it is useful to put two things (e.g. R.A. and Dec.)
# on the same line
######################################################################
sub item { # (name, value, name, value...)
my $self=shift;
######################################
# open the HTML file
######################################
open HTML, ">>$self->{FILE}";
print HTML "<LI>";
##################################
# loop over all name: value pairs
##################################
my $name;
my $data;
while($name=shift) {
$data=shift || "";
print HTML "<STRONG>$name</STRONG> $data\n";
}
########################
# close the HTML file
########################
close HTML;
} # end of item method
##############################################################################
# Start an HTML table with the given headings
##############################################################################
sub begin_table {
my $self = shift;
my @headings = @_;
open HTML, ">>$self->{FILE}";
print HTML "<TABLE BORDER=1>\n";
print HTML "<TR>";
foreach (@headings) {
print HTML "<TH>$_</TH>";
}
print HTML "</TR>\n";
close HTML;
} # end of begin_table method
##############################################################################
# add a row to an HTML table
##############################################################################
sub table_row {
my $self = shift;
my @data = @_;
open HTML, ">>$self->{FILE}";
print HTML "<TR>";
foreach (@data) {
print HTML "<TD>$_</TD>";
}
print HTML "</TR>\n";
close HTML;
} # end of table_row method
##############################################################################
# add a row to an HTML table
##############################################################################
sub end_table {
my $self = shift;
my @data = @_;
open HTML, ">>$self->{FILE}";
print HTML "</TABLE>";
close HTML;
} # end of end_table method