comparison 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
comparison
equal deleted inserted replaced
5:7e27e874655b 6:316e1d54ffd4
1 """
2 functionality for `jinja` templates
3 """
4
5 import os
6 from jinja2 import Template
7
8 # default template location
9 here = os.path.dirname(os.path.abspath(__file__))
10 template_dir = os.path.join(here, 'templates')
11
12
13 class TemplateLoader(object):
14
15 def __init__(self, template_dir=template_dir):
16 assert os.path.exists(template_dir)
17 self.template_dir = template_dir
18
19 def load(self, template):
20 path = os.path.join(self.template_dir, template)
21 assert os.path.exists(path)
22 with open(path) as f:
23 return Template(f.read())