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.

make_ns(ns)

Returns the lazily created template namespace.

update(d)

Updates the extra variable dictionary for the namespace.

class pecan.templating.GenshiRenderer(path, extra_vars)

Bases: object

Defines the builtin Genshi renderer.

render(template_path, namespace)

Implements Genshi rendering.

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.KajikiRenderer(path, extra_vars)

Bases: object

Defines the builtin Kajiki renderer.

render(template_path, namespace)

Implements Kajiki 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.

Parameters
  • custom_renderers – custom-defined renderers to manufacture

  • extra_vars – extra vars for the template namespace

add_renderers(custom_dict)

Adds a custom renderer.

Parameters

custom_dict – a dictionary of custom renderers to add

available(name)

Returns true if queried renderer class is available.

Parameters

name – renderer name

get(name, template_path)

Returns the renderer object.

Parameters
  • name – name of the requested renderer

  • template_path – path to the template

pecan.templating.format_genshi_error(exc_value)

Implements Genshi renderer error formatting.

pecan.templating.format_jinja_error(exc_value)

Implements Jinja renderer error formatting.

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

Formats the the line context for error rendering.

Parameters
  • 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.

pecan.templating.format_mako_error(exc_value)

Implements Mako renderer error formatting.