Skip to content

Commit 260fe93

Browse files
committed
feat: use python-box for context with both key and attribute access
Now the context object is converted to Box (python-box), allowing access to its values both as attributes (F.key) and by key (F['key'])
1 parent 3ea6512 commit 260fe93

3 files changed

Lines changed: 55 additions & 29 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ packages = [{ include = "textcompose" }]
1212
dependencies = [
1313
"jinja2>=3.1.6",
1414
"magic-filter>=1.0.12",
15+
"python-box>=7.3.2",
1516
]
1617

1718
keywords = [

textcompose/core/component.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from abc import ABC, abstractmethod
22
from typing import Any, Mapping, Callable
33

4+
from box import Box
45
from magic_filter import MagicFilter
56

67
# Direct import to prevent circular import issues
@@ -13,6 +14,7 @@ def __init__(self, when: Condition | None = None) -> None:
1314

1415
@staticmethod
1516
def resolve(value, context: Mapping[str, Any], **kwargs) -> str | None:
17+
context = Box(context)
1618
if isinstance(value, MagicFilter):
1719
return value.resolve(context)
1820
elif hasattr(value, "render") and callable(getattr(value, "render")):

0 commit comments

Comments
 (0)