[OpenSource.nederland.net]

TPL Compiler

OSI Certified Open Source Software Template Compiler
Current version: 1.0.5
Copyright (c) 2003 Computel Standby BV
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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
We explicitly claim no rights to the output generated by this program.

tplCompiler for Webware

Jose Galvez has adapted TPL Compiler and integrated it in the Webware for Python framework. The resulting tplCompiler for Webware has several enhancements compared to the version found here, like automatically compiling the template when needed.

Control structures/Example

The template style for this template compiler is based on the phpBB template style. There are two types of control statements that can be used in the templates. These are explained below. The dynamic content for the template can be stored in a dictionary which is then applied to the template. In the examples we call this dictionary: content_dict.

Variable substitution

Every occurrence of
{VARIABLE_NAME}
will be replaced with the content of
content_dict['VARIABLE_NAME']

Loops

A loop will show the content of a list of sub-dictionaries. This can be best explained with an example. Take for example the following content_dict:
content_dict = { 'TITLE': 'This is a title', 'ITEMS': [{ 'NAME': 'Item one', 'VALUE': 'Value one' }, { 'NAME': 'Item two', 'VALUE': 'Value two' }] }
Which can be applied to the following example template:
<html><head> <title>{TITLE}</title> </head><body> <h1>{TITLE}</h1> <table> <!-- BEGIN ITEMS --> <tr> <td>{ITEMS.NAME}</td> <td>{ITEMS.VALUE}</td> </tr> <!-- END ITEMS --> </table> </body></html>
This will result in the following output:
<html><head> <title>This is a title</title> </head><body> <h1>This is a title</h1> <table> <tr> <td>Item one</td> <td>Value one</td> </tr> <tr> <td>Item two</td> <td>Value two</td> </tr> </table> </body></html>

Release History

v1.0

Initial release

v1.0.1

Fixed a stupid bug with a docstring in the generated python module. Also added an extra example.

v1.0.2

Fixed a bug with escaping special characters. The backslash was not escaped.

v1.0.3

Added an automatic counter to every loop. In every block BLOCKNAME there is now an automatic counter BLOCKNAME.TPL_AUTO_ID. Counting starts at 1. This can be used for numbering items, id's etc.

v1.0.4

Usualy the template complains when certain data items are missing in the input-dictionary. This version provides a second parameter to the apply function that makes the template silently ignore missing data items.

v1.0.5

Fixed a bug that caused % to be displayed twice in lines where no variabled were used. Also added a command-line option to specify the output filename.

To Do

Add the option to compile a template on-the-fly

Although this will perform worse than pre-compiling a template it can be useful for testing and debugging templates.

Add more and better documentation

One thing that has caused us to write this template compiler is that existing template systems are often not very well documented. Because this project is very new we haven't had time to write decent documentation yet, but we hope that the example shown above will help you to get started.

Add more examples

Examples are a good way to demonstrate the capabilities of a software package. As soon as this website is generated using TPL Compiler we are at least going to publish all sources and templates used here.

Contact information

TPL Compiler is written and distributed by Sander Steffann. The software is developed as part of an internal project for Computel Standby BV. All sourcecode from the initial release is copyright (c) 2003 Computel Standby BV and distributed under the GPL licence. After the initial release Mick van der Most van Spijk will help with enhancing the software and documentation. If you have any contributions to TPL Compiler please send a message to one of these developers.

Downloads

Python Distutils source distribution

RPM for Python 2.2

Source RPM

Valid XHTML 1.0! Valid CSS! Open Source
This website is provided by www.nederland.net