Skip to content

Commit

Permalink
Jinja2 Globals
Browse files Browse the repository at this point in the history
  • Loading branch information
rescrv committed Jan 19, 2013
1 parent 8e1931a commit 0043b1a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions firmant/jinja2.py
Expand Up @@ -40,6 +40,9 @@
import firmant.urls


_context = {}


class Jinja2TemplateParser(object):

def __init__(self, fix, regex):
Expand Down Expand Up @@ -84,7 +87,8 @@ def write_all(self):
self.write(key, obj)

def write(self, key, obj):
context = self._context.copy()
context = _context.copy()
context.update(self._context)
template = self._env.get_template(obj)
data = template.render(context)
firmant.output.write(key, data)
Expand All @@ -109,8 +113,13 @@ def write_all(self):
self.write(key, obj)

def write(self, key, obj):
context = self._context.copy()
context = _context.copy()
context.update(self._context)
context[self._objname] = obj
template = self._env.get_template(self._template)
data = template.render(context)
firmant.output.write(key, data)


def addglobal(name, obj):
_context[name] = obj

0 comments on commit 0043b1a

Please sign in to comment.