class documentation

Extensions can be used to add extra functionality to the Jinja template system at the parser level. Custom extensions are bound to an environment but may not store environment specific data on `self`. The reason for this is that an extension can be bound to another environment (for overlays) by creating a copy and reassigning the `environment` attribute. As extensions are created by the environment they cannot accept any arguments for configuration. One may want to work around that by using a factory function, but that is not possible as extensions are identified by their import name. The correct way to configure the extension is storing the configuration values on the environment. Because this way the environment ends up acting as central configuration storage the attributes may clash which is why extensions have to ensure that the names they choose for configuration are not too generic. ``prefix`` for example is a terrible name, ``fragment_cache_prefix`` on the other hand is a good name as includes the name of the extension (fragment cache).

Method __init__ Undocumented
Method __init_subclass__ Undocumented
Method attr Return an attribute node for the current extension. This is useful to pass constants on extensions to generated template code.
Method bind Create a copy of this extension bound to another environment.
Method call_method Call a method of the extension. This is a shortcut for :meth:`attr` + :class:`jinja2.nodes.Call`.
Method filter_stream It's passed a :class:`~jinja2.lexer.TokenStream` that can be used to filter tokens returned. This method has to return an iterable of :class:`~jinja2.lexer.Token`\s, but it doesn't have to return a :class:`~jinja2...
Method parse If any of the :attr:`tags` matched this method is called with the parser as first argument. The token the parser stream is pointing at is the name token that matched. This method has to return one or a list of multiple nodes.
Method preprocess This method is called before the actual lexing and can be used to preprocess the source. The `filename` is optional. The return value must be the preprocessed source.
Class Variable identifier Undocumented
Class Variable priority Undocumented
Class Variable tags Undocumented
Instance Variable environment Undocumented
def __init__(self, environment): (source)

Undocumented

Parameters
environment:EnvironmentUndocumented
def __init_subclass__(cls): (source)

Undocumented

def attr(self, name, lineno=None): (source)

Return an attribute node for the current extension. This is useful to pass constants on extensions to generated template code. :: self.attr('_my_attribute', lineno=lineno)

Parameters
name:strUndocumented
lineno:t.Optional[int]Undocumented
Returns
nodes.ExtensionAttributeUndocumented
def bind(self, environment): (source)

Create a copy of this extension bound to another environment.

Parameters
environment:EnvironmentUndocumented
Returns
ExtensionUndocumented
def call_method(self, name, args=None, kwargs=None, dyn_args=None, dyn_kwargs=None, lineno=None): (source)

Call a method of the extension. This is a shortcut for :meth:`attr` + :class:`jinja2.nodes.Call`.

Parameters
name:strUndocumented
args:t.Optional[t.List[nodes.Expr]]Undocumented
kwargs:t.Optional[t.List[nodes.Keyword]]Undocumented
dyn_args:t.Optional[nodes.Expr]Undocumented
dyn_kwargs:t.Optional[nodes.Expr]Undocumented
lineno:t.Optional[int]Undocumented
Returns
nodes.CallUndocumented
def filter_stream(self, stream): (source)

It's passed a :class:`~jinja2.lexer.TokenStream` that can be used to filter tokens returned. This method has to return an iterable of :class:`~jinja2.lexer.Token`\s, but it doesn't have to return a :class:`~jinja2.lexer.TokenStream`.

Parameters
stream:TokenStreamUndocumented
Returns
t.Union[TokenStream, t.Iterable[Token]]Undocumented
def parse(self, parser): (source)

If any of the :attr:`tags` matched this method is called with the parser as first argument. The token the parser stream is pointing at is the name token that matched. This method has to return one or a list of multiple nodes.

Parameters
parser:ParserUndocumented
Returns
t.Union[nodes.Node, t.List[nodes.Node]]Undocumented
def preprocess(self, source, name, filename=None): (source)

This method is called before the actual lexing and can be used to preprocess the source. The `filename` is optional. The return value must be the preprocessed source.

Parameters
source:strUndocumented
name:t.Optional[str]Undocumented
filename:t.Optional[str]Undocumented
Returns
strUndocumented
identifier: t.ClassVar[str] = (source)

Undocumented

priority: int = (source)

Undocumented

environment = (source)

Undocumented