Created
May 14, 2015 04:08
-
-
Save half-duplex/09d7e005ddbc225852fc to your computer and use it in GitHub Desktop.
jinja2 erb style __main__
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| """ | |
| jinja2.__main__ | |
| ~~~~~~~~~~~~~~~ | |
| Allows for simple rendering in the style of eRuby, accepting variables from | |
| the environment. | |
| :copyright: (c) 2015 by the Jinja Team. | |
| :license: BSD, see LICENSE for more details. | |
| """ | |
| import os | |
| import sys | |
| from jinja2.environment import Environment | |
| from jinja2.loaders import FileSystemLoader | |
| if len(sys.argv) < 2: | |
| raise Exception("Run like: my_variable=Arnold python -m jinja2 my_template.jinja") | |
| template_file = sys.argv[1] | |
| loader = FileSystemLoader(searchpath=os.getcwd()) | |
| template_env = Environment(loader=loader) | |
| template = template_env.get_template(template_file) | |
| output = template.render(os.environ) | |
| print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment