Fixup jinja2 loader configuration

This commit is contained in:
James Page 2016-11-10 09:58:20 +00:00
parent eba40a46dc
commit 85328c6aa1
2 changed files with 11 additions and 8 deletions

4
.gitignore vendored
View File

@ -55,4 +55,6 @@ ChangeLog
.*sw? .*sw?
# Files created by releasenotes build # Files created by releasenotes build
releasenotes/build releasenotes/build
.settings

View File

@ -26,17 +26,18 @@ class SnapFileRenderer():
'''Helper class for rendering snap templates for runtime use''' '''Helper class for rendering snap templates for runtime use'''
def __init__(self): def __init__(self):
self._loaders = [ self._tmpl_env = Environment(
FileSystemLoader(os.path.join(os.environ.get('SNAP'), loader=FileSystemLoader(os.path.join(os.environ.get('SNAP'),
'templates')) 'templates')),
] trim_blocks=True
self._tmpl_env = Environment(loader=self._loaders) )
def render(self, template_name, env): def render(self, template_name, env):
'''Render j2 template using SNAP environment context '''Render j2 template using SNAP environment context provided
@param template_name: name of the template to use for rendering @param template_name: name of the template to use for rendering
@return: string of rendered context, ready to write back to a file @param env: dict of variables to pass to the renderer
@return: string of rendered data, ready to write back to a file
''' '''
try: try:
template = self._tmpl_env.get_template(template_name) template = self._tmpl_env.get_template(template_name)