From 94ef48fafc8b7e120986881ec3a405f90e91725c Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 26 Feb 2025 16:56:31 -0800 Subject: [PATCH] Test get_value macro --- {{cookiecutter.out_dir}}/.vars | 4 +++- {{cookiecutter.out_dir}}/_macros.jinja2 | 23 ++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/{{cookiecutter.out_dir}}/.vars b/{{cookiecutter.out_dir}}/.vars index 1ffa5f7..ef60fab 100644 --- a/{{cookiecutter.out_dir}}/.vars +++ b/{{cookiecutter.out_dir}}/.vars @@ -3,4 +3,6 @@ {% endfor %} {% import "_macros.jinja2" as macros %} -GREETING = "{{ macros.greeting('World') }}" \ No newline at end of file + +{% set min_sdk_version = macros.get_value(cookiecutter.pyproject, "tool.flet.android.min_sdk_version") %} +min_sdk_version: {{ min_sdk_version }} \ No newline at end of file diff --git a/{{cookiecutter.out_dir}}/_macros.jinja2 b/{{cookiecutter.out_dir}}/_macros.jinja2 index f5a97ba..97a9a5d 100644 --- a/{{cookiecutter.out_dir}}/_macros.jinja2 +++ b/{{cookiecutter.out_dir}}/_macros.jinja2 @@ -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 %} \ No newline at end of file