Skip to content

zhongdai/tiny-render

Repository files navigation

Tiny Render

Unit Testing Deployment PyPI version

Version: 0.2.0

This is a very simple wrapper for Jinja2 by providing few built-in variables.

Additional variables for the Template,

  • {{ _gitsha }} - will be the shortsha for git hash, the value will be None if git is not installed or the current directory is not a git repo.
  • {{ 'HOME' | getenv }} - the environment variable HOME will be renderred. It will raise exception if HOME is not set
  • {{ _date_str }} - the current date in yyyymmdd format
  • {{ _time_str }} - the current date/time in yyyymmddHHMMSS format

Installation

pip install tiny-render

Sample Code

from tiny_render import Render

with open(os.path.join("/tmp","test.txt"), 'w') as f:
    f.write("gitsha: {{_gitsha}}, hello {{key}}")

params = {"key": "world"}

r = Render("/tmp")

r.go("test.txt", **params)

# the output is "gitsha: xxxxxxx, hello world"

About

A simple wrapper for Jinja2 to render source code

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors