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:
@@ -222,8 +222,8 @@ def _docs_evaluator_sx() -> str:
|
||||
)
|
||||
|
||||
|
||||
async def _docs_primitives_sx() -> str:
|
||||
prims = await _primitives_section_sx()
|
||||
def _docs_primitives_sx() -> str:
|
||||
prims = _primitives_section_sx()
|
||||
return (
|
||||
f'(~doc-page :title "Primitives"'
|
||||
f' (~doc-section :title "Built-in functions" :id "builtins"'
|
||||
@@ -402,11 +402,11 @@ def _reference_attr_detail_sx(slug: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
async def _reference_attrs_sx() -> str:
|
||||
def _reference_attrs_sx() -> str:
|
||||
from content.pages import REQUEST_ATTRS, BEHAVIOR_ATTRS, SX_UNIQUE_ATTRS
|
||||
req = await _attr_table_sx("Request Attributes", REQUEST_ATTRS)
|
||||
beh = await _attr_table_sx("Behavior Attributes", BEHAVIOR_ATTRS)
|
||||
uniq = await _attr_table_sx("Unique to sx", SX_UNIQUE_ATTRS)
|
||||
req = _attr_table_sx("Request Attributes", REQUEST_ATTRS)
|
||||
beh = _attr_table_sx("Behavior Attributes", BEHAVIOR_ATTRS)
|
||||
uniq = _attr_table_sx("Unique to sx", SX_UNIQUE_ATTRS)
|
||||
return (
|
||||
f'(~doc-page :title "Attribute Reference"'
|
||||
f' (p :class "text-stone-600 mb-6"'
|
||||
@@ -419,10 +419,10 @@ async def _reference_attrs_sx() -> str:
|
||||
)
|
||||
|
||||
|
||||
async def _reference_headers_sx() -> str:
|
||||
def _reference_headers_sx() -> str:
|
||||
from content.pages import REQUEST_HEADERS, RESPONSE_HEADERS
|
||||
req_table = await _headers_table_sx("Request Headers", REQUEST_HEADERS)
|
||||
resp_table = await _headers_table_sx("Response Headers", RESPONSE_HEADERS)
|
||||
req_table = _headers_table_sx("Request Headers", REQUEST_HEADERS)
|
||||
resp_table = _headers_table_sx("Response Headers", RESPONSE_HEADERS)
|
||||
return (
|
||||
f'(~doc-page :title "Headers"'
|
||||
f' (p :class "text-stone-600 mb-6"'
|
||||
@@ -433,29 +433,29 @@ async def _reference_headers_sx() -> str:
|
||||
)
|
||||
|
||||
|
||||
async def _reference_events_sx() -> str:
|
||||
from shared.sx.helpers import render_to_sx
|
||||
def _reference_events_sx() -> str:
|
||||
from shared.sx.helpers import sx_call
|
||||
from shared.sx.parser import SxExpr
|
||||
from content.pages import EVENTS
|
||||
rows = []
|
||||
for name, desc in EVENTS:
|
||||
rows.append(await render_to_sx("doc-two-col-row", name=name, description=desc))
|
||||
rows.append(sx_call("doc-two-col-row", name=name, description=desc))
|
||||
rows_sx = "(<> " + " ".join(rows) + ")"
|
||||
table = await render_to_sx("doc-two-col-table",
|
||||
table = sx_call("doc-two-col-table",
|
||||
intro="sx fires custom DOM events at various points in the request lifecycle.",
|
||||
col1="Event", col2="Description", rows=SxExpr(rows_sx))
|
||||
return f'(~doc-page :title "Events" {table})'
|
||||
|
||||
|
||||
async def _reference_js_api_sx() -> str:
|
||||
from shared.sx.helpers import render_to_sx
|
||||
def _reference_js_api_sx() -> str:
|
||||
from shared.sx.helpers import sx_call
|
||||
from shared.sx.parser import SxExpr
|
||||
from content.pages import JS_API
|
||||
rows = []
|
||||
for name, desc in JS_API:
|
||||
rows.append(await render_to_sx("doc-two-col-row", name=name, description=desc))
|
||||
rows.append(sx_call("doc-two-col-row", name=name, description=desc))
|
||||
rows_sx = "(<> " + " ".join(rows) + ")"
|
||||
table = await render_to_sx("doc-two-col-table",
|
||||
table = sx_call("doc-two-col-table",
|
||||
intro="The client-side sx.js library exposes a public API for programmatic use.",
|
||||
col1="Method", col2="Description", rows=SxExpr(rows_sx))
|
||||
return f'(~doc-page :title "JavaScript API" {table})'
|
||||
|
||||
@@ -18,8 +18,8 @@ async def _sx_full_headers(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
main_nav = await _main_nav_sx(kw.get("section"))
|
||||
sx_row = await _sx_header_sx(main_nav)
|
||||
main_nav = _main_nav_sx(kw.get("section"))
|
||||
sx_row = _sx_header_sx(main_nav)
|
||||
return await render_to_sx_with_env("sx-layout-full", {},
|
||||
sx_row=SxExpr(sx_row))
|
||||
|
||||
@@ -29,8 +29,8 @@ async def _sx_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import render_to_sx_with_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
main_nav = await _main_nav_sx(kw.get("section"))
|
||||
sx_row = await _sx_header_sx(main_nav)
|
||||
main_nav = _main_nav_sx(kw.get("section"))
|
||||
sx_row = _sx_header_sx(main_nav)
|
||||
rows = await render_to_sx_with_env("sx-layout-full", {},
|
||||
sx_row=SxExpr(sx_row))
|
||||
return await oob_header_sx("root-header-child", "sx-header-child", rows)
|
||||
@@ -47,9 +47,9 @@ async def _sx_section_full_headers(ctx: dict, **kw: Any) -> str:
|
||||
sub_nav = kw.get("sub_nav", "")
|
||||
selected = kw.get("selected", "")
|
||||
|
||||
main_nav = await _main_nav_sx(section)
|
||||
sub_row = await _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
||||
sx_row = await _sx_header_sx(main_nav, child=sub_row)
|
||||
main_nav = _main_nav_sx(section)
|
||||
sub_row = _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
||||
sx_row = _sx_header_sx(main_nav, child=sub_row)
|
||||
return await render_to_sx_with_env("sx-section-layout-full", {},
|
||||
sx_row=SxExpr(sx_row))
|
||||
|
||||
@@ -65,9 +65,9 @@ async def _sx_section_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
sub_nav = kw.get("sub_nav", "")
|
||||
selected = kw.get("selected", "")
|
||||
|
||||
main_nav = await _main_nav_sx(section)
|
||||
sub_row = await _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
||||
sx_row = await _sx_header_sx(main_nav, child=sub_row)
|
||||
main_nav = _main_nav_sx(section)
|
||||
sub_row = _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
||||
sx_row = _sx_header_sx(main_nav, child=sub_row)
|
||||
rows = await render_to_sx_with_env("sx-section-layout-full", {},
|
||||
sx_row=SxExpr(sx_row))
|
||||
return await oob_header_sx("root-header-child", "sx-header-child", rows)
|
||||
@@ -76,12 +76,12 @@ async def _sx_section_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
async def _sx_mobile(ctx: dict, **kw: Any) -> str:
|
||||
"""Mobile menu for sx home page: main nav + root."""
|
||||
from shared.sx.helpers import (
|
||||
mobile_menu_sx, mobile_root_nav_sx, render_to_sx, SxExpr,
|
||||
mobile_menu_sx, mobile_root_nav_sx, sx_call, SxExpr,
|
||||
)
|
||||
|
||||
main_nav = await _main_nav_sx(kw.get("section"))
|
||||
main_nav = _main_nav_sx(kw.get("section"))
|
||||
return mobile_menu_sx(
|
||||
await render_to_sx("mobile-menu-section",
|
||||
sx_call("mobile-menu-section",
|
||||
label="sx", href="/", level=1, colour="violet",
|
||||
items=SxExpr(main_nav)),
|
||||
await mobile_root_nav_sx(ctx),
|
||||
@@ -91,21 +91,21 @@ async def _sx_mobile(ctx: dict, **kw: Any) -> str:
|
||||
async def _sx_section_mobile(ctx: dict, **kw: Any) -> str:
|
||||
"""Mobile menu for sx section pages: sub nav + main nav + root."""
|
||||
from shared.sx.helpers import (
|
||||
mobile_menu_sx, mobile_root_nav_sx, render_to_sx, SxExpr,
|
||||
mobile_menu_sx, mobile_root_nav_sx, sx_call, SxExpr,
|
||||
)
|
||||
|
||||
section = kw.get("section", "")
|
||||
sub_label = kw.get("sub_label", section)
|
||||
sub_href = kw.get("sub_href", "/")
|
||||
sub_nav = kw.get("sub_nav", "")
|
||||
main_nav = await _main_nav_sx(section)
|
||||
main_nav = _main_nav_sx(section)
|
||||
|
||||
parts = []
|
||||
if sub_nav:
|
||||
parts.append(await render_to_sx("mobile-menu-section",
|
||||
parts.append(sx_call("mobile-menu-section",
|
||||
label=sub_label, href=sub_href, level=2, colour="violet",
|
||||
items=SxExpr(sub_nav)))
|
||||
parts.append(await render_to_sx("mobile-menu-section",
|
||||
parts.append(sx_call("mobile-menu-section",
|
||||
label="sx", href="/", level=1, colour="violet",
|
||||
items=SxExpr(main_nav)))
|
||||
parts.append(await mobile_root_nav_sx(ctx))
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from shared.sx.helpers import (
|
||||
render_to_sx, SxExpr,
|
||||
sx_call, SxExpr,
|
||||
)
|
||||
|
||||
|
||||
async def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None) -> str:
|
||||
def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None) -> str:
|
||||
"""Build nav link items as sx."""
|
||||
parts = []
|
||||
for label, href in items:
|
||||
parts.append(await render_to_sx("nav-link",
|
||||
parts.append(sx_call("nav-link",
|
||||
href=href, label=label,
|
||||
is_selected="true" if current == label else None,
|
||||
select_colours="aria-selected:bg-violet-200 aria-selected:text-violet-900",
|
||||
@@ -18,54 +18,54 @@ async def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
|
||||
async def _doc_nav_sx(items: list[tuple[str, str]], current: str) -> str:
|
||||
def _doc_nav_sx(items: list[tuple[str, str]], current: str) -> str:
|
||||
"""Build the in-page doc navigation pills."""
|
||||
items_sx = " ".join(
|
||||
f'(list "{label}" "{href}")'
|
||||
for label, href in items
|
||||
)
|
||||
return await render_to_sx("doc-nav", items=SxExpr(f"(list {items_sx})"), current=current)
|
||||
return sx_call("doc-nav", items=SxExpr(f"(list {items_sx})"), current=current)
|
||||
|
||||
|
||||
async def _attr_table_sx(title: str, attrs: list[tuple[str, str, bool]]) -> str:
|
||||
def _attr_table_sx(title: str, attrs: list[tuple[str, str, bool]]) -> str:
|
||||
"""Build an attribute reference table."""
|
||||
from content.pages import ATTR_DETAILS
|
||||
rows = []
|
||||
for attr, desc, exists in attrs:
|
||||
href = f"/reference/attributes/{attr}" if exists and attr in ATTR_DETAILS else None
|
||||
rows.append(await render_to_sx("doc-attr-row", attr=attr, description=desc,
|
||||
rows.append(sx_call("doc-attr-row", attr=attr, description=desc,
|
||||
exists="true" if exists else None,
|
||||
href=href))
|
||||
rows_sx = "(<> " + " ".join(rows) + ")"
|
||||
return await render_to_sx("doc-attr-table", title=title, rows=SxExpr(rows_sx))
|
||||
return sx_call("doc-attr-table", title=title, rows=SxExpr(rows_sx))
|
||||
|
||||
|
||||
async def _headers_table_sx(title: str, headers: list[tuple[str, str, str]]) -> str:
|
||||
def _headers_table_sx(title: str, headers: list[tuple[str, str, str]]) -> str:
|
||||
"""Build a headers reference table."""
|
||||
rows = []
|
||||
for name, value, desc in headers:
|
||||
rows.append(await render_to_sx("doc-headers-row",
|
||||
rows.append(sx_call("doc-headers-row",
|
||||
name=name, value=value, description=desc))
|
||||
rows_sx = "(<> " + " ".join(rows) + ")"
|
||||
return await render_to_sx("doc-headers-table", title=title, rows=SxExpr(rows_sx))
|
||||
return sx_call("doc-headers-table", title=title, rows=SxExpr(rows_sx))
|
||||
|
||||
|
||||
async def _primitives_section_sx() -> str:
|
||||
def _primitives_section_sx() -> str:
|
||||
"""Build the primitives section."""
|
||||
from content.pages import PRIMITIVES
|
||||
parts = []
|
||||
for category, prims in PRIMITIVES.items():
|
||||
prims_sx = " ".join(f'"{p}"' for p in prims)
|
||||
parts.append(await render_to_sx("doc-primitives-table",
|
||||
parts.append(sx_call("doc-primitives-table",
|
||||
category=category,
|
||||
primitives=SxExpr(f"(list {prims_sx})")))
|
||||
return " ".join(parts)
|
||||
|
||||
|
||||
async def _sx_header_sx(nav: str | None = None, *, child: str | None = None) -> str:
|
||||
def _sx_header_sx(nav: str | None = None, *, child: str | None = None) -> str:
|
||||
"""Build the sx docs menu-row."""
|
||||
label_sx = await render_to_sx("sx-docs-label")
|
||||
return await render_to_sx("menu-row-sx",
|
||||
label_sx = sx_call("sx-docs-label")
|
||||
return sx_call("menu-row-sx",
|
||||
id="sx-row", level=1, colour="violet",
|
||||
link_href="/", link_label="sx",
|
||||
link_label_content=SxExpr(label_sx),
|
||||
@@ -75,40 +75,40 @@ async def _sx_header_sx(nav: str | None = None, *, child: str | None = None) ->
|
||||
)
|
||||
|
||||
|
||||
async def _docs_nav_sx(current: str | None = None) -> str:
|
||||
def _docs_nav_sx(current: str | None = None) -> str:
|
||||
from content.pages import DOCS_NAV
|
||||
return await _nav_items_sx(DOCS_NAV, current)
|
||||
return _nav_items_sx(DOCS_NAV, current)
|
||||
|
||||
|
||||
async def _reference_nav_sx(current: str | None = None) -> str:
|
||||
def _reference_nav_sx(current: str | None = None) -> str:
|
||||
from content.pages import REFERENCE_NAV
|
||||
return await _nav_items_sx(REFERENCE_NAV, current)
|
||||
return _nav_items_sx(REFERENCE_NAV, current)
|
||||
|
||||
|
||||
async def _protocols_nav_sx(current: str | None = None) -> str:
|
||||
def _protocols_nav_sx(current: str | None = None) -> str:
|
||||
from content.pages import PROTOCOLS_NAV
|
||||
return await _nav_items_sx(PROTOCOLS_NAV, current)
|
||||
return _nav_items_sx(PROTOCOLS_NAV, current)
|
||||
|
||||
|
||||
async def _examples_nav_sx(current: str | None = None) -> str:
|
||||
def _examples_nav_sx(current: str | None = None) -> str:
|
||||
from content.pages import EXAMPLES_NAV
|
||||
return await _nav_items_sx(EXAMPLES_NAV, current)
|
||||
return _nav_items_sx(EXAMPLES_NAV, current)
|
||||
|
||||
|
||||
async def _essays_nav_sx(current: str | None = None) -> str:
|
||||
def _essays_nav_sx(current: str | None = None) -> str:
|
||||
from content.pages import ESSAYS_NAV
|
||||
return await _nav_items_sx(ESSAYS_NAV, current)
|
||||
return _nav_items_sx(ESSAYS_NAV, current)
|
||||
|
||||
|
||||
async def _main_nav_sx(current_section: str | None = None) -> str:
|
||||
def _main_nav_sx(current_section: str | None = None) -> str:
|
||||
from content.pages import MAIN_NAV
|
||||
return await _nav_items_sx(MAIN_NAV, current_section)
|
||||
return _nav_items_sx(MAIN_NAV, current_section)
|
||||
|
||||
|
||||
async def _sub_row_sx(sub_label: str, sub_href: str, sub_nav: str,
|
||||
def _sub_row_sx(sub_label: str, sub_href: str, sub_nav: str,
|
||||
selected: str = "") -> str:
|
||||
"""Build the level-2 sub-section menu-row."""
|
||||
return await render_to_sx("menu-row-sx",
|
||||
return sx_call("menu-row-sx",
|
||||
id="sx-sub-row", level=2, colour="violet",
|
||||
link_href=sub_href, link_label=sub_label,
|
||||
selected=selected or None,
|
||||
|
||||
Reference in New Issue
Block a user