Fix get_value - 1

This commit is contained in:
Feodor Fitsner 2025-02-26 17:11:41 -08:00
parent eb347a3b71
commit 938ebcc6f2
2 changed files with 9 additions and 17 deletions

View File

@ -4,5 +4,5 @@
{% import "_macros.jinja2" as macros %} {% import "_macros.jinja2" as macros %}
{% set min_sdk_version = macros.get_value(cookiecutter.pyproject.tool, "flet.android.min_sdk_version") %} {% set min_sdk_version = macros.get_value(cookiecutter.pyproject, "tool.flet.android.min_sdk_version") %}
min_sdk_version: {{ min_sdk_version }} min_sdk_version: {{ min_sdk_version }}

View File

@ -3,22 +3,14 @@
{% macro get_value(dict, path) %} {% macro get_value(dict, path) %}
{# Split the path into keys #} {# Split the path into keys #}
{% set keys = path.split('.') %} {% set keys = path.split('.') %}
{% if keys and dict is mapping and keys[0] in dict %}
{# Initialize the result with the input dictionary #} {% set next_value = dict[keys[0]] %}
{% set result = dict %} {% if keys | length == 1 %}
{{ next_value }}
{# Use a flag to detect when to stop processing #}
{% set valid = true %}
{# Iterate through the keys and traverse the dictionary #}
{% for key in keys %}
{% if valid and result is mapping and key in result %}
{% set result = result[key] %}
{% else %} {% else %}
{% set result = none %} {{ get_value(next_value, keys[1:] | join('.')) }}
{% set valid = false %} {% endif %}
{% else %}
{{ none }}
{% endif %} {% endif %}
{% endfor %}
{{ result }}
{% endmacro %} {% endmacro %}