emit.pl

This module contains functions to parse an HTML template file and generate HTML. It contains two entry points: emitHTML and genHTML.

eval(emitHTML($filePath),$flags); processes $filePath and emits the resulting HTML on STDOUT.
my $content = eval(genHTML($filePath),$flags); processes $filePath and returns the resulting HTML.

As shown above, calls to either routine must be wrapped in an eval (which allows locally defined variables to be referenced in the HTML template).

Download

emit.pl

Example calls

eval(emitHTML("path/to/page.ht"),$flags);
my $content = eval(genHTML("path/to/page.ht"),$flags);

Flags

The second argument is an integer that sets debugging flags; flags are enabled by adding the following together:

1save generated file to path/to/debug/page.ht.out
2save debugging information to path/to/debug/page.ht.dbg
4embed debugging information in the generated HTML
8save internal state after completion

Flags 2, 4, and 8 are primarily used to debug emit.pl (rather than the template).

Template

The HTML template file may contain Perl variable references. It may also contain preprocessing directives to cause lines to be conditionally included (or not). Preprocessing directives begin in column one and start with a hash "#".

The preprocessing directives are:

A condition may be any valid Perl expression.

The argument to #include is the path to another HTML template file that is to be included into the output.

Note: Lines with only a hash or with a hash that is followed by either a space or another hash are comments.

Example: example.ht


Send me reports of any errors or suggestions you have about my Perl scripts.
The code described on this page is Copyright 2003, 2007 Tony Lewis <tlewis@exelana.com>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.