Coverage for /Users/davegaeddert/Development/dropseed/plain/plain/plain/templates/core.py: 69%

1 import jinja2

2

3 from .jinja import environment

4

5

6 class TemplateFileMissing(Exception):

7 def __str__(self) -> str:

8 if self.args:

9 return f"Template file {self.args[0]} not found"

10 else:

11 return "Template file not found"

12

13

14 class Template:

15 def __init__(self, filename: str) -> None:

16 self.filename = filename

17

18 try:

19 self._jinja_template = environment.get_template(filename)

20 except jinja2.TemplateNotFound:

21 raise TemplateFileMissing(filename)

22

23 def render(self, context: dict) -> str:

24 return self._jinja_template.render(context)