JinjaRender¶
A builder that renders a string to a file.
- class disseminate.builders.jinja_render.JinjaRender(env, context, render_ext=None, **kwargs)¶
A builder that renders a file using Jinja2.
Note
The JinjaRender should not render the template until the build step to make sure the document and context are properly loaded first.
- Parameters
- env: :obj:`.builders.Environment`
The build environment
- parameters, argsTuple[
paths.SourcePath
, str, tuple, list] The input parameters (dependencies), including filepaths, for the build
- outfilepathOptional[
paths.TargetPath
] If specified, the path for the output file.
- contextdict
A context to use with the renderer.
- render_extstr
The extension for the rendered file. Either this or the outfilepath must be specified. ex: ‘.tex’
- build(complete=False)¶
Run the build.
- Parameters
- completeOptional[bool]
If True, run the build until it has completed If False, start the build in the background.
- Returns
- statusstr
The current status of the build.
Note
This function will run the sub-builders.
Each builder is atomic
When running a build, not all of the builders might be called in the first build–for example, subsequent builders may rely on the results of previous builds. For this reason, builders should be used in conjunction with an environment to make sure a set of builds are completed or the build complete=True should be used.
- jinja_environment()¶
The jinja environment.
- property outfilepath¶
The output filename and path
- property parameters¶
The list of input parameters, including filepaths, needed for the build
- static runtime_error(future, error_msg=None, raise_error=True)¶
Raise an error from a future working with subprocess
- static runtime_success(future)¶
Test whether a future from a subprocess is successful.
- template()¶
Retrieve the template from the context
- disseminate.builders.jinja_render.context_filepaths(template_filepaths)¶
Return a list of context modifier files (ex: context.txt) from template filepaths.
- Parameters
- template_filepathsList[
pathlib.Path
] A list of filepaths for templates.
- template_filepathsList[
- Returns
- filepathsList[
pathlib.Path
] A list of paths.
- filepathsList[
- disseminate.builders.jinja_render.rewrite_path(context, stub)¶
A Jinja2 filter for rewriting paths, like css paths.
Note
This function will only modify the path if an existing file can be found in the target directory. If not, it will log an error and return the path unchanged. This means that the dependent .css (and other) files should have been copied to the target directory before rendering the template.
Note
This function is not sped up from using a ThreadPoolExecutor, and implementing with a ProcessPoolExecutor gives problems with pickling objects.
- disseminate.builders.jinja_render.template_filepaths(template, environment)¶
Return a list of filepaths from a Jinja2 template object.
- Parameters
- template
jinja2.Template
The jinja2 template object to load filepaths for
- environment
jinja2.Environment
The jinja2 environment object
- template
- Returns
- filepathsList[
pathlib.Path
] A list of paths.
- filepathsList[