Mercurial > hg > GlobalNeighbors
diff globalneighbors/template.py @ 6:316e1d54ffd4
move to jinja templates
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 15:47:59 -0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/globalneighbors/template.py Sat Jun 24 15:47:59 2017 -0700 @@ -0,0 +1,23 @@ +""" +functionality for `jinja` templates +""" + +import os +from jinja2 import Template + +# default template location +here = os.path.dirname(os.path.abspath(__file__)) +template_dir = os.path.join(here, 'templates') + + +class TemplateLoader(object): + + def __init__(self, template_dir=template_dir): + assert os.path.exists(template_dir) + self.template_dir = template_dir + + def load(self, template): + path = os.path.join(self.template_dir, template) + assert os.path.exists(path) + with open(path) as f: + return Template(f.read())