HTML::FormatTable - base class for formatting HTML Tables


FormatNroff documentation Contained in the FormatNroff distribution.

Index


Code Index:

NAME

Top

HTML::FormatTable - base class for formatting HTML Tables

SYNOPSIS

Top

 require HTML::FormatTable;
 @ISA = qw(HTML::FormatTable);

DESCRIPTION

Top

The HTML::FormatTable is a base class for formatting HTML tables. It is used by a class such as HTML::FormatTableNroff, which is called by the formatter HTML::FormatNroff when tables are processed.

METHODS

Top

$table = new HTML::FormatTable($formatter, %attr);

Create new table representation. Formatter is used to output table (e.g. $formatter is HTML::FormatNroff)

Attributes include

 align: table alignment (default is 'left'),
 tab: the character used in tbl to separate table cells.
       (the default is '%', and should be a character not included 
        in table text)
 page_width: the page width in inches (e.g. "6")
 width: width of table, string including the percent (eg "100%")

$table->end_row();

End the current table row.

$table->start_data(%attr);

Start new table cell.

$table->end_data();

End table cell.

$table->add_text($text);

Add text to table

$table->output();

Output the table - must be overridden by subclass.

SEE ALSO

Top

HTML::Formatter, HTML::FormatTableCell, HTML::FormatTableCellNroff, HTML::FormatTableNroff, HTML::FormatTableRow, HTML::FormatTableRowNroff

COPYRIGHT

Top

AUTHOR

Top

Frederick Hirsch <f.hirsch@opengroup.org>


FormatNroff documentation Contained in the FormatNroff distribution.
package HTML::FormatTable;

require 5.004;

use strict;
use Carp;

sub new {
    my($class, $formatter, %attr) = @_;

    my $self = bless {	
	formatter => $formatter,
	align => $attr{'align'} || 'left',
	width => $attr{'width'},
	page_width => $attr{'page_width'},
	tab => '%',
	border => 1,
	previous_rows => [],
	current_row => undef,
	data => [],
    }, $class;

    return $self;
}

sub end_row {
    my($self) = @_;

    $self->{"current_row"} = pop(@{$self->{'previous_rows'}});
}

sub start_data {
    my($self, %attr) = @_;
    
    $self->{"current_row"}->add_element(%attr);
}

sub end_data {
    my($self) = @_;
    
    $self->{"current_row"}->end_element();
}

sub add_text {
    my($self, $text) = @_;

    if(defined( $self->{"current_row"} ) &&
       $self->{"current_row"} ne "") {
	$self->{"current_row"}->add_text($text);
    } else {
	return 0;
    }
}

sub output {
    croak "FormatTable::out must be overridden\n";
}

1;