Add register_sx_layout infrastructure, convert account/federation/orders
Phase 0: Add _ctx_to_env() and render_to_sx_with_env() to shared/sx/helpers.py, register_sx_layout() to shared/sx/layouts.py, and ~root-header/~root-mobile wrapper defcomps to layout.sx. Convert built-in "root" layout to .sx. Phases 1-3: Convert account (65→19 lines), federation (105→97 lines), and orders (88→21 lines) to use register_sx_layout with .sx defcomps that read ctx values as free variables from the evaluation environment. No more Python building SX strings via SxExpr(await root_header_sx(ctx)). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
"""Orders defpage setup — registers layouts and loads .sx pages."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def setup_orders_pages() -> None:
|
||||
"""Register orders-specific layouts and load page definitions."""
|
||||
@@ -17,110 +15,7 @@ def _load_orders_page_files() -> None:
|
||||
load_page_dir(os.path.dirname(__file__), "orders")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Layouts
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _register_orders_layouts() -> None:
|
||||
from shared.sx.layouts import register_custom_layout
|
||||
register_custom_layout("orders", _orders_full, _orders_oob, _orders_mobile)
|
||||
register_custom_layout("order-detail", _order_detail_full, _order_detail_oob, _order_detail_mobile)
|
||||
|
||||
|
||||
async def _orders_full(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, header_child_sx, call_url, render_to_sx
|
||||
|
||||
list_url = kw.get("list_url", "/")
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
auth_hdr = await render_to_sx("auth-header-row",
|
||||
account_url=account_url,
|
||||
select_colours=ctx.get("select_colours", ""),
|
||||
account_nav=_as_sx_nav(ctx),
|
||||
)
|
||||
orders_hdr = await render_to_sx("orders-header-row", list_url=list_url)
|
||||
inner = "(<> " + auth_hdr + " " + orders_hdr + ")"
|
||||
return "(<> " + root_hdr + " " + await header_child_sx(inner) + ")"
|
||||
|
||||
|
||||
async def _orders_oob(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, render_to_sx
|
||||
from shared.sx.helpers import call_url
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
list_url = kw.get("list_url", "/")
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
auth_hdr = await render_to_sx("auth-header-row",
|
||||
account_url=account_url,
|
||||
select_colours=ctx.get("select_colours", ""),
|
||||
account_nav=_as_sx_nav(ctx),
|
||||
oob=True,
|
||||
)
|
||||
orders_hdr = await render_to_sx("orders-header-row", list_url=list_url)
|
||||
auth_child_oob = await render_to_sx("oob-header-sx",
|
||||
parent_id="auth-header-child",
|
||||
row=SxExpr(orders_hdr))
|
||||
root_hdr = await root_header_sx(ctx, oob=True)
|
||||
return "(<> " + auth_hdr + " " + auth_child_oob + " " + root_hdr + ")"
|
||||
|
||||
|
||||
async def _orders_mobile(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import mobile_menu_sx, mobile_root_nav_sx
|
||||
return mobile_menu_sx(await mobile_root_nav_sx(ctx))
|
||||
|
||||
|
||||
async def _order_detail_full(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, render_to_sx
|
||||
from shared.sx.helpers import call_url
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
list_url = kw.get("list_url", "/")
|
||||
detail_url = kw.get("detail_url", "/")
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
order_row = await render_to_sx(
|
||||
"menu-row-sx",
|
||||
id="order-row", level=3, colour="sky", link_href=detail_url,
|
||||
link_label="Order", icon="fa fa-gbp",
|
||||
)
|
||||
auth_hdr = await render_to_sx("auth-header-row",
|
||||
account_url=account_url,
|
||||
select_colours=ctx.get("select_colours", ""),
|
||||
account_nav=_as_sx_nav(ctx),
|
||||
)
|
||||
orders_hdr = await render_to_sx("orders-header-row", list_url=list_url)
|
||||
detail_header = await render_to_sx(
|
||||
"order-detail-header-stack",
|
||||
auth=SxExpr(auth_hdr),
|
||||
orders=SxExpr(orders_hdr),
|
||||
order=SxExpr(order_row),
|
||||
)
|
||||
return "(<> " + root_hdr + " " + detail_header + ")"
|
||||
|
||||
|
||||
async def _order_detail_oob(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
detail_url = kw.get("detail_url", "/")
|
||||
order_row_oob = await render_to_sx(
|
||||
"menu-row-sx",
|
||||
id="order-row", level=3, colour="sky", link_href=detail_url,
|
||||
link_label="Order", icon="fa fa-gbp", oob=True,
|
||||
)
|
||||
header_child_oob = await render_to_sx("oob-header-sx",
|
||||
parent_id="orders-header-child",
|
||||
row=SxExpr(order_row_oob))
|
||||
root_hdr = await root_header_sx(ctx, oob=True)
|
||||
return "(<> " + header_child_oob + " " + root_hdr + ")"
|
||||
|
||||
|
||||
async def _order_detail_mobile(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import mobile_menu_sx, mobile_root_nav_sx
|
||||
return mobile_menu_sx(await mobile_root_nav_sx(ctx))
|
||||
|
||||
|
||||
def _as_sx_nav(ctx: dict) -> Any:
|
||||
"""Convert account_nav fragment to SxExpr for use in component calls."""
|
||||
from shared.sx.helpers import _as_sx
|
||||
return _as_sx(ctx.get("account_nav"))
|
||||
from shared.sx.layouts import register_sx_layout
|
||||
register_sx_layout("orders", "orders-layout-full", "orders-layout-oob", "orders-layout-mobile")
|
||||
register_sx_layout("order-detail", "order-detail-layout-full", "order-detail-layout-oob", "order-detail-layout-mobile")
|
||||
|
||||
Reference in New Issue
Block a user