feat: add preset bool filter
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user