Skip to content

Jinja2

Jinja2Conf

Bases: BaseModel

JINJA2 config model.

Parameters:

Name Type Description Default
template_directory str

Template directory.

required
template str

JINJA template.

required
Source code in stac_generator/plugins/mappings/jinja2.py
21
22
23
24
25
26
27
28
29
class Jinja2Conf(BaseModel):
    """JINJA2 config model."""

    template_directory: str = Field(
        description="Template directory.",
    )
    template: str = Field(
        description="JINJA template.",
    )

Jinja2Mapping

Bases: BaseMapping

Render extracted metadata into Jinja template.

Plugin name: jinja2_mapping

Example Configuration

.. code-block:: yaml

- name: jinja2_mapping
  conf:
    template_directory: /path/to/template/directory
    template: template_name
Source code in stac_generator/plugins/mappings/jinja2.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Jinja2Mapping(BaseMapping):
    """Render extracted metadata into Jinja template.

    **Plugin name:** ``jinja2_mapping``

    Example Configuration:
        .. code-block:: yaml

            - name: jinja2_mapping
              conf:
                template_directory: /path/to/template/directory
                template: template_name

    """

    config_class = Jinja2Conf

    def run(
        self,
        body: dict,
        recipe: Recipe,
        **kwargs,
    ) -> dict:
        environment = Environment(loader=FileSystemLoader(self.conf.template_directory))
        template = environment.get_template(self.conf.template)

        return template.render(**body)