How to use the chevron.tokenizer.tokenize function in chevron

To help you get started, we’ve selected a few chevron examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apls777 / spotty / spotty / helpers / run.py View on Github external
def render_script(template: str, params: dict):
    """Renders a script template.

    It based on the Mustache templates, but only
    variables and delimiter changes are allowed.

    Raises an exception if one of the provided parameters doesn't
    exist in the template.
    """
    tokens = list(tokenize(template))
    template_keys = set()
    for tag, key in tokens:
        if tag not in ['literal', 'no escape', 'variable', 'set delimiter']:
            raise ValueError('Script templates support only variables and delimiter changes.')

        template_keys.add(key)

    # check that the script contains keys for all provided parameters
    for key in params:
        if key not in template_keys:
            raise ValueError('Parameter "%s" doesn\'t exist in the script.' % key)

    return chevron.render(tokens, params)

chevron

Mustache templating language renderer

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis

Similar packages