Test context aware function

This commit is contained in:
Feodor Fitsner 2025-03-04 11:05:08 -08:00
parent 5acc93870e
commit 1a365316ba
2 changed files with 8 additions and 2 deletions

View File

@ -1,3 +1,4 @@
from jinja2 import pass_context
from jinja2.ext import Extension
@ -5,4 +6,9 @@ class FoobarExtension(Extension):
def __init__(self, environment):
super(FoobarExtension, self).__init__(environment)
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})"

View File

@ -28,7 +28,7 @@ splash_screen_text: {{ splash_screen_text }}
Uppercase Example: {{ 2 | foobar }}
Greeter: {{ greet("John") }}
get_pyproject: {{ get_pyproject("tool.flet") }}
*/
{% for dep in cookiecutter.flutter.dependencies %}