Template¶
The template plugin is actually two plugins. The first treats the content of the file itself as the template, whereas
the second inserts the content into a layout template. This plugin uses jinja2 to do all templating. The dependencies necessary for this plugin can be
installed using the template
extra.
-
class
pysmith.contrib.web.template.
_BaseTemplate
(*, match_pattern='*', globals=None, global_include=None, environment_args={})[source]¶ This class is not intended to be instantiated directly, but instead just serves to hold common logic for both template plugins.
- Parameters
match_pattern (str) – The pattern of files to process.
globals (dict(str, object)) – Global values to insert into the underlying
Environment
.global_include (str) – The name of a template (to be retrieved using
get_template()
) containing macros that will be included in the globals list of theEnvironment
. The macros will be available in all templates, but will not have access to the rendering context.environment_args (dict(str, object)) – A dictionary of options to pass to the
Environment
constructor.
-
class
pysmith.contrib.web.template.
ContentTemplate
(*, **kwargs)[source]¶ Treats the contents of the files as a template and renders it. This can be used to do pre-processing on the source files. All parameters specified in
_BaseTemplate
are valid for this class as well. When the template is rendered, the build infometadata
will be available assite
.
-
class
pysmith.contrib.web.template.
LayoutTemplate
(*, layout_selector='layout', output_extension='.html', **kwargs)[source]¶ Treats the contents of the files as a variable to pass into a template. The layout to use is selected by the
layout_selector
parameter. When the template is rendered, the filecontents
will be available in the rendering context ascontents
, the filemetadata
will be available aspage
, and the build infometadata
will be available assite
. In addition to the parameters specified below, all parameters specified in_BaseTemplate
are valid for this class as well.- Parameters
layout_selector (str or func(
FileInfo
)) – The layout selector. If this is a string, it will be used as the key to look up the template in the file metadata. If this is a function, it will be executed to find the name of the template to use.output_extension (str) – The extension to use for the output file. The file info will be moved to a new key in the files dictionary if the file needs to be renamed to have the correct extension.