picongpu.pypicongpu.rendering.renderer
This file is part of PIConGPU. Copyright 2021-2024 PIConGPU contributors Authors: Hannes Troepgen, Brian Edward Marre License: GPLv3+
Classes
helper class to render Mustache templates |
Module Contents
- class picongpu.pypicongpu.rendering.renderer.Renderer
helper class to render Mustache templates
Collection of (static) functions to render Mustache templates.
Also contains checks for structure of passed context (JSON) objects and the JSON schema checks and related functions (loading schema database, checking schemas, looking up schemas by type etc.)
- static check_rendering_context(context: Any) None
check if a context object may be renderd
If checks succeed passes silently, else raises.
Must be used before the preprocessor (as it checks that keys reserved for the preprocessor are not yet used).
Performs if the given object is acceptable as rendering context: - is dict - leafs are string, boolean, None, int, or float (or empty list) - child nodes are leaf, set or list - list items must be dict - keys are strings - keys do not contain dot (.) - keys do not begin with underscore (_) -> reserved for preprocessor
- Parameters:
context – object to be checked
- Raises:
Exception – on check failure
- static get_context_preprocessed(context: dict) dict
preprocess a context object
Applies the following preproccessing to an object: - list items have property “_first” and “_last” (boolean) added - numbers are translated to C++-compatible strings
rejects unchecked rendering contexts
- Parameters:
context – context to be preprocessed
- Returns:
preprocessed copy of context dict
- static get_rendered_template(context: dict, template: str) str
get rendered version of the provided string
Renders a given string using the given context object.
- Parameters:
context – (checked and preprocessed) rendering context
template – string containing template to be rendered
- Returns:
rendered template
- static render_directory(context: dict, path: str) None
Render all templates inside a given directory and remove the templates
Recursively find all files inside given path and render the files ending in “.mustache” to the same name without the ending. The original “.mustache” files are renamed with a dot “.” prefix.
- Parameters:
context – (checked and preprocessed) rendering context
path – directory containing “.mustache” files