NAME
HTML::TableTiler - easily generates graphic styled HTML tables
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 = new HTML::TableTiler(\$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 |
|
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>'
- tile_table ( matrix [, mode ] )
-
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.)
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
HTML::MagicTemplate, that supplies an extended and transparent interface to this module.
SUPPORT and FEEDBACK
I would like to have just a line of feedback from everybody who tries or actually uses this software. Feel free to write me any comment, suggestion or request.
AUTHOR
Domizio Demichelis, <dd@4pro.net>.
COPYRIGHT
Copyright (c)2002 Domizio Demichelis. All Rights Reserved. This is free software; it may be used freely and redistributed for free providing this copyright header remains part of the software. You may not charge for the redistribution of this software. Selling this code without Domizio Demichelis' written permission is expressly forbidden.
This software may not be modified without first notifying the author (this is to enable me to track modifications). In all cases the copyright header should remain fully intact in all modifications.
This code is provided on an "As Is'' basis, without warranty, expressed or implied. The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall the author, be liable for any special, indirect or consequential damages or any damages whatsoever including but not limited to loss of use, data or profits. By using this software you agree to indemnify the author from any liability that might arise from it is use. Should this code prove defective, you assume the cost of any and all necessary repairs, servicing, correction and any other costs arising directly or indrectly from it is use.
The copyright notice must remain fully intact at all times. Use of this software or its output, constitutes acceptance of these terms.