makejinja.plugin
1from collections import abc 2from pathlib import Path 3from typing import Any, Protocol 4 5from jinja2 import Environment 6from jinja2.ext import Extension 7 8from makejinja.config import Config 9 10__all__ = ["Plugin"] 11 12Extensions = abc.Sequence[type[Extension]] 13Filter = abc.Callable[[Any], Any] 14Filters = abc.Sequence[Filter] 15Function = abc.Callable[..., Any] 16Functions = abc.Sequence[Function] 17Test = abc.Callable[..., Any] 18Tests = abc.Sequence[Test] 19Policies = abc.Mapping[str, Any] 20MutableData = abc.MutableMapping[str, Any] 21Data = abc.Mapping[str, Any] 22PathFilter = abc.Callable[[Path], bool] 23PathFilters = abc.Sequence[PathFilter] 24 25 26class Plugin(Protocol): 27 """Extend the functionality of makejinja with a plugin implementing a subset of this protocol.""" 28 29 def __init__(self, *, env: Environment, data: Data, config: Config) -> None: 30 pass 31 32 def functions(self) -> Functions: 33 return [] 34 35 def data(self) -> Data: 36 return {} 37 38 def filters(self) -> Filters: 39 return [] 40 41 def tests(self) -> Tests: 42 return [] 43 44 def policies(self) -> Policies: 45 return {} 46 47 def extensions(self) -> Extensions: 48 return [] 49 50 def path_filters(self) -> PathFilters: 51 return [] 52 53 # Deprecated: Use functions() and data() instead 54 def globals(self) -> Functions: 55 return [] 56 57 58AbstractLoader = Plugin
class
Plugin(typing.Protocol):
27class Plugin(Protocol): 28 """Extend the functionality of makejinja with a plugin implementing a subset of this protocol.""" 29 30 def __init__(self, *, env: Environment, data: Data, config: Config) -> None: 31 pass 32 33 def functions(self) -> Functions: 34 return [] 35 36 def data(self) -> Data: 37 return {} 38 39 def filters(self) -> Filters: 40 return [] 41 42 def tests(self) -> Tests: 43 return [] 44 45 def policies(self) -> Policies: 46 return {} 47 48 def extensions(self) -> Extensions: 49 return [] 50 51 def path_filters(self) -> PathFilters: 52 return [] 53 54 # Deprecated: Use functions() and data() instead 55 def globals(self) -> Functions: 56 return []
Extend the functionality of makejinja with a plugin implementing a subset of this protocol.
Plugin( *, env: jinja2.environment.Environment, data: collections.abc.Mapping[str, typing.Any], config: makejinja.config.Config)