LinuxCommandLibrary

mako-render

Render Mako templates

SYNOPSIS

mako-render [OPTIONS] TEMPLATE_FILE [DATA_FILE]

PARAMETERS

TEMPLATE_FILE
    The path to the Mako template file to be rendered.

DATA_FILE
    An optional path to a file containing data for the template. This file is typically in JSON or YAML format, and its contents are loaded as a dictionary accessible within the template context.

-D FILE, --data=FILE
    Specifies an explicit data file (e.g., JSON, YAML) to be loaded for the template context. This is an alternative way to provide the DATA_FILE argument.

-o FILE, --output=FILE
    Writes the rendered output to the specified FILE instead of standard output.

-t DIR, --template-dir=DIR
    Adds the specified DIR to the template lookup path. This allows the template to locate included or inherited templates from this directory.

-E ENCODING, --encoding=ENCODING
    Specifies the character ENCODING for the output. Common values include 'utf-8', 'latin-1', etc. Defaults to 'utf-8' if not specified.

--strict
    Enables strict mode, causing the command to exit with an error if a template variable is accessed but not found in the provided data context.

-h, --help
    Displays a help message and exits, showing available options and usage.

DESCRIPTION

The mako-render command is a utility for rendering Mako templates directly from the command line. Mako is a popular templating language for Python, known for its performance and rich feature set, including inheritance, includes, and filters.

This command allows users to specify a Mako template file and provide contextual data (often in JSON or YAML format) that the template will use during rendering. The rendered output, typically HTML, XML, or plain text, is then printed to standard output or an optionally specified file. It's commonly used for testing templates, generating configuration files, or creating dynamic content in shell scripts without requiring a full Python application.

CAVEATS

The mako-render command is not a standard, universally installed Linux utility. Its availability depends on whether it has been specifically installed (e.g., via pip install mako and then a custom script, or as part of a larger project like Ansible). The exact options and behavior may vary slightly depending on the specific implementation of the script. Users should consult the source or local documentation if the command behaves unexpectedly.

DATA FORMAT

The DATA_FILE or file provided via --data is typically expected to be in JSON or YAML format. The command parses this file and makes its contents available as variables within the Mako template. For example, if a JSON file contains {"name": "World"}, you can access ${name} in your Mako template.

TEMPLATE LOOKUP

When a template uses <%include> or <%inherit> directives, Mako needs to know where to find these referenced templates. The --template-dir option is crucial for specifying additional directories where Mako should look for these dependencies, beyond the directory of the main template file itself.

HISTORY

Mako was first released in 2007 by Michael Bayer as a Python templating library designed for high performance and a flexible syntax. It gained popularity in various Python web frameworks and standalone applications. The mako-render utility typically evolved as a simple command-line wrapper script bundled with Mako's examples or created by users for quick template testing and standalone rendering tasks, rather than being a core part of the Mako library itself. Its development is intertwined with the evolution of the Mako project, continuously adapting to Python versions and community needs for template rendering.

SEE ALSO

python(1), jinja2cli(1), sed(1), awk(1)

Copied to clipboard