Test context aware function
This commit is contained in:
parent
5acc93870e
commit
1a365316ba
|
|
@ -1,3 +1,4 @@
|
||||||
|
from jinja2 import pass_context
|
||||||
from jinja2.ext import Extension
|
from jinja2.ext import Extension
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5,4 +6,9 @@ class FoobarExtension(Extension):
|
||||||
def __init__(self, environment):
|
def __init__(self, environment):
|
||||||
super(FoobarExtension, self).__init__(environment)
|
super(FoobarExtension, self).__init__(environment)
|
||||||
environment.filters["foobar"] = lambda v: v * 2
|
environment.filters["foobar"] = lambda v: v * 2
|
||||||
environment.globals["greet"] = lambda name: f"Hello, {name}"
|
environment.globals["get_pyproject"] = self.get_pyproject
|
||||||
|
|
||||||
|
@pass_context
|
||||||
|
def get_pyproject(self, context, setting):
|
||||||
|
pyproject = context.get("pyproject", {})
|
||||||
|
return f"Hello, {setting}! (pyproject: {pyproject})"
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ splash_screen_text: {{ splash_screen_text }}
|
||||||
|
|
||||||
Uppercase Example: {{ 2 | foobar }}
|
Uppercase Example: {{ 2 | foobar }}
|
||||||
|
|
||||||
Greeter: {{ greet("John") }}
|
get_pyproject: {{ get_pyproject("tool.flet") }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{% for dep in cookiecutter.flutter.dependencies %}
|
{% for dep in cookiecutter.flutter.dependencies %}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue