Test my_custom_function
This commit is contained in:
parent
6221e5b036
commit
7a20a3a195
|
|
@ -28,6 +28,5 @@
|
||||||
"pwa_theme_color": "#0175C2",
|
"pwa_theme_color": "#0175C2",
|
||||||
"split_per_abi": false,
|
"split_per_abi": false,
|
||||||
"options": null,
|
"options": null,
|
||||||
"pyproject": null,
|
"pyproject": null
|
||||||
"get_pyproject": null
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
import cookiecutter.utils
|
||||||
|
|
||||||
|
|
||||||
|
def get_pyproject(pyproject_toml: Any, setting: Optional[str] = None):
|
||||||
|
if not setting:
|
||||||
|
return pyproject_toml
|
||||||
|
|
||||||
|
d = pyproject_toml
|
||||||
|
for k in setting.split("."):
|
||||||
|
d = d.get(k)
|
||||||
|
if d is None:
|
||||||
|
return None
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def my_custom_function(value):
|
||||||
|
"""Example function: returns the value in uppercase"""
|
||||||
|
return value.upper()
|
||||||
|
|
||||||
|
|
||||||
|
def another_function(value1, value2):
|
||||||
|
"""Concatenates two values with a space"""
|
||||||
|
return f"{value1} {value2}"
|
||||||
|
|
||||||
|
|
||||||
|
# Inject custom functions into Jinja's global context
|
||||||
|
def add_custom_filters(cookiecutter):
|
||||||
|
cookiecutter.globals["my_custom_function"] = my_custom_function
|
||||||
|
cookiecutter.globals["another_function"] = another_function
|
||||||
|
|
||||||
|
|
||||||
|
# Run after project is generated
|
||||||
|
add_custom_filters(cookiecutter)
|
||||||
|
|
@ -26,7 +26,7 @@ loading_screen: {{ loading_screen }}
|
||||||
|
|
||||||
loading_screen_text: {{ loading_screen_text }}
|
loading_screen_text: {{ loading_screen_text }}
|
||||||
|
|
||||||
test: {{ cookiecutter.get_pyproject("tool.flet.loading_screen_text") }}
|
Uppercase Example: {{ my_custom_function("abc") }}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{% for dep in cookiecutter.flutter.dependencies %}
|
{% for dep in cookiecutter.flutter.dependencies %}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue