added jinja quick loa

This commit is contained in:
Michael Herman 2014-06-13 10:52:30 -05:00
parent 0fb024c199
commit 3c25e474d3
3 changed files with 26 additions and 1 deletions

View File

@ -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 ...."

24
16_jinja_quick_load.py Normal file
View File

@ -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)

View File

@ -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