pecan.templating – Pecan Templating

The pecan.templating module includes support for a variety of templating engines, plus the ability to create your own template engines.

class pecan.templating.ExtraNamespace(extras={})

Bases: object

Extra variables for the template namespace to pass to the renderer as named parameters.

Parameters:extras – dictionary of extra parameters. Defaults to an empty dict.

Returns the lazily created template namespace.


Updates the extra variable dictionary for the namespace.

class pecan.templating.JinjaRenderer(path, extra_vars)

Bases: object

Defines the builtin Jinja renderer.

render(template_path, namespace)

Implements Jinja rendering.

class pecan.templating.JsonRenderer(path, extra_vars)

Bases: object

Defines the builtin JSON renderer.

render(template_path, namespace)

Implements JSON rendering.

class pecan.templating.MakoRenderer(path, extra_vars)

Bases: object

Defines the builtin Mako renderer.

render(template_path, namespace)

Implements Mako rendering.

class pecan.templating.RendererFactory(custom_renderers={}, extra_vars={})

Bases: object

Manufactures known Renderer objects.

  • custom_renderers – custom-defined renderers to manufacture
  • extra_vars – extra vars for the template namespace

Adds a custom renderer.

Parameters:custom_dict – a dictionary of custom renderers to add

Returns true if queried renderer class is available.

Parameters:name – renderer name
get(name, template_path)

Returns the renderer object.

  • name – name of the requested renderer
  • template_path – path to the template

Implements Jinja renderer error formatting.

pecan.templating.format_line_context(filename, lineno, context=10)

Formats the the line context for error rendering.

  • filename – the location of the file, within which the error occurred
  • lineno – the offending line number
  • context – number of lines of code to display before and after the offending line.

Implements Mako renderer error formatting.