fixml.modules.template
Classes
A dumber FileSystemLoader which does not accept path and thus allows |
|
Static wrapper class for setting states for Jinja2's Environment. |
Module Contents
- class fixml.modules.template.ExternalFileLoader
Bases:
jinja2.BaseLoaderA dumber FileSystemLoader which does not accept path and thus allows arbitrary file locations as valid template path.
- get_source(environment: jinja2.Environment, path: str | pathlib.Path)
Get the template source, filename and reload helper for a template. It’s passed the environment and template name and has to return a tuple in the form
(source, filename, uptodate)or raise a TemplateNotFound error if it can’t locate the template.The source part of the returned tuple must be the source of the template as a string. The filename should be the name of the file on the filesystem if it was loaded from there, otherwise
None. The filename is used by Python for the tracebacks if no loader extension is used.The last item in the tuple is the uptodate function. If auto reloading is enabled it’s always called to check if the template changed. No arguments are passed so the function must store the old state somewhere (for example in a closure). If it returns False the template will be reloaded.
- class fixml.modules.template.TemplateLoader
Static wrapper class for setting states for Jinja2’s Environment.
- template_exts = ['jinja', 'j2']
- env
- ext_env
- template_aliases
- classmethod load(template_name: str) jinja2.Template
- classmethod load_from_external(ext_template_path: str | pathlib.Path, validate_template: str | None = None) jinja2.Template
Load template from external file.
Return the source as a Jinja2 Template when given a path.
- Parameters:
ext_template_path (str or pathlib.Path) – Path to the external template file.
validate_template (str, optional) – If provided, the external template source will be compared with the referred internal template to confirm all variables are present.
- Returns:
Source file loaded as a Jinja2 Template.
- Return type:
jinja2.Template
- classmethod _get_vars_from_source(source: str) set[str]
- classmethod list() list[str]
- classmethod list_vars_in_template(template_name: str) set[str]
List all variables present in template.