import collections
import sys
import typing

import jinja2


class TemplateRenderer:
    def __init__(self, base_path: typing.Union[str, typing.List[str]]):
        loader = jinja2.FileSystemLoader(base_path or sys.path)
        environment = jinja2.Environment(loader=loader)
        self._environment = environment

    def render(self, template_file_path: str, template_variables: collections.Mapping) -> str:
        template = self._environment.get_template(template_file_path)

        return template.render(**template_variables)
