annotate globalneighbors/template.py @ 19:811adc9736eb

add configuration for gunicorn
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 15:43:45 -0700
parents 316e1d54ffd4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 """
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 functionality for `jinja` templates
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 import os
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 from jinja2 import Template
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 # default template location
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 here = os.path.dirname(os.path.abspath(__file__))
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 template_dir = os.path.join(here, 'templates')
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 class TemplateLoader(object):
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 def __init__(self, template_dir=template_dir):
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 assert os.path.exists(template_dir)
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 self.template_dir = template_dir
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 def load(self, template):
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 path = os.path.join(self.template_dir, template)
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 assert os.path.exists(path)
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 with open(path) as f:
316e1d54ffd4 move to jinja templates
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 return Template(f.read())