Remove render_to_sx from public API: enforce sx_call for all service code
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m44s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m44s
Replace ~250 render_to_sx calls across all services with sync sx_call, converting many async functions to sync where no other awaits remained. Make render_to_sx/render_to_sx_with_env private (_render_to_sx). Add (post-header-ctx) IO primitive and shared post/post-admin defmacros. Convert built-in post/post-admin layouts from Python to register_sx_layout with .sx defcomps. Remove dead post_admin_mobile_nav_sx. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
Named layout presets for defpage.
|
||||
|
||||
Each layout generates header rows for full-page and OOB rendering.
|
||||
Layouts wrap existing helper functions from ``shared.sx.helpers`` so
|
||||
defpage can reference them by name (e.g. ``:layout :root``).
|
||||
Built-in layouts delegate to .sx defcomps via ``register_sx_layout``.
|
||||
Services register custom layouts via ``register_custom_layout``.
|
||||
|
||||
Layouts are registered in ``_LAYOUT_REGISTRY`` and looked up by
|
||||
``get_layout()`` at request time.
|
||||
@@ -13,12 +13,6 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Awaitable
|
||||
|
||||
from .helpers import (
|
||||
root_header_sx, post_header_sx, post_admin_header_sx,
|
||||
oob_header_sx,
|
||||
mobile_menu_sx, mobile_root_nav_sx,
|
||||
post_mobile_nav_sx, post_admin_mobile_nav_sx,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -83,57 +77,8 @@ def get_layout(name: str) -> Layout | None:
|
||||
return _LAYOUT_REGISTRY.get(name)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Built-in layouts
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _post_full(ctx: dict, **kw: Any) -> str:
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
post_hdr = await post_header_sx(ctx)
|
||||
return "(<> " + root_hdr + " " + post_hdr + ")"
|
||||
|
||||
|
||||
async def _post_oob(ctx: dict, **kw: Any) -> str:
|
||||
post_hdr = await post_header_sx(ctx, oob=True)
|
||||
# Also replace #post-header-child (empty — clears any nested admin rows)
|
||||
child_oob = await oob_header_sx("post-header-child", "", "")
|
||||
return "(<> " + post_hdr + " " + child_oob + ")"
|
||||
|
||||
|
||||
async def _post_admin_full(ctx: dict, **kw: Any) -> str:
|
||||
slug = ctx.get("post", {}).get("slug", "")
|
||||
selected = kw.get("selected", "")
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
admin_hdr = await post_admin_header_sx(ctx, slug, selected=selected)
|
||||
post_hdr = await post_header_sx(ctx, child=admin_hdr)
|
||||
return "(<> " + root_hdr + " " + post_hdr + ")"
|
||||
|
||||
|
||||
async def _post_admin_oob(ctx: dict, **kw: Any) -> str:
|
||||
slug = ctx.get("post", {}).get("slug", "")
|
||||
selected = kw.get("selected", "")
|
||||
post_hdr = await post_header_sx(ctx, oob=True)
|
||||
admin_hdr = await post_admin_header_sx(ctx, slug, selected=selected)
|
||||
admin_oob = await oob_header_sx("post-header-child", "post-admin-header-child", admin_hdr)
|
||||
return "(<> " + post_hdr + " " + admin_oob + ")"
|
||||
|
||||
|
||||
async def _post_mobile(ctx: dict, **kw: Any) -> str:
|
||||
return mobile_menu_sx(await post_mobile_nav_sx(ctx), await mobile_root_nav_sx(ctx))
|
||||
|
||||
|
||||
async def _post_admin_mobile(ctx: dict, **kw: Any) -> str:
|
||||
slug = ctx.get("post", {}).get("slug", "")
|
||||
selected = kw.get("selected", "")
|
||||
return mobile_menu_sx(
|
||||
await post_admin_mobile_nav_sx(ctx, slug, selected),
|
||||
await post_mobile_nav_sx(ctx),
|
||||
await mobile_root_nav_sx(ctx),
|
||||
)
|
||||
|
||||
|
||||
register_layout(Layout("post", _post_full, _post_oob, _post_mobile))
|
||||
register_layout(Layout("post-admin", _post_admin_full, _post_admin_oob, _post_admin_mobile))
|
||||
# Built-in post/post-admin layouts are registered below via register_sx_layout,
|
||||
# after that function is defined.
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -153,27 +98,29 @@ def register_sx_layout(name: str, full_defcomp: str, oob_defcomp: str,
|
||||
register_sx_layout("account", "account-layout-full",
|
||||
"account-layout-oob", "account-layout-mobile")
|
||||
"""
|
||||
from .helpers import render_to_sx_with_env
|
||||
from .helpers import _render_to_sx_with_env
|
||||
|
||||
async def full_fn(ctx: dict, **kw: Any) -> str:
|
||||
env = {k.replace("_", "-"): v for k, v in kw.items()}
|
||||
return await render_to_sx_with_env(full_defcomp, env)
|
||||
return await _render_to_sx_with_env(full_defcomp, env)
|
||||
|
||||
async def oob_fn(ctx: dict, **kw: Any) -> str:
|
||||
env = {k.replace("_", "-"): v for k, v in kw.items()}
|
||||
return await render_to_sx_with_env(oob_defcomp, env)
|
||||
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 = {k.replace("_", "-"): v for k, v in kw.items()}
|
||||
return await render_to_sx_with_env(mobile_defcomp, env)
|
||||
return await _render_to_sx_with_env(mobile_defcomp, env)
|
||||
|
||||
register_layout(Layout(name, full_fn, oob_fn, mobile_fn))
|
||||
|
||||
|
||||
# Register built-in "root" layout via .sx defcomps
|
||||
# Register built-in layouts via .sx defcomps
|
||||
register_sx_layout("root", "layout-root-full", "layout-root-oob", "layout-root-mobile")
|
||||
register_sx_layout("post", "layout-post-full", "layout-post-oob", "layout-post-mobile")
|
||||
register_sx_layout("post-admin", "layout-post-admin-full", "layout-post-admin-oob", "layout-post-admin-mobile")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user