Last active
July 19, 2016 13:54
-
-
Save michaelkuty/8ff6cb368b08314117bedee5dbb27a95 to your computer and use it in GitHub Desktop.
Simple Jinja renderer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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