23 lines
671 B
Python
23 lines
671 B
Python
""" Reads a jinja template from a file """
|
|
|
|
import os
|
|
import jinja2
|
|
|
|
|
|
class JinjaTemplate:
|
|
""" Reads and instanciates a template from a file """
|
|
|
|
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
|
|
env = jinja2.Environment(
|
|
loader=jinja2.FileSystemLoader(base_path),
|
|
autoescape=jinja2.select_autoescape(
|
|
enabled_extensions=("xml", "network"), default_for_string=True,
|
|
),
|
|
)
|
|
|
|
def __init__(self, path):
|
|
self.template = self.env.get_template(path)
|
|
|
|
def inst(self, *args, **kwargs):
|
|
""" instanciates the template """
|
|
return self.template.render(*args, **kwargs)
|