Package: scrippy-template
scrippy_templateSimplified management of template files for theScrippyframework.PrerequisitesPython modulesList of required modulesThe modules listed below will be automatically installed.jinja2InstallationManualgitclonehttps://codeberg.org/scrippy/scrippy-template.gitcdscrippy-template
python-mpipinstall-rrequirements.txt
makeinstallWithpippipinstallscrippy-templateUsageThis module allows document generation from template files using thejinja2rendering engine.To be usable, template files must be located in the directory defined by thebase_pathparameter passed to thetemplate.Rendererobject.To handle variable interpolation, the template fileMUSTaccept a dictionary namedparamsas a parameter.This dictionary must contain all the variables necessary for the complete rendering of the template file.The rendering of the template file is obtained from thetemplate.Rendererobject, whose instantiation requires the name of a template file and the base path in which to search for the template file.Environment-specific parameters forJinja2can be modified through theenvattribute of thetemplate.Rendererobject.By convention, the template files used by theScrippyframework are stored in the directory defined by theenv::templatedirdirconfiguration parameter (see the configuration of theScrippyframework in the relevantdocumentation).A template is a simple text file with certain duly marked passages interpolated by the variables passed as parameters.TheRenderer.render()method returns the rendering of the template file.The variables must be supplied to the template file as a dictionary namedparams.The dictionary will be passed to the template file which will be responsible for interpolating the variables it contains.Template files can include:control structuresloopsSimple template fileWith the following template file namedtemplate_test.modlocated in the directory/var/scrippy/templates:Hello {{params.user}}

You received this email because you are a member of the functional administrators of {{params.app}}.

The {{params.script}} script execution on {{params.date}} ended with the following error code:
- {{params.error.code}}: {{params.error.msg}}

--
Regards.
{{params.sender}}The template file can be used as follows:importdatetimefromscrippy_templateimporttemplateparams={"user":"Harry Fink","app":"Flying Circus","script":"dead_parrot.py","date":datetime.datetime.now().strftime("%Y/%m/%d"),"error":{"code":42,"msg":"It’s not pinin’! It’s passed on! This parrot is no more!"},"sender":"Luiggi Vercotti",}base_path='/var/lib/scrippy/templates'template_file='template.j2'renderer=template.Renderer(base_path,template_file)print(renderer.render(params))With the default values, the message displayed at the end of the script will contain:Hello Harry Fink

You received this email because you are a member of the functional administrators of Flying Circus.

The  dead_parrot.py script execution on 2019/09/15 ended with the following error code:
- 42: It’s not pinin’! It’s passed on! This parrot is no more!

--
Regards.
Luigi VercottiTemplate file with control structuresparams={"user":"Harry Fink","app":"Flying Circus","script":"dead_parrot.py","date":datetime.datetime.now().strftime("%Y/%m/%d"),"num_error":42,"sender":"Luiggi Vercotti",}Hello {{params.user}}

You received this email because you are a member of the functional administrators of {{params.app}}.

The {{params.script}} script execution on {{params.date}} ended
{% if params.num_errors == 0 %}
- without error
{% else %}
 with {{params.num_errors}} error(s)
{% endif %}

--
Regards.
{{params.sender}}Template file with loopparams={"user":"Harry Fink","app":"Flying Circus","script":"dead_parrot.py","date":datetime.datetime.now().strftime("%Y/%m/%d"),'errors':[{'code':2,'msg':"It's not pinin’! It's passed on! This parrot is no more!"},{'code':3,'msg':"Ohh! The cat's eaten it."}],"sender":"Luiggi Vercotti",}Hello {{params.user}}

You received this email because you are a member of the functional administrators of {{params.app}}.

The {{params.script}} script execution on {{params.date}} ended with the following errors:
{% for error in params.errors %}
- {{ error.code }}: {{ error.msg}}
{% endfor %}

--
Regards.
{{params.sender}}