htmltmpl-1.22/doc/examples/products.py 0100664 0000764 0000764 00000003163 07344073045 016641 0 ustar trip trip
import MySQLdb
import MySQLdb.cursors
from htmltmpl import TemplateManager, TemplateProcessor
# Define some constants.
DB = "test"
USER = ""
PASSWD = ""
TABLE = """
CREATE TABLE IF NOT EXISTS Products (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
CONSTRAINT pkey_id
PRIMARY KEY(id)
)
"""
template = TemplateManager().prepare("products.tmpl")
tproc = TemplateProcessor()
# Assign a string to template variable named "title".
tproc.set("title", "Our products")
# Connect the database. Create the table.
db = MySQLdb.connect(db = DB, user = USER, passwd = PASSWD,
cursorclass = MySQLdb.cursors.DictCursor)
create_cur = db.cursor()
create_cur.execute(TABLE)
create_cur.close()
# Insert some data.
insert_cur = db.cursor()
insert_cur.executemany("""
INSERT INTO Products (name) VALUES (%(name)s)
""", [
{"name": "Seagate"},
{"name": "Conner"},
{"name": "Maxtor"}
])
insert_cur.close()
# Select the products.
products_cur = db.cursor()
products_cur.execute("""
SELECT id, name
FROM Products
""")
# Append product data in form of mappings (dictionaries) to the
# products list.
products = []
for i in range(products_cur.rowcount):
products.append(products_cur.fetchone())
products_cur.close()
db.close()
# Assign the products list to template loop identifier 'Products'.
# NOTE: htmltmpl automatically converts all the values
# to strings using str().
tproc.set("Products", products)
# Process the template and print the result.
print tproc.process(template)
htmltmpl-1.22/doc/examples/products.tmpl 0100664 0000764 0000764 00000000544 07342033601 017155 0 ustar trip trip
The documentation of this module can be found in 'doc' directory of the
distribution tarball or at the website of this package.
Latest versions of this module are also available at that website.
You can use and redistribute this module under conditions of the
GNU General Public License that can be found either at
http://www.gnu.org/ or in file "LICENSE" contained in the
distribution tarball of this module.
Copyright (c) 2001 Tomas Styblo, tripie@cpan.org
Prague, the Czech Republic
This class provides all the functionality of easydoc. You can
subclass it and override its processing methods module(),
mclass() and method() to customize its behaviour.
You also can easily use your own template to modify the output
in any way you need. Output colors can be customized via
parameters.
Easydoc is an example application that uses htmltmpl
to provide flexible HTML output. It can process docstrings
embedded in source file of a module and generate proper XHTML
documentation from them. It's very similar to the
javadoc program used by Java applications.
The API documentation for htmltmpl and easydoc itself
is auto-generated by easydoc.
The purpose of the program is to ease maintenance of
documentation. It's very annoying to maintain more
versions of documentation at once - docstrings in a source
file and a HTML form of them which is much more convenient
for common users. After a while the two versions always fail
to be synchronized and become a maintenance nightmare.
The solution is to maintain the documentation only in form
of docstrings in the source code and generate the HTML version
automatically from them.
Of course, many other solutions exist for this purpose. This
program was created to be similar to javadoc and as a
test application for htmltmpl. The default template it uses
is quite complex; it contains loops which are nested
four levels deep. You can replace the default template with
your own one to customize the output.
Easydoc is now part of the htmltmpl distribution and is
automatically installed when you install htmltmpl.
There also is a script called easy.py which provides
command line interface to the module. It's included in the
distribution. Run it without any parameters to view
usage instructions.
The API documentation of the easydoc module can be found
here.
This example documented module illustrates and describes the special
syntax of docstrings which easydoc requires. The syntax is similar to
that of javadoc.
""" Short one line description of the module.
Detailed description of the module which can span more lines. You can
use HTML tags here, but you should use only in-line tags which will not
break the page. Do NOT use <p> or <br> tags to separate
paragraphs. Instead use empty lines which are automatically converted
to paragraph separators. HTML brackets which are not part of a tag
should be written as appropriate HTML entities. All strings in form
[ http://some.url.com ] are automatically converted to
hyperlinks.
After the detailed description comes the 'meta' section which should be
used to give the docstring processor some structured information about
the section which is being documented. It uses special statements which
begin with the '@' character. This character is ignored if it isn't the
first non-whitespace character on a line. URLs in parameters that
specify an URL should _NOT_ be written in the special hyperlink form
described above.
@name easydoc
@version 1.00
@website http://htmltmpl.sourceforge.net/
@author-name Tomas Styblo
@author-email tripie@cpan.org
@license-name GNU GPL
@license-url http://www.gnu.org/licenses/gpl.html
@require htmltmpl ([ http://htmltmpl.sourceforge.net ])
@require some other prerequisite ...
"""
class Example:
""" One line description of the class. End it with a dot if appropriate.
Detailed description which can span more lines. You can use HTML tags
here, but you should use only in-line tags which will not break the page.
Do NOT use <p> or <br> tags to separate paragraphs. Instead
use empty lines which are automatically converted to paragraph separators.
HTML brackets which are not part of a tag should be written as appropriate
HTML entities. Code examples must be placed inside a <pre> block.
After the detailed description comes the 'meta' section which should
be used to give the docstring processor some structured information
about the section which is being documented. It uses special statements
which begin with the '@' character. This character is ignored if it isn't
the first non-whitespace character on a line.
@hidden The meta section can contain some special processing instructions.
The @hidden instruction can be used to exclude the section which is being
documented from the resulting documentation. This is useful for private
classes and methods.
The sections marked as hidden can be included in the output if you use
the '--with-hidden' command line option of easydoc.
"""
def method(param1, param2=""):
""" Short one line description of the method.
Detailed description of the method. Same rules as for detailed
descriptions of classes apply here.
The header statement below must contain a full header of the method,
as it appears in the code. It's used for quick overview of the
method's parameters and their default values. Do not include the
self parameter of methods here.
@return Short one line description of return value.
Here comes detailed description of the return value. It can span
more lines and contain appropriate HTML markup. You should explicitly
document cases when the method has no return value.
@header
method(param1, param2="")
@param param1 One Line description of parameter.
More detailed description of the 'param' parameter which again can
span more lines and contain HTML tags. These detailed descriptions
are terminated by either end of the docstring or by another statement.
The detailed descriptions also can consist of more paragraphs
separated by an empty line.
@param param2 One line description of parameter.
Detailed description of the second parameter.
@hidden This statement has the same meaning as in classes.
"""
This section is a description of the gettext support integrated in
htmltmpl. It's of interest for anyone who would like to use htmltmpl
to easily build a multilingual web application.
The section describes only the gettext support in htmltmpl. Please
refer to other sources for general info on gettext and its
principles. The info manual for gettext should be included in every
modern UNIX distribution.
The gettext support in htmltmpl must be explicitely activated by
setting the parameter 'gettext' of TemplateManager or
TemplateCompiler constructor to TRUE.
The support will not work if your computer's locale system is not
installed properly or if your Python or PHP interpreter is not
configured to support locales and gettext. In Python, gettext support
is part of the standard library. PHP must be compiled using the
'--with-gettext' parameter, otherwise an attempt to use
htmltmpl in gettext mode will result in a "call to undefined
function" error.
The brackets will be removed when the template is processed.
If you need to include opening brackets somewhere in the text of the
template, you can escape them using a backslash. In the following example
the brackets will not be removed and the word 'jumps' will not be translated.
The backslash will be removed always and only when it is placed right before
opening or closing double brackets.
Quick brown fox \[[jumps]] over a lazy dog.
Sometimes we need to use the backslash '\'.
... will be printed as:
Quick brown fox [[jumps]] over a lazy dog.
Sometims we need to use the backslash '\'.
In some rare cases you need to print a backslash right before double
brackets. You can use another backslash to escape the backslash. In that
case, one backslash will be printed and the translation will take place.
In the following example the word 'jumps' will be translated:
Quick brown fox \\[[jumps]] over a lazy dog.
... will be printed as:
Quick brown fox \jumps over a lazy dog.
The backslash can also be used to include closing double brackets in a text
which should be translated. In the following example, the double brackets
are taken as a part of the text to be translated. That means, the whole
text 'jumps over ]] a lazy' will be translated.
Quick brown fox [[jumps over \]] a lazy]] dog.
A backslash always escapes another backslash. That means that to print two
backslashes, you must write four of them. An example:
This will print one backslash: \.
This will print one backslash: \\.
This will print two backslashes: \\\\.
... will be printed as:
This will print one backslash: \.
This will print one backslash: \.
This will print two backslashes: \\.
tmpl-xgettext
The gettext strings must usually be extracted using the xgettext program.
The standard xgettext program cannot work with htmltmpl templates, though.
You must use the tmpl-xgettext.pl script which is included in htmltmpl
distribution to convert the templates into a format which xgettext can
understand.
Your program must initialize gettext before it calls the
process() method
of TemplateProcessor. It usually means to call setlocale(),
bindtextdomain() and textdomain() with appropriate parameters.
Check documentation of PHP or Python gettext extensions
for more information.
Also, your program is of course responsible for translation of any texts
which are assigned as values to TMPL_VARs.
The purpose of the templating engine is to provide web
application developers,
who need to separate program code and design (HTML code) of their
web application projects, with a templating tool that can be
easily used by cooperating webdesigners who have no programming
skills.
Templating language provided by the engine is inspired by Perl
templating module HTML::Template.
Templates created for HTML::Template can be used with this engine.
The engine is currently available for Python and PHP.
The Python package includes easydoc, a module
which uses the templating engine to generate HTML documentation
from docstrings embedded in source files of Python modules.
The primary goal of the templating engine is to keep things simple
for a webdesigner who creates the templates. Therefore, neither
Python nor PHP code can be used in the templates.
Instead, the templating
engine provides its own simple templating language that supports
basic programming operations like for example loops, conditionals
and substitution of variables. These operations are controlled
from within the templates by statements that look like HTML tags
and integrate nicely with regular HTML code.
The secondary goal is good performance. High speed template
processing is necessary when the engine is used by web
applications.
I am aware that other templating solutions for Python and PHP
exist.
But none of them is similar to HTML::Template. I love its
enforcement of strict separation of code and HTML and the style
and syntax of its template language.
I find it much more cleaner and maintainable than
the other solutions. Also, I need to move some projects from
Perl to Python and PHP and I want to reuse my old HTML::Template
templates. These are the reasons why I created the templating
engine.
The engine now also has an integrated support for gettext, which
makes it very convenient for development of multilingual
"skinnable" web applications.
You can use and redistribute the engine under conditions of the
GNU General Public License that can be found either at
http://www.gnu.org/
or in file "LICENSE" contained in the distribution tarball of the
engine.
Author of the engine and its documentation is not an English
native speaker. Corrections of grammar or spelling are welcome.
Credits
The engine is inspired by Perl templating module HTML::Template
created by Sam Tregar (sam@tregar.com).
Sam invented the excellent templating
language. The htmltmpl implementation, however, was designed from scratch
and is not based on code of HTML::Template.
You should check the documentation of HTML::Template.
The templating language of htmltmpl is fully compatible with
HTML::Template and the documentation of HTML::Template
describes it much better than the yet unfinished documentation
of htmltmpl.
There is a
mailing list for htmltmpl on SourceForge. Don't hesitate
to post a message if you find a bug, want to contribute a patch or
have some interesting idea.
Templates created for HTML::Template can be used with this engine
in case they do not violate character case rules of htmltmpl.
WARNING:
Template statements and their parameters must always be in uppercase.
Variable names must always be in lowercase. Loop names must be in
lowercase, but capitalized.
WARNING:
All included templates must be located in a directory named
'inc' which must be a subdirectory of the
directory in which the main template file is located. You must
refer to these templates only by their filename, ie. without
the 'inc' part of the path.
This engine offers all features of HTML::Template except:
The IPC shared cache.
The engine also offers some additional features:
Gettext support for easy creation of multilingual web applications.
Special comments in form of "### some comment" can be added
to the templates. These comments are removed when the
templates are processed.
Precompiled versions of the templates can be saved
to disk to increase performance significantly.
This feature vastly reduces the need of caching of any sort.
Multipart templates can be created using the <TMPL_BOUNDARY>
directive. Multipart templates are useful when you need to process
and output a part of the template before all data needed to process
the whole template are ready.
Additional loop context variables.
__PASS__
__PASSTOTAL__
__EVERY__x
Loop identifiers used in <TMPL_VAR> statements produce
a total number of passes in the corresponding loop.
You can override the global_vars setting on a per-variable
basis using a new 'GLOBAL' parameter.
All variables are by default automatically HTML escaped.
This can be disabled by setting the 'html_escape' parameter
to false.
Syntax overview
Statements
The control statements of the templating language look like HTML tags.
They can be written in two forms:
<TMPL_VAR>
<!-- TMPL_VAR -->
There must be exactly one space after
the opening "<!--" and before the
closing "-->" if you use the longer form.
All statements except TMPL_VAR should be placed on a separate line.
All tabs and spaces on a line before a statement are removed,
if there are no other characters except tabs and spaces between
beginning of the line and the statement.
A trailing newline after a statement is removed if there are no other
characters between the newline and the statement.
The white-space removing described above is a Good Thing, because it
keeps the HTML nicely formatted, especially when loops are involved.
If you want to preserve the newline after a statement, just add a space
or a tab after the statement.
The statements do not need to follow HTML validity rules.
For example, following usage of TMPL_VAR is absolutely valid:
<img src="<TMPL_VAR image>" />
Unrecognized TMPL_* statements are detected and TemplateError
is raised when one is found.
Statements must be completely in uppercase: for example "TMPL_VAR".
It improves readability of the templates a lot. It makes
the statements easily distinguishable from normal XHTML tags,
that are always in lowercase.
Templates must not contain the '\0' character (ASCII code zero).
Parameters of the statements
Parameters can be written in two forms:
with double quotes: <TMPL_VAR myvar ESCAPE="HTML">
without double quotes: <TMPL_VAR myvar ESCAPE=HTML>
There must not be any space between the "=" character and the name or
the value of the parameter.
Parameter names must be completely in uppercase: ESCAPE="HTML".
Predefined special values of parameters (like for example the
"HTML", "URL" and "NONE" values of the ESCAPE parameter) must
be completely in uppercase.
Parameter names and values can contain only alphanumeric characters
(non-locale) plus some additional characters: dash, dot, underscore,
colon, slash, backslash. They must NOT contain any spaces.
Identifiers
There are three types of identifiers:
names of variables
names of loops
filenames of included templates
Names of loops and variables can contain ASCII (non-locale)
alphanumeric characters, underscores and dashes. Names of loops and
variables are further restricted by the character case rules
described below.
Template filenames in TMPL_INCLUDE statements can contain only the same
characters that are allowed in values of parameters(see above). They
must NOT contain any spaces.
Minimum length of an identifier is one character.
Names of variables and loops can be specified in two ways:
as bare-words: <TMPL_VAR myvar>
as 'NAME' parameters: <TMPL_VAR NAME="myvar">
Following character case rules apply to the
names of variables and loops:
Variable names must be completely in lowercase: myvar
Loop names must be capitalized and in lowercase: Myloop
Valid statements and parameters
TMPL_INCLUDE
NAME
TMPL_VAR
NAME, ESCAPE, GLOBAL
TMPL_IF
NAME, GLOBAL
TMPL_UNLESS
NAME, GLOBAL
TMPL_ELSE
/TMPL_IF
/TMPL_UNLESS
TMPL_LOOP
NAME
/TMPL_LOOP
TMPL_BOUNDARY
Template comments
Comments are in form of "### some comment".
Everything that follows these four characters - "### " - is removed
before the template is processed.
The ending space in "### " IS significant.
Comments can be disabled using the 'comments' parameter.
Examples:
<TMPL_VAR myname> ### first comment
<TMPL_VAR hisname> ### second comment
Statements
Template inclusion
The <TMPL_INCLUDE> statement includes a template
directly into the current template at the point where the
statement is found. The included template contents are used
exactly as if its contents were physically included in the main
template.
All included templates must be located in a directory named
'inc' which must be a subdirectory of the
directory in which the main template file is located. You must
refer to these templates only by their filename, ie. without
the 'inc' part of the path.
Examples:
In this example, the file header.tmpl must be located in the
'inc' subdirectory of the directory in
which the main template file is located.
Variables defined by the TMPL_VAR statements are substituted with values
associated with them by the set() method of TemplateProcessor.
Escaping of variables
All variables are automatically HTML escaped. This can be disabled
using the 'html_escape' parameter.
Escaping of variables can also be specified on a per variable basis
using the ESCAPE parameter. This parameter overrides the default
escaping setting. It can have three values:
HTML : enable HTML escaping
URL : enable URL escaping
NONE : disable escaping
Global look-up of variables
All variables that are inside a loop are local to that loop.
If you want to reference a "global" variable from inside a loop,
then you must either enable the 'global_vars' parameter or use
the GLOBAL parameter to override 'global_vars'
setting on a per variable basis.
The TMPL_IF, /TMPL_IF, TMPL_ELSE, TMPL_UNLESS and /TMPL_UNLESS
statements are conditionals.
They mark start and end of a block that is included in the output
only when the condition is true.
Only names of variables or loops can be used
in the condition. Conditional blocks may contain other nested conditional
blocks.
If name of a loop is used in a condition, then the condition is true
if the content of the loop will be included in the output at least once.
Examples:
<TMPL_IF myvar>
This block appears in the output if myvar is true.
<TMPL_ELSE>
This block appears in the output if myvar is false.
</TMPL_IF><TMPL_UNLESS hisvar>
This block appears in the output if hisvar is false.
<TMPL_ELSE>
This block appears in the output if hisvar is true.
</TMPL_UNLESS>
Loops
TODO
The TMPL_LOOP and /TMPL_LOOP statements mark start and end of a block
which is printed once for each mapping in the list of mappings
associated with the corresponding loop.
Loops can contain other nested loops. Every loop introduces its own namespace
(scope) for variables. Variables located inside a loop cannot reference
variables located outside the loop unless the 'global_vars' parameter
is true, or unless this parameter is overridden for
this variable using the 'GLOBAL' parameter of the corresponding
TMPL_VAR statement.
Loop names used as variables in TMPL_VAR statements produce
total number of passes in the corresponding loop.
examples
<TMPL_LOOP Myloop>
This block appears in the output
once for every pass of the loop.
<TMPL_VAR myvar>### Local variable.</TMPL_LOOP>
Magic loop variables
Magic context variables are automatically defined in every loop.
They can be used the same way as normal variables. Their names always
start with two underscores.
Values of these variables are always integers (true = 1, false = 0).
Following list lists all recognized magic variables.
Any other variable name which starts with two underscores is
invalid. The TemplateError exception is raised when such a variable
name is found.
__FIRST__
This variable is true if current pass is the first pass.
__LAST__
This variable is true if current pass is the last pass.
__INNER__
This variable is true if current pass is neither first nor last pass.
__ODD__
This variable is true if number of current pass is odd.
That means it's true in the first, third, fifth, seventh ..... pass.
__PASS__
Value of this variable is the number of current pass.
Passes are counted from one. Value of this variable is one in the first
pass, two in the second pass etc.
__PASSTOTAL__
Value of this variable is total number of passes in current loop.
__EVERY__x
Where 'x' must be an integer. It can consist of more than one digit.
This variable is true if number of
current pass modulo 'x' equals to zero. The variable is never true in
first or last pass, even if the condition above is true
in such a pass. This variable can be used to put separators
between every 'x' items of a list.
Multipart templates
Multipart templates can be created using the <TMPL_BOUNDARY>
directive. This directive has no parameters.
Multipart templates are useful when you need to process
and output a part of the template before all data needed to process
the whole template are ready.
This can be useful to improve
perceived responsiveness of web applications by sending the top part of
a page to the client before the web application for example sends a slow
query to the database and generates rest of the page from results of
the query. Keep in mind that you probably will have to flush the
output stream to achieve the desired effect. This can usually be done by
calling sys.stdout.flush() in Python or flush() in PHP.
Multipart templates must follow this rule: every part itself
must be a syntactically valid template. It means that boundaries
between the parts must not be located inside a conditional block or
inside a loop block.
The boundaries are processed after template inclusions are processed.
It's possible to put the boundaries into the included templates,
tough it's not recommended.
Please consult API documentation of the TemplateProcessor.process()
method to find out how to correctly use multipart templates in
your applications.
examples
This is part one.
<TMPL_BOUNDARY>
This is part two.
<TMPL_BOUNDARY>
This is part three.
This is the PHP version of htmltmpl. This page contains
some basic information about the module and examples that
illustrate its usage.
A complete documentation of the module's API can be found
here.
It contains description of all public classes and methods which
the module provides. The documentation is automatically
generated from docstrings in source file of the
Python version of the module. There are some
minor differences between the PHP and the Python version.
These differences are described later on this page.
The PHP version of the module works on UNIX and Windows
platforms. It requires PHP 4.0.6 or newer.
If you get strange compilation errors, then your PHP is too old.
The API of the PHP version differs from the Python version in
following aspects:
Debugging is activated by pointing a global variable
$HTMLTMPL_DEBUG to a debugging logfile. No constructor takes
the 'debug' parameter in the PHP version.
All the factory methods which return an internally
constructed Template object return a
REFERENCE to it.
That means your code must use reference assignments:
$manager = new TemplateManager();
$template =& $manager->prepare($template_file);
PHP does not support exceptions. The TemplateError
exception class does not exist in the PHP version. Instead,
all problems are handled via user_error() followed
by exit().
The version numbering is mutually independent. The 1.00 release
of the PHP version was based on the Python release 1.18.
Source files of all these examples are available in 'doc/examples'
directory of the distribution. Files from the regression test
suite (the 'test' directory) can also serve as examples.
The documentation of this templating engine is separated to two parts:
1. Description of the templating language.
2. Documentation of classes and API of this module that provides
a Python implementation of the templating language.
All the documentation can be found in 'doc' directory of the
distribution tarball or at the homepage of the engine.
Latest versions of this module are also available at that website.
You can use and redistribute this module under conditions of the
GNU General Public License that can be found either at
http://www.gnu.org/ or in file "LICENSE" contained in the
distribution tarball of this module.
This optional parameter is a flag that can be used to enable or
disable automatic HTML escaping of variables.
All variables are by default automatically HTML escaped.
The escaping process substitutes HTML brackets, ampersands and
double quotes with appropriate HTML entities.
magic_vars
Enable or disable loop magic variables.
This parameter can be used to enable or disable
"magic" context variables, that are automatically defined inside
loops. Magic variables are enabled by default.
Refer to the language specification for description of these
magic variables.
global_vars
Globally activate global lookup of variables.
This optional parameter is a flag that can be used to specify
whether variables which cannot be found in the current scope
should be automatically looked up in enclosing scopes.
Automatic global lookup is disabled by default. Global lookup
can be overriden on a per-variable basis by the
GLOBAL parameter of a TMPL_VAR
statement.
debug
Enable or disable debugging messages.
METHOD:
process()
Process a compiled template. Return the result as string.
(class
TemplateProcessor)
This method actually processes a template and returns
the result.
RETURN VALUE:
Result of the processing as string.
PARAMETERS:
process(template, part=None)
template
A compiled template.
Value of this parameter must be an instance of the
Template class created either by the
TemplateManager or by the TemplateCompiler.
part
The part of a multipart template to process.
This parameter can be used only together with a multipart
template. It specifies the number of the part to process.
It must be greater than zero, because the parts are numbered
from one.
The parts must be processed in the right order. You
cannot process a part which precedes an already processed part.
If this parameter is not specified, then the whole template
is processed, or all remaining parts are processed.
METHOD:
set()
Associate a value with top-level template variable or loop.
(class
TemplateProcessor)
A template identifier can represent either an ordinary variable
(string) or a loop.
To assign a value to a string identifier pass a scalar
as the 'value' parameter. This scalar will be automatically
converted to string.
To assign a value to a loop identifier pass a list of mappings as
the 'value' parameter. The engine iterates over this list and
assigns values from the mappings to variables in a template loop
block if a key in the mapping corresponds to a name of a variable
in the loop block. The number of mappings contained in this list
is equal to number of times the loop block is repeated in the
output.
This method resets the data contained in the template processor
instance. The template processor instance can be used to process
any number of templates, but this method must be called after
a template is processed to reuse the instance,
RETURN VALUE:
No return value.
PARAMETERS:
reset(keep_data=0)
keep_data
Do not reset the template data.
Use this flag if you do not want the template data to be erased.
This way you can reuse the data contained in the instance of
the TemplateProcessor.
CLASS: TemplateError
Fatal exception. Raised on runtime or template syntax errors.
This exception is raised when a runtime error occurs or when a syntax
error in the template is found. It has one parameter which always
is a string containing a description of the error.
All potential IOError exceptions are handled by the module and are
converted to TemplateError exceptions. That means you should catch the
TemplateError exception if there is a possibility that for example
the template file will not be accesssible.
The exception can be raised by constructors or by any method of any
class.
The instance is no longer usable when this exception is raised.
CLASS: Template
This class represents a compiled template.
This class provides storage and methods for the compiled template
and associated metadata. It's serialized by pickle if we need to
save the compiled template to disk in a precompiled form.
You should never instantiate this class directly. Always use the
TemplateManager or TemplateCompiler classes to
create the instances of this class.
The only method which you can directly use is the is_uptodate
method.
Check whether the compiled template is uptodate.
(class
Template)
Return true if this compiled template is uptodate.
Return false, if the template source file was changed on the
disk since it was compiled.
Works by comparison of modification times.
Also takes modification times of all included templates
into account.
RETURN VALUE:
True if the template is uptodate, false otherwise.
PARAMETERS:
is_uptodate(compile_params=None)
compile_params
Only for internal use.
Do not use this optional parameter. It's intended only for
internal use by the TemplateManager.
CLASS: TemplateCompiler
Preprocess, parse, tokenize and compile the template.
This class parses the template and produces a 'compiled' form
of it. This compiled form is an instance of the Template
class. The compiled form is used as input for the TemplateProcessor
which uses it to actually process the template.
This class should be used direcly only when you need to compile
a template from a string. If your template is in a file, then you
should use the TemplateManager class which provides
a higher level interface to this class and also can save the
compiled template to disk in a precompiled form.
Compiled template.
The return value is an instance of the Template
class.
PARAMETERS:
compile(file)
file
Filename of the template.
See the prepare() method of the TemplateManager
class for exaplanation of this parameter.
CLASS: TemplateManager
Class that manages compilation and precompilation of templates.
You should use this class whenever you work with templates
that are stored in a file. The class can create a compiled
template and transparently manage its precompilation. It also
keeps the precompiled templates up-to-date by modification times
comparisons.
This optional parameter can be used to enable or disable
TMPL_INCLUDE inclusion of templates. Disabling of
inclusion can improve performance a bit. The inclusion is
enabled by default.
max_include
Maximum depth of nested inclusions.
This optional parameter can be used to specify maximum depth of
nested TMPL_INCLUDE inclusions. It defaults to 5.
This setting prevents infinite recursive inclusions.
precompile
Enable or disable precompilation of templates.
This optional parameter can be used to enable or disable
creation and usage of precompiled templates.
A precompiled template is saved to the same directory in
which the main template file is located. You need write
permissions to that directory.
Precompilation provides a significant performance boost because
it's not necessary to parse the templates over and over again.
The boost is especially noticeable when templates that include
other templates are used.
Comparison of modification times of the main template and all
included templates is used to ensure that the precompiled
templates are up-to-date. Templates are also recompiled if the
htmltmpl module is updated.
The TemplateErrorexception is raised when the precompiled
template cannot be saved. Precompilation is enabled by default.
Precompilation is available only on UNIX and Windows platforms,
because proper file locking which is necessary to ensure
multitask safe behaviour is platform specific and is not
implemented for other platforms. Attempts to enable precompilation
on the other platforms result in raise of the
TemplateError exception.
comments
Enable or disable template comments.
This optional parameter can be used to enable or disable
template comments.
Disabling of the comments can improve performance a bit.
Comments are enabled by default.
gettext
Enable or disable gettext support.
debug
Enable or disable debugging messages.
This optional parameter is a flag that can be used to enable
or disable debugging messages which are printed to the standard
error output. The debugging messages are disabled by default.
METHOD:
update()
Update (recompile) a compiled template.
(class
TemplateManager)
This method recompiles a template compiled from a file.
If precompilation is enabled then the precompiled form saved on
disk is also updated.
RETURN VALUE:
Recompiled template.
It's ensured that the returned template is up-to-date.
PARAMETERS:
update(template)
template
A compiled template.
This parameter should be an instance of the Template
class, created either by the TemplateManager or by the
TemplateCompiler. The instance must represent a template
compiled from a file on disk.
METHOD:
prepare()
Preprocess, parse, tokenize and compile the template.
(class
TemplateManager)
If precompilation is enabled then this method tries to load
a precompiled form of the template from the same directory
in which the template source file is located. If it succeeds,
then it compares modification times stored in the precompiled
form to modification times of source files of the template,
including source files of all templates included via the
TMPL_INCLUDE statements. If any of the modification times
differs, then the template is recompiled and the precompiled
form updated.
If precompilation is disabled, then this method parses and
compiles the template.
RETURN VALUE:
Compiled template.
The methods returns an instance of the Template class
which is a compiled form of the template. This instance can be
used as input for the TemplateProcessor.
PARAMETERS:
prepare(file)
file
Path to the template file to prepare.
The method looks for the template file in current directory
if the parameter is a relative path. All included templates must
be placed in subdirectory 'inc' of the
directory in which the main template file is located.
This is the Python version of htmltmpl. This page contains
some basic information about the module and examples that
illustrate its usage.
A complete documentation of the module's API can be found
here.
It contains description of all public classes and methods which
the module provides. The documentation is automatically
generated from docstrings in source file of the module by my
application easydoc, which uses
htmltmpl and is included in the htmltmpl distribution.
The module should work on all platforms supported by Python.
The module is supported by its author only on the UNIX
platform using Python versions 2.1 or newer.
Releases 1.15 and up are vastly redesigned to be multi-task safe
and more flexible. The design and interface
was completely changed to be much more object oriented and
more maintainable. The downside of this change is that the
interface is no longer similar to that of HTML::Template.
The module is multi-task safe in terms of properly synchronized
accesses to the precompiled templates that are loaded from and
saved to disk. However, instances of any of its classes should
NOT be shared by multiple threads.
The only exception are instances of the Template class,
which can be shared by multiple threads.
It would be possible to protect all critical data
and sections by locks to achieve complete thread safeness, but
the resulting overhead probably is not worth the effort.
I hardly can imagine a situation in which someone would want
or need to share the instances among multiple threads.
Source files of all these examples are available in 'doc/examples'
directory of the distribution. Files from the regression test
suite (the 'test' directory) can also serve as examples.
FAQ: Emacs (the 'htmlize-file' command) is used to colorify
the source code examples.
import MySQLdb
import MySQLdb.cursors
from htmltmpl import TemplateManager, TemplateProcessor
# Define some constants.
DB = "test"
USER = ""
PASSWD = ""
TABLE = """
CREATE TABLE IF NOT EXISTS Products (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
CONSTRAINT pkey_id
PRIMARY KEY(id)
)
"""
template = TemplateManager().prepare("products.tmpl")
tproc = TemplateProcessor()
# Assign a string to template variable named "title".
tproc.set("title", "Our products")
# Connect the database. Create the table.
db = MySQLdb.connect(db = DB, user = USER, passwd = PASSWD,
cursorclass = MySQLdb.cursors.DictCursor)
create_cur = db.cursor()
create_cur.execute(TABLE)
create_cur.close()
# Insert some data.
insert_cur = db.cursor()
insert_cur.executemany("""
INSERT INTO Products (name) VALUES (%(name)s)
""", [
{"name": "Seagate"},
{"name": "Conner"},
{"name": "Maxtor"}
])
insert_cur.close()
# Select the products.
products_cur = db.cursor()
products_cur.execute("""
SELECT id, name
FROM Products
""")
# Append product data in form of mappings (dictionaries) to the
# products list.
products = []
for i in range(products_cur.rowcount):
products.append(products_cur.fetchone())
products_cur.close()
db.close()
# Assign the products list to template loop identifier 'Products'.
# NOTE: htmltmpl automatically converts all the values
# to strings using str().
tproc.set("Products", products)
# Process the template and print the result.
print tproc.process(template)
TITLE: OK
VAR1: OK
VAR3: OK
VAR8-1: OK
VAR8-2: OK
htmltmpl-1.22/test/nestcond.tmpl 0100664 0000764 0000764 00000001651 07341332026 015525 0 ustar trip trip
htmltmpl-1.22/CODING 0100664 0000764 0000764 00000000571 07341331774 012732 0 ustar trip trip
Please follow this code style:
Indent size is 4 spaces.
Use spaces instead of real tabs.
Never exceed maximum line width of 79 characters.
Use (extend) the test suite.
Function and variable naming style: cool_variable, cool_function
All function and variable names are in lowercase.
Class naming style: MyClass
htmltmpl-1.22/Changes 0100664 0000764 0000764 00000010757 07406736266 013355 0 ustar trip trip
1.22 : 2001/12/10
- precompilation with gettext bugfix (compile_params missing gettext)
1.21 : 2001/11/28
- this release fixes a major bug in the new gettext support
1.20 : 2001/11/25
- New major feature: integrated GETTEXT support which is
ideal for easy creation of multilingual web applications.
Check the documentation for description of this new feature.
- documentation enhancements (clarification of included templates)
1.18 : 2001/10/08
- new feature: multipart templates.
They can be created using the new directive.
Please see the updated Language reference documentation
for more information about this new feature.
- rewritten parser:
- bugfix: multiple parameters now can be specified in any order
- better performance of parsing of template inclusions
- bugfix: the magic variable __EVERY__x now works also if x > 9
- extended test-suite
- some small documentation fixes
1.17 : 2001/09/03
- Added the "binary" flag to open() where it's appropriate.
This could cause problems on Windows.
- The most important function - TemplateProcessor().process() -
was optimized and is now twice faster. The template
'test/complex.tmpl' can be processed 50x per second on my K6-350,
when it's precompiled in memory.
- The default template of easydoc was somewhat enhanced and is now
indented properly.
- easy.py has new option "--methodbg"
1.16 : 2001/09/02
- bugfix in easydoc: hidden classes were not hidden
1.15 : 2001/09/01
- !! This release is a major redesign of the module.
It's incompatible with code using the old interface.
I tried to make the old interface as similar to HTML::Template
as possible, but it apparently was not a good idea, because
design of HTML::Template is not much object oriented.
So, please check the documentation for description of the
new much more flexible interface. !!
- The module is now multitask safe on UNIX and Windows
platforms (precompiled '.tmplc' files are now properly locked).
On Macintosh the locking is not implemented and precompilation
is disabled on that platform. Anyone willing to implement the
file locking on Mac ?
- Corrupted or incompatible .tmplc files are now transparently
detected, removed and recreated.
- Templates are now recompiled, if the precompiled form was compiled
with different 'include', 'max_include' or 'comments' settings.
- Templates now can be compiled also from strings.
- Test suite enhancements.
1.14 : 2001/08/26
- documentation updates
1.13 : 2001/08/26
- documentation updates & spellchecking
- new examples in 'doc'
- some pyChecker cleanups
1.10 : 2001/08/25
- !! Please note that you must delete all your old compiled
templates (.tmplc files) before you upgrade to this version.
This version introduces a new format of .tmplc files which is
not compatible with the old one. !!
- !! Exceptions TmplEx and FatalEx were removed. New exception
TemplateError replaces them both. !!
- FIXED: self._include_files list was not reset when the template
has changed on the disk and was recompiled
- FIXED: invocation of os.stat() on an included template which
may be no longer accessible
- new optimization: see merge_statements()
- unrecognized TMPL_* statements are now detected and TemplateError
is raised if one is found (it's more compatible with HTML::Template)
- unrecognized magic variables are now detected and TemplateError is
raised when one is found
- better exception handling
- OO design polishing => moved template metadata to a new separate
Metadata class
- the new .tmplc format is much more extensible
- some code was replaced with library functions from os.path
- some variables and methods now have more descriptive names
- documentation enhancements
- added this Changes file
- general code polishing
1.00 : 2001/08/15
- first release
- submitted to the Vaults of Parnassus
htmltmpl-1.22/LICENSE 0100664 0000764 0000764 00000043100 07341332001 013024 0 ustar trip trip
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
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
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
htmltmpl-1.22/MANIFEST 0100664 0000764 0000764 00000003407 07407003206 013163 0 ustar trip trip CODING
Changes
LICENSE
MANIFEST
MANIFEST.in
README
TODO
VERSION
easy.py
easydoc.py
easydocp.py
htmltmpl.py
setup.py
test.py
tmpl-xgettext.pl
doc/easydoc-api.html
doc/easydoc.html
doc/gettext.html
doc/index.html
doc/lang.html
doc/main.css
doc/makedoc.sh
doc/php.html
doc/python-api.html
doc/python.html
doc/examples/products.html
doc/examples/products.py
doc/examples/products.tmpl
doc/examples/template.html
doc/examples/template.py
doc/examples/template.tmpl
test/cached.py
test/cached.res
test/cached.tmpl
test/compiled.py
test/compiled.res
test/compiled.tmpl
test/complex.py
test/complex.res
test/complex.tmpl
test/else.py
test/else.res
test/else.tmpl
test/escape.py
test/escape.res
test/escape.tmpl
test/foot.inc
test/globalvars.py
test/globalvars.res
test/globalvars.tmpl
test/head.inc
test/if.py
test/if.res
test/if.tmpl
test/include.py
test/include.res
test/include.tmpl
test/loop.py
test/loop.res
test/loop.tmpl
test/maxinclude.py
test/maxinclude.res
test/maxinclude.tmpl
test/multipart.py
test/multipart.res
test/multipart.tmpl
test/nestcond.py
test/nestcond.res
test/nestcond.tmpl
test/nestloop.py
test/nestloop.res
test/nestloop.tmpl
test/params.py
test/params.res
test/params.tmpl
test/simple.py
test/simple.res
test/simple.tmpl
test/unless.py
test/unless.res
test/unless.tmpl
test/badtmpl/README
test/badtmpl/head.inc
test/badtmpl/notclosecond.py
test/badtmpl/notclosecond.tmpl
test/badtmpl/notcloseloop.py
test/badtmpl/notcloseloop.tmpl
test/badtmpl/notopencond.py
test/badtmpl/notopencond.tmpl
test/badtmpl/notopenloop.py
test/badtmpl/notopenloop.tmpl
test/gettext/.test-gettext.py.swp
test/gettext/en.po
test/gettext/gettext.tmpl
test/gettext/test-gettext.py
test/gettext/test.po
test/gettext/locale/en/LC_MESSAGES/test.mo
test/inc/inc1.tmpl
test/inc/inc2.tmpl
test/inc/recurse.tmpl
htmltmpl-1.22/MANIFEST.in 0100664 0000764 0000764 00000000415 07400313400 013555 0 ustar trip trip include LICENSE
include README
include TODO
include VERSION
include CODING
include MANIFEST
include MANIFEST.in
include Changes
include test.py
include easy.py
include tmpl-xgettext.pl
recursive-include test *
recursive-include doc *
global-exclude *.pyc *.tmplc *cvs*
htmltmpl-1.22/README 0100664 0000764 0000764 00000001013 07362502002 012677 0 ustar trip trip
htmltmpl
========
A Python based templating engine for separation of code and HTML.
To run the regression tests (recommended):
python test.py
To install the module:
(become root)
python setup.py install
Documentation can be found in the 'doc' directory or at the homepage
of this module:
http://htmltmpl.sourceforge.net/
AUTHOR: Tomas Styblo, tripie@cpan.org
LICENSE: GNU GPL (included in file "LICENSE")
htmltmpl-1.22/TODO 0100664 0000764 0000764 00000000262 07344073044 012525 0 ustar trip trip
- Locking of .tmplc files on Macintosh to make the module thread safe
on this platform (making the precompilation of templates possible
on this platform).
htmltmpl-1.22/VERSION 0100664 0000764 0000764 00000000005 07406735572 013112 0 ustar trip trip 1.22
htmltmpl-1.22/easy.py 0100775 0000764 0000764 00000022752 07344516433 013367 0 ustar trip trip #!/usr/bin/env python
import sys
import getopt
import easydoc
BGCOLOR = "#d8d0a4"
TEXTCOLOR = "black"
LINKCOLOR = "red"
METHODBG = "#d8e0d4"
TEMPLATE = """
: documentation
VERSION:
AUTHOR:
()
WEBSITE:
LICENSE:
REQUIRES:
FUNCTIONS:
CLASSES:
:
FUNCTION: ()
PARAMETERS:
CLASS:
METHODS:
METHOD: ()
(class
)
### Constructors do not have return value.
RETURN VALUE:
PARAMETERS:
"""
def main():
try:
optlist, args = getopt.getopt(sys.argv[1:], "h", ["with-hidden",
"help",
"debug",
"template=",
"bgcolor=",
"textcolor=",
"linkcolor=",
"methodbg="])
except:
help("Invalid options.")
# Process parameters.
module = None
output = None
if len(args) == 0:
help("Missing parameters.")
elif len(args) == 2:
module = args[0]
output = args[1]
else:
help("Invalid number of parameters.")
# Process options.
with_hidden, debug = 0, 0
bgcolor, textcolor, linkcolor = BGCOLOR, TEXTCOLOR, LINKCOLOR
methodbg = METHODBG
template = TEMPLATE
for x in optlist:
opt, value = x
if opt == "-h" or opt == "--help":
help()
elif opt == "--template":
f = open(value)
template = f.read()
f.close()
elif opt == "--with-hidden":
with_hidden = 1
elif opt == "--debug":
debug = 1
elif opt == "--bgcolor":
bgcolor = value
elif opt == "--textcolor":
textcolor = value
elif opt == "--linkcolor":
linkcolor = value
elif opt == "--methodbg":
methodbg = value
easy = easydoc.Easydoc(template, debug)
out = open(output, "w")
out.write(easy.process(module, bgcolor, textcolor, linkcolor, methodbg, with_hidden))
out.close()
def help(error=""):
print "easydoc for Python, version", easydoc.VERSION
print "(c) 2001 Tomas Styblo, tripie@cpan.org"
print
if error: print error
print
print "easy