Replace env free-variable threading with IO-primitive auto-fetch macros

Layout components now self-resolve context (cart-mini, auth-menu, nav-tree,
rights, URLs) via new IO primitives (root-header-ctx, select-colours,
account-nav-ctx, app-rights) and defmacro wrappers (~root-header-auto,
~auth-header-row-auto, ~root-mobile-auto). This eliminates _ctx_to_env(),
HELPER_CSS_CLASSES, and verbose :key threading across all 10 services.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 18:20:57 +00:00
parent 8be00df6d9
commit 7fda7a8027
41 changed files with 551 additions and 523 deletions

View File

@@ -146,30 +146,27 @@ def register_sx_layout(name: str, full_defcomp: str, oob_defcomp: str,
mobile_defcomp: str | None = None) -> None:
"""Register a layout that delegates entirely to .sx defcomps.
The defcomps read ctx values as free variables from the evaluation
environment (populated by ``_ctx_to_env``). Python layouts become
one-liners::
Layout defcomps use IO primitives (via auto-fetching macros) to
self-populate — no Python env injection needed. Any extra kwargs
from the caller are passed as kebab-case env entries::
register_sx_layout("account", "account-layout-full",
"account-layout-oob", "account-layout-mobile")
"""
from .helpers import render_to_sx_with_env, _ctx_to_env
from .helpers import render_to_sx_with_env
async def full_fn(ctx: dict, **kw: Any) -> str:
env = _ctx_to_env(ctx)
env.update({k.replace("_", "-"): v for k, v in kw.items()})
env = {k.replace("_", "-"): v for k, v in kw.items()}
return await render_to_sx_with_env(full_defcomp, env)
async def oob_fn(ctx: dict, **kw: Any) -> str:
env = _ctx_to_env(ctx, oob=True)
env.update({k.replace("_", "-"): v for k, v in kw.items()})
env = {k.replace("_", "-"): v for k, v in kw.items()}
return await render_to_sx_with_env(oob_defcomp, env)
mobile_fn = None
if mobile_defcomp:
async def mobile_fn(ctx: dict, **kw: Any) -> str:
env = _ctx_to_env(ctx)
env.update({k.replace("_", "-"): v for k, v in kw.items()})
env = {k.replace("_", "-"): v for k, v in kw.items()}
return await render_to_sx_with_env(mobile_defcomp, env)
register_layout(Layout(name, full_fn, oob_fn, mobile_fn))