Example #1
0
def create_environment() -> Environment:
    """Create the Jinja environment containing the functionality to render
    templates."""
    env = Environment()

    # define the filterfunc decorator and patch it into the environment
    # so we can define filters using a decorator
    def filterfunc(target, func):
        target.filters[func.__name__] = func
        return func

    env.filterfunc = types.MethodType(filterfunc, env)

    return env