excess.org

Ian Ward

Consulting
GenericConsulting.ca
Software
Urwid 2008-07-14 (0.9.8.3)
Speedometer 2008-05-29 (2.6)
Templayer 2006-09-25 (1.4)
mkzip.py 2003-09-15 (1.2)
File Tosser 2001 (0.1e-6)
Writing
Tags

Home

Ian Ward's email:
first name at this domain

Facebook profile

Locations of visitors to this page

Templayer 1.4

Purpose

Templayer is a layered template library for Python. It currently supports only HTML generation, but its simple design is easily extended to support other file formats.

Templayer was created to offer an alternative to the more common ways of generating dynamic HTML: embedding code within the HTML (PHP etc.) , or embedding HTML within code (traditional CGI). Neither of these methods allow for a clean separation of the form, or layout, of a page and the function of page generation. Instead of mixing HTML and Python, two rich and extremely expressive languages, we can add a small amount of syntax to each and keep the two separate and coherent.

Documentation

The Tutorial demonstrates Templayer basics.

The Reference Manual documents the Templayer API.

Download / Changelog

Current version is 1.4

Version 1.4 browse module

Version 1.4 tarball (2006-09-25)

  * Added a django_form convenience function for using Templayer
    with the Django web framework's FormWrapper objects.

  * Added an allow_degenerate parameter to Template.__init__.  If
    set to True then a template file that is missing a contents
    block will be accepted and not cause an exception to be raised.

  * Added a special layer name '*' that treats the entire contents 
    of a template file as a layer.

  * Added two new HTML Markup elements:
    - ('pluralize',count,singular_markup,plural_markup) inserts
      singular_markup if count equals one, and plural_markup 
      otherwise.
    - ('&',entity) inserts the given HTML entity where valid
      entity values include "gt", "#161" and "#xA9".

  * FileLayer.close now returns the file object to which it wrote.
    This simplifies the code required to use Templayer in Django
    view functions.

  * Fixed a really obvious bug in the html_href function.

Version 1.3 tarball (2006-08-30)

  * Added reference documentation and a new tutorial.

  * Added an auto_reload parameter to Template.__init__ to make the
    Template.start_file function check and reload a template if it has
    been modified.  This is useful for mod_python and web frameworks
    with long-lived processes.

  * Changed the internal representation of the templates to improve
    performance for large templates and to solve an issue with
    slots being filled with text that appears to contain another
    slot that is being filled at the same time.

    The new implementation no longer allows "%" and "{" characers in
    slot and layer names.

  * The Template.missing_slot function is now passed a list of 
    missing slots for a layer.  This should improve performance when 
    ignoring a large number of missing slots.

  * The HTML markup has been adjusted to make its use of <br> and <p> 
    tags more standards-compliant.

  * HtmlTemplate has been renamed to HTMLTemplate and MarkupException
    has been renamed to MarkupError.  The old names are still 
    provided for backwards compatibility.

Installation

Debian, system wide

Users of Debian may install python-templayer from the main Debian repositories.

Other Debian users add the following line to your /etc/apt/sources.list:

deb http://excess.org/ unstable main

Then issue the following commands as root to install Templayer:

apt-get update
apt-get install python-templayer

Others, system wide

Download and extract the Templayer tarball, then run the following commands in the templayer directory as root:

python setup.py install

Local install

If you don't have root access or you don't want to do a system wide install, you can download and extract the Templayer tarball, then copy the file templayer.py into the directory of each program that needs to use it.