Reference¶
mako2cli.cli¶
Command-line interface.
mako2cli.DataLoader¶
Dataloaader module.
-
class
mako2cli.DataLoader.DataLoader(data_file)¶ Data loading interface.
Load data from a file source. Only YAML is actually supported.
-
data_file¶ file containing data.
- Type
Path
-
classmethod
from_string(data_file)¶ Factory method for initialize from string path.
- Parameters
data_file (str) – path to data file as string.
- Return type
- Returns
a DataLoader class instance.
-
get_data()¶ Return the data parsed as dictionary.
- Return type
Dict- Returns
data parsed as dictionary.
- Raises
yaml.YAMLError – if file is not valid YAML.
-
mako2cli.Renderer¶
Renderer module.
-
class
mako2cli.Renderer.Renderer(template_file, data_file, output_file)¶ Execute a template rendering gived data file.
This class manage the template rendering from a data file.
-
template_file¶ file with template logic to render.
- Type
Path
-
data_file¶ data to use for rendering
- Type
Path
-
output_file¶ file containing the rendering output.
- Type
Path
Example:
>>> from pathlib import Path >>> import tempfile >>> from mako2cli import Renderer >>> temporary_dir = tempfile.mkdtemp() >>> template_file = Path(temporary_dir) / "template.mako" >>> template_file.write_text("hello ${name}!") >>> data_file = Path(temporary_dir) / "data.yaml" >>> data_file.write_text("name: world") >>> output_file = Path(temporary_dir) / "output" >>> r = Renderer(template_file, data_file, output_file) >>> r.execute() >>> bool(output_file.read_text() == "hello world!") True
-
execute()¶ Execute the rendering process, generate the output file.
- Return type
None
-
classmethod
from_string(template_file, data_file, output_file)¶ Factory method used for string filenames.
- Parameters
template_file (str) – file with template logic to render.
data_file (str) – data to use for rendering.
output_file (str) – file containing the rendering output.
- Return type
- Returns
Renderer class instance
-
mako2cli.TemplateEngine¶
Template Engine module.
-
class
mako2cli.TemplateEngine.TemplateEngine(template)¶ Manage the template logic rendering.
-
template¶ Mako template object
-
classmethod
initialize(template_filename)¶ Factory method for class creation.
- Parameters
template_filename (str) – file with template logic to render.
- Return type
- Returns
TemplateEngine intialized object
- Raises
TemplateEngineException – if file contains invalid syntax.
-
render(output_file_name, data)¶ Render the template.
Execute the template rendering given a data set.
- Parameters
output_file_name (str) – output file rendering.
data (Dict) – data to use for rendering.
- Raises
TemplateEngineException – if file contains invalid syntax.
- Return type
None
-
-
exception
mako2cli.TemplateEngine.TemplateEngineException¶ Generic module exception.