Test get_value macro

This commit is contained in:
Feodor Fitsner 2025-02-26 16:56:31 -08:00
parent a04cf70655
commit 94ef48fafc
2 changed files with 21 additions and 6 deletions

View File

@ -3,4 +3,6 @@
{% endfor %}
{% import "_macros.jinja2" as macros %}
GREETING = "{{ macros.greeting('World') }}"
{% set min_sdk_version = macros.get_value(cookiecutter.pyproject, "tool.flet.android.min_sdk_version") %}
min_sdk_version: {{ min_sdk_version }}

View File

@ -1,8 +1,21 @@
{# _macros.jinja2 #}
{% macro upper_case(value) %}
{{ value.upper() }}
{% endmacro %}
{% macro greeting(name) %}
Hello, {{ name }}!
{% macro get_value(dict, path) %}
{# Split the path into keys #}
{% set keys = path.split('.') %}
{# Initialize the result with the input dictionary #}
{% set result = dict %}
{# Iterate through the keys and traverse the dictionary #}
{% for key in keys %}
{% if result is mapping and key in result %}
{% set result = result[key] %}
{% else %}
{% set result = none %}
{% break %}
{% endif %}
{% endfor %}
{{ result }}
{% endmacro %}