diff --git a/15_check_my_environment.py b/15_check_my_environment.py index 82be943..11017c4 100644 --- a/15_check_my_environment.py +++ b/15_check_my_environment.py @@ -42,4 +42,4 @@ if CONFIGFILE is None: print "Config file: {}".format(CONFIGFILE) if not os.path.exists(CONFIGFILE): sys.exit("Configuration error! Config file does not exist") -print "Congig ok ...." +print "Config ok ...." diff --git a/16_jinja_quick_load.py b/16_jinja_quick_load.py new file mode 100644 index 0000000..7af9b3d --- /dev/null +++ b/16_jinja_quick_load.py @@ -0,0 +1,24 @@ +""" +Render a quick Jinja2 template. +Thanks Danny - http://pydanny.com/jinja2-quick-load-function.html + +Example: + +>>> from jinja_quick_load import render_from_template +>>> data = { +... "date": "June 12, 2014", +... "items": ["oranges", "bananas", "steak", "milk"] +... } +>>> render_from_template(".", "shopping_list.html", **data) + +""" + + +from jinja2 import FileSystemLoader, Environment + + +def render_from_template(directory, template_name, **kwargs): + loader = FileSystemLoader(directory) + env = Environment(loader=loader) + template = env.get_template(template_name) + return template.render(**kwargs) diff --git a/readme.md b/readme.md index c5d4c20..1303ca7 100644 --- a/readme.md +++ b/readme.md @@ -15,3 +15,4 @@ 1. **13_random_name_generator.py**: random name generator 1. **14_html_to_markdown.sh**: Convert all html files in a single directory to markdown 1. **15_check_my_environment.py**: Pass in a config file based on your environment. +1. **16_jinja_quick_load.py**: Render a quick Jinja2 template