spg (version 0.1, 04 February 2008)
index
/home/muhuk/subversion/spg/release/0.1/spg.py

Static File Generator
 
Templates consist of a header part and template body. Two parts are seperated
with 2 blank lines ('\n\n\n').
 
Template body is a string which includes anchors where you want to insert other
text. Anchor are in python (string interpolation) format. For example
"%(SOME_VARIABLE_NAME)s"). Values can come from the template itself, its parent
(if present) or some other template linked.
 
Every line in header part contains one statements and if needed some arguments.
Header statements include:
 
    extend MOUNT_POINT "/path/to/parent/template"
    define SOME_CONSTANT_NAME "Value as a string"
    link SOME_VARIABLE_NAME "path/to/another/template" [extra_arguments]
    output ["/alternate/output/path"]
 
(Square brackets indicate optional arguments)
(More help on header statements at class documentation)
 
Once you have your templates prepared put them together with other files needed
(images, etc.) in a directory and run spg from command line like:
 
     spg.py /home/me/web/my/site/
 
Command line options are:
 
    -w or --overwrite:  To render and save all templates unconditionally. If you
                        don't set this parameter templates are only rendered
                        when necessary.
 
    -c or --copy:       [NOT IMPLEMENTED] Copies all files but the templates to
                        a directory or archive depending on the parameter given.
 
    -o or --output-extension:   Overrides the default output extension (html).
 
    -h or --help        Displays a not so helpful help.

 
Modules
       
getopt
os
re
sys

 
Classes
       
DefaultTemplate
DefaultTemplateServer
TemplateConstant
TemplateLink
TemplateOutput
TemplateParent

 
class DefaultTemplate
     Methods defined here:
__delitem__(self)
__getitem__(self, key)
__init__(self, server, path, source=None)
__iter__(self)
__repr__(self)
__setitem__(self)
__str__(self)
dependencies(self)
export(self)
externalDependencies(self)
getVariables(self)
has_key(self, key)
load(self, path=None)
next(self)
read(self, raw_data)
render(self, env=None, use_locals=True)
save(self)
write(self)

 
class DefaultTemplateServer
     Methods defined here:
__getitem__(self, path)
__init__(self, root_dir, output_extension='html', template_extension='tmpl', overwrite=False)
__setattr__(self, name, value)
gather(self)
getTemplate(self, path)
lastModifiedDate(self, t, d=0)
resolvePath(self, p)
writeAll(self)

 
Template = class DefaultTemplate
     Methods defined here:
__delitem__(self)
__getitem__(self, key)
__init__(self, server, path, source=None)
__iter__(self)
__repr__(self)
__setitem__(self)
__str__(self)
dependencies(self)
export(self)
externalDependencies(self)
getVariables(self)
has_key(self, key)
load(self, path=None)
next(self)
read(self, raw_data)
render(self, env=None, use_locals=True)
save(self)
write(self)

 
class TemplateConstant
    Wrapper for constants.
 
Constants are created with define statement in the header.
 
A constant statement has exactly 2 arguments. A mount point and a value as a
python expression. The value is usually a string.
 
(Multiline strings are not recognized, it would be better to create a seperate
template if multiline text is needed.)
 
  Methods defined here:
__init__(self, t, s)
__repr__(self)
__str__(self)

 
class TemplateLink
    Wrapper for linked templates.
 
Linked templates are basically templates that are rendered and used within the
main template when it is rendered. A link can be formed with link statement.
 
The link statement has 2 required arguments, a mount point and the path for the
template being linked, and 1 optional python expression for extra arguments.
 
Extra arguments override all other arguments. You may supply a python dictionary
as extra arguments for basic interpolation or you may supply a list of
dictionaries to get multiple copies of the same template (possibly) rendered
with different values.
 
  Methods defined here:
__call__(self)
__init__(self, t, s)
__repr__(self)
__str__(self, env=None, use_locals=True)
renderWithParameters(self, params, env)

 
class TemplateOutput
    Wrapper for template output
 
An output statement is required if the template will create a rendered file.
 
Output has 1 optional argument to specify an alternate output path. If it is
omitted template path is used.
 
  Methods defined here:
__call__(self)
__init__(self, t, s)
__repr__(self)

 
class TemplateParent
    Wrapper for parent templates.
 
A parent template is assigned with an extend statement in the header. The extend
statement MUST be the first of headers.
 
Extend statement accepts exactly 2 arguments; a mount point and the path for the
parent template.
 
When a template is rendered it inserts itself wherever the variable choosen as
mount point in the parent. This is done recursively so there might be as many
layers (of extension) as needed.
 
  Methods defined here:
__call__(self)
__init__(self, t, s)
__repr__(self)
__str__(self)

 
Functions
       
main()
pickOption(opts, *keys)

 
Data
        __author__ = u'Atamert \xd6l\xe7gen <muhuk@muhuk.com>'
__date__ = '04 February 2008'
__version__ = '0.1'

 
Author
        Atamert Ölçgen <muhuk@muhuk.com>