Coverage for src/kwai/core/template/jinja2_template.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that implements the Template interface for a jinja2 template.""" 

2 

3import jinja2 

4 

5from .template import Template 

6 

7 

8class Jinja2Template(Template): 

9 """A jinja2 template.""" 

10 

11 def __init__(self, template: jinja2.Template, **kwargs): 

12 """Construct a new template. 

13 

14 kwargs will be merged with the variables used in render. 

15 """ 

16 self._template = template 

17 self._variables = kwargs 

18 

19 def render(self, **kwargs) -> str: 

20 """Render the template.""" 

21 return self._template.render(kwargs | self._variables)