feat: add preset bool filter

This commit is contained in:
2026-08-10 13:36:12 +03:00
parent 9d15380443
commit a77a430d51
6 changed files with 34 additions and 11 deletions
+6 -1
View File
@@ -9,6 +9,10 @@ from jinja2 import Environment
from ..preset.model import Variables
def do_bool(data: str | None) -> bool:
return not (data is None or data.lower() in ["false", "null", "none", "0", ""])
def _build_env(basepath: Path) -> Environment:
env = Environment()
@@ -60,6 +64,7 @@ def _build_env(basepath: Path) -> Environment:
env.filters["get"] = do_get
env.filters["search"] = do_search
env.filters["key"] = do_key
env.filters["bool"] = do_bool
return env
@@ -78,6 +83,6 @@ class PathTemplate:
def check_conditions(self, templates: list[str], variables: Variables) -> bool:
for template in templates:
value = self.fill_template(template, variables)
if value.lower() in ["false", "null", "none", "0", ""]:
if not do_bool(value):
return False
return True