LinuxCommandLibrary

mako-render

Render Mako templates

SYNOPSIS

mako-render [options] template_file

PARAMETERS

template_file
    Path to the Mako template file to be rendered.

--data data
    JSON or Python literal data to pass to the template context. For example: --data '{"key":"value"}'

--data-file file
    Path to a JSON or Python literal data file to load into the template context.

--module-directory path
    Add a directory to the Python module search path.

--enable-looping
    Enables support for loops in the template rendering.

--output-file file
    Path to a file where the rendered output will be written. If not specified, output is written to stdout.

--preprocessor callable
    Importable Python callable that will act as a preprocessor for the template.

--postprocessor callable
    Importable Python callable that will act as a postprocessor for the template.

--error-handler callable
    Importable Python callable that will handle errors during rendering.

--imports imports
    Python imports to pass to the template context. For example: --imports 'import os, sys'

--input-encoding encoding
    Encoding of the template file.

--output-encoding encoding
    Encoding of the output file.

--default-filters filters
    Default filters to apply to all expressions in the template.

--disable-unicode
    Disable Unicode support.

--uri
    Treat template file as a URI.

--filesystem-checks
    Enable checking of files modified on the file system during compilation.

--buffer-filters
    Whether filters run first against the entire output buffer, rather than per-expression.

--strict-undefined
    Raise an exception if an undefined variable is accessed.

--cache-dir path
    Sets the caching directory path.

--module-id string
    Sets the caching module ID.

--template-args args
    Template arguments to pass as dictionary.

--template-lookup callable
    Sets the template lookup from importable callable.

-h, --help
    Show help message and exit.

DESCRIPTION

The mako-render command is a command-line tool that uses the Mako templating engine to render templates. It allows you to process Mako templates with data provided through various means, such as command-line arguments, environment variables, or external data files. This is useful for automating the generation of configuration files, scripts, or other text-based outputs based on dynamic data. The command takes a Mako template as input and produces a rendered output based on the data supplied. Mako's capabilities include variable substitution, control structures (like if/else and loops), and the ability to import and reuse other templates. mako-render simplifies using the Mako engine in scripting and automation scenarios. It provides a flexible way to generate dynamic content from templates within the Linux environment.

CAVEATS

Error handling and debugging can be challenging, especially with complex templates. Ensure proper error handling and logging within your templates and when using the command to diagnose issues effectively.

ERROR HANDLING

When rendering, errors within the Mako template can cause the command to fail. Use --error-handler to customize error handling with a python method.

DATA INPUT

The --data and --data-file options provide flexibility in passing data to the template. Choose the method best suited for your data source and format. Ensure the data format (JSON or Python literal) matches the expected structure in the template.

PYTHON INTEGRATION

As Mako is Python-based, the --imports, --preprocessor and --postprocessor options allows integration with Python code.
Importing modules can extend the available functionality during the rendering process.

HISTORY

The mako-render command is part of the Mako templating engine, a Python library developed for generating dynamic content. Mako gained popularity as a more expressive and flexible alternative to other template engines, offering both Python code integration and XML-style syntax. The mako-render command provides a way to leverage Mako templates from the command line, making it useful for scripting and automation workflows.

SEE ALSO

python(1)

Copied to clipboard