Loads a template from a Python dict mapping template names to template source. This loader is useful for unittesting: >>> loader = DictLoader({'index.html': 'source here'}) Because auto reloading is rarely useful this is disabled by default.
| 434 | |
| 435 | |
| 436 | class DictLoader(BaseLoader): |
| 437 | """Loads a template from a Python dict mapping template names to |
| 438 | template source. This loader is useful for unittesting: |
| 439 | |
| 440 | >>> loader = DictLoader({'index.html': 'source here'}) |
| 441 | |
| 442 | Because auto reloading is rarely useful this is disabled by default. |
| 443 | """ |
| 444 | |
| 445 | def __init__(self, mapping: t.Mapping[str, str]) -> None: |
| 446 | self.mapping = mapping |
| 447 | |
| 448 | def get_source( |
| 449 | self, environment: "Environment", template: str |
| 450 | ) -> t.Tuple[str, None, t.Callable[[], bool]]: |
| 451 | if template in self.mapping: |
| 452 | source = self.mapping[template] |
| 453 | return source, None, lambda: source == self.mapping.get(template) |
| 454 | raise TemplateNotFound(template) |
| 455 | |
| 456 | def list_templates(self) -> t.List[str]: |
| 457 | return sorted(self.mapping) |
| 458 | |
| 459 | |
| 460 | class FunctionLoader(BaseLoader): |
no outgoing calls