Created
December 19, 2017 21:09
-
-
Save j18e/6d50882d60b92572b721d69d20bcc7fa to your computer and use it in GitHub Desktop.
Jinja Templating Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Usage: render_jinja.py <template_file> <parameters_file> | |
Parameters file must be yaml encoded. Use Jinja2 to reference in template. | |
Options: -h | |
""" | |
from docopt import docopt | |
from jinja2 import Environment, FileSystemLoader | |
import yaml | |
if __name__ == '__main__': | |
args = docopt(__doc__) | |
def render_template(template_file, parameters_file): | |
with open(parameters_file) as yaml_file: | |
parameters = yaml.load(yaml_file) | |
env = Environment(loader=FileSystemLoader('.')) | |
template = env.get_template(template_file) | |
return template.render(parameters) | |
print(render_template(args['<template_file>'], args['<parameters_file>'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment