6
|
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())
|