Skip to content

Instantly share code, notes, and snippets.

@michaelkuty
Last active July 19, 2016 13:54
Show Gist options
  • Save michaelkuty/8ff6cb368b08314117bedee5dbb27a95 to your computer and use it in GitHub Desktop.
Save michaelkuty/8ff6cb368b08314117bedee5dbb27a95 to your computer and use it in GitHub Desktop.
Simple Jinja renderer
import jinja2
from jinja2 import Environment
import yaml
jinja2.filters.FILTERS['yaml'] = lambda s: yaml.safe_dump(
s, default_flow_style=True)
jinja2.filters.FILTERS['parse_aliases'] = lambda s: yaml.safe_dump(
s.split(','), default_flow_style=True)
class JinjaRenderer(object):
'''Object for rendering'''
env = Environment()
def render(self, template=None, context={}):
''''Render Template meta from jinja2 templates.
'''
return self.env.from_string(template).render(context)
renderer = JinjaRenderer()
renderer.render('{{ myvar }}', context=context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment