NAME

HTML::TableTiler - easily generates complex graphic styled HTML tables

VERSION 1.21

The latest versions changes are reported in the Changes file in this distribution.

INSTALLATION

Prerequisites
    HTML::PullParser >= 1.0
    IO::Util         >= 1.2
CPAN
    perl -MCPAN -e 'install HTML::TableTiler'
Standard installation

From the directory where this file is located, type:

    perl Makefile.PL
    make
    make test
    make install

SYNOPSIS

the tile
    <table border="1" cellspacing="2" cellpadding="2">
    <tr>
        <td><b><i>a optional placeholder</i></b></td>
        <td>another optional placeholder</td>
    </tr>
    </table>
the code
    $matrix=[
               [ 'Balls', 'A470', 250, 2.75 ],
               [ 'Cubes', 'A520', 378, 3.25 ],
               [ 'Cones', 'A665', 186, 2.85 ]
            ];

Object-Oriented interface:

    use HTML::TableTiler;
    $tt = HTML::TableTiler->new(\$tile);
    print $tt->tile_table($matrix);

Function-Oriented interface

    use HTML::TableTiler qw(tile_table);
    print tile_table($matrix, \$tile);
the tiled table
    <table border="1" cellspacing="2" cellpadding="2">
    <tr>
        <td><b><i>Balls</i></b></td>
        <td>A470</td>
        <td>250</td>
        <td>2.75</td>
    </tr>
    <tr>
        <td><b><i>Cubes</i></b></td>
        <td>A520</td>
        <td>378</td>
        <td>3.25</td>
    </tr>
    <tr>
        <td><b><i>Cones</i></b></td>
        <td>A665</td>
        <td>186</td>
        <td>2.85</td>
    </tr>
    </table>

DESCRIPTION

HTML::TableTiler uses a minimum HTML table as a tile to generate a complete HTML table from a bidimensional array of data. It can easily produce simple or complex graphic styled tables with minimum effort and maximum speed.

Think about the table tile as a sort of tile that automatically expands itself to contain the whole data. You can control the final look of a table by choosing either the HORIZONTAL and the VERTICAL tiling mode among: PULL, TILE and TRIM.

The main advantages to use it are:

  • automatic table generation

    Pass only a bidimensional array of data to generate a complete HTML table. No worry to decide in advance the quantity of cells (or rows) in the table.

  • complex graphic patterns generation without coding

    Just prepare a simple table tile in your preferred WYSIWYG HTML editor and let the module do the job for you.

  • simple to maintain

    You can indipendently change the table tile or the code, and everything will go as you would expect.

HTML Examples

Below this paragraph you should see several HTML examples. If you don't see any example, please take a look at the Examples.html file included in this distribution: an image is worth thousands of words (expecially with HTML)!

All the examples use the code below:

common code for all the examples
01
02
03
04
05
06
07
08
09
10

$matrix=[
          [ 'Descr.', 'Item', 'Quant.','Cost', 'Price' ],
          [ 'Balls',  'A001', '101',   '2.75', '4.95'  ],
          [ 'Cubes',  'A002', '102',   '3.75', '5.95'  ],
          [ 'Cones',  'A003', '103',   '4.75', '6.75'  ],
          [ 'Tubes',  'A004', '104',   '5.75', '7.95'  ]
        ];

use HTML::TableTiler qw(tile_table);
print tile_table($matrix, $tile, $modes);

See tile and modes in each example to understand how both work in combination.
Placeholders are optional, but very useful to preview the final result.

Example #1

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile: undef (default: '<table><tr><td></td></tr></table>')

Modes: not allowed with default tile

Example #2

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder
placeholder

Modes: undef (default: H_PULL V_PULL)

Example #3

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder
placeholder

Modes: V_TILE (default: H_PULL)

Example #4

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder placeholder

Modes: undef (default: H_PULL V_PULL)

Example #5

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder placeholder

Modes: H_TILE (default: V_PULL)

Example #6

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder placeholder
placeholder placeholder

Modes: H_TILE V_TILE

Example #7

Descr. Item Quant. Cost Price
Balls A001 101 2.75 4.95
Cubes A002 102 3.75 5.95
Cones A003 103 4.75 6.75
Tubes A004 104 5.75 7.95

Tile:

placeholder placeholder
placeholder placeholder

Modes: undef (default: H_PULL V_PULL)

METHODS

new ( [tile] )

The constructor method generate a HTML::TableTiler object. It accepts one optional tile parameter that can be a reference to a SCALAR content, a path to a file or a filehandle. If you don't pass any tile to the constructor method, a plain tile will be used internally to generate a plain HTML table. A tile must be a valid HTML chunk containing at least one "<tr> ... </tr>" area. See "HTML Examples" or the Examples.html file in order to know more useful details about table tiles.

Examples of constructors:

    $tt = HTML::TableTiler->new( \$tile_scalar );
    $tt = HTML::TableTiler->new( '/path/to/table_tile_file' );
    $tt = HTML::TableTiler->new( *TABLE_TILE_FILEHANDLER );
    $tt = HTML::TableTiler->new(); # default \'<table><tr><td></td></tr></table>'
is_matrix( array_reference )

This method checks if the passed array_reference is a matrix (i.e. an array of arrays). It returns 1 on success and 0 on failure. It is called automatically by the tile_table() method unless you pass a true value as tird argument.

tile_table ( matrix [, mode ] [, checked] )

This method generates a tiled table including the data contained in matrix. The matrix parameter must be a reference to a bidimensional array:

    $matrix=[
               [ 'Balls', 'A470', '250', '2.75' ],
               [ 'Cubes', 'A520', '378', '3.25' ],
               [ 'Cones', 'A665', '186', '2.85' ]
            ];

The mode parameter must be scalar containing one or two literal words representing ROW and COLUMN tiling mode. These are the accepted modes:

H_PULL

The grafic style of each rightmost CELL in the tile will be rightward replicated. This is the default HORIZONTAL tiling mode, so if you don't explicitly assign any other H_* mode, this mode will be used by default.

H_TILE

The grafic style of each ROW in the tile will be rightward replicated.

H_TRIM

The table ROW will be trimmed to the tile ROW, and the surplus data in matrix will be ignored.

V_PULL

The grafic style of each bottommost CELL in the tile will be downward replicated. This is the default VERTICAL tiling mode, so if you don't explicitly assign any other V_* mode, this mode will be used by default.

V_TILE

The grafic style of each COLUMN in the tile will be downward replicated.

V_TRIM

The table COLUMN will be trimmed to the tile COLUMN, and the surplus data in matrix will be ignored.

Examples:

    $tt->TableTiler( \@matrix, "V_TRIM H_TILE" );
    $tt->TableTiler( \@matrix, "V_TILE" ); # default "H_PULL"
    $tt->TableTiler( \@matrix );             # default "H_PULL V_PULL"

Different combinations of tiling modes and tiles can easily produce complex tiled tables. (See "HTML Examples" or the Examples.html file for details.)

A true checked argument avoid the is_matrix method to be internally called.

FUNCTIONS

tile_table ( matrix [, tile [, mode ]] )

If you prefer a function-oriented programming style, you can import or directly use the tile_table() function:

    use HTML::TableTiler qw( tile_table );
    print tile_table( \@matrix, \$tile, "V_TILE" );
    print tile_table( \@matrix );

    # or
    use HTML::TableTiler;
    print HTML::TableTiler::tile_table( \@matrix, \$tile, "V_TILE" );
    print HTML::TableTiler::tile_table( \@matrix);

Note that you have to pass the tile as the optional second parameter, and the mode as the optional third parameter. (See method tile_table() for details).

SEE ALSO

Template::Magic::HTML, that supplies an extended and transparent interface to this module.

SUPPORT and FEEDBACK

If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?HTML::TableTiler.

AUTHOR and COPYRIGHT

© 2002-2004 by Domizio Demichelis.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 833:

Non-ASCII character seen before =encoding in '©'. Assuming ISO8859-1