jip.templates

The JIP templates module wraps around the jinja2 template engine used and allows to render job templates and other strings.

The module stores a global context that is used during script evaluation and implements the JIP filter functions. The template environment is stored as a global reverence and the template engine is exposed thought the render_template() function.

class jip.templates.JipUndefined(hint=None, obj=missing, name=None, exc=<class 'jinja2.exceptions.UndefinedError'>)

Custom undefined implementation that does not modify unknown variables

exception jip.templates.RenderError(template, message, line=None)

Exception raised in case a tempalte could not be rendered properly

jip.templates.environment = None

the jinja2 environment

jip.templates.ext_filter(ctx, value, splitter='.', all=False)

Cut away the last file extension splitted by splitter. The default splitter is .

Parameters:
  • ctx – the context
  • value – the file path
  • splitter – the splitter
  • all – if set to True the left-mose occurence of the split character is used
jip.templates.parent_filter(ctx, value)

Returns the name of the parent directory of the given file path

Parameters:
  • ctx – the context
  • value – the file path
Returns:

the name of the parent directory

jip.templates.render_template(template, **kwargs)

Render a template using the given keyword arguments as context

Parameters:
  • template (string) – the template string
  • kwargs – the context
jip.templates.replace_filter(ctx, value, search, replace)

Replaces all hits of the pattern woth the replacement string

Parameters:
  • ctx – the context
  • value – the source value
  • search – the search pattern
  • replace – the replacement string
Returns:

the new string

Fork me on GitHub