Convert all 23 register_custom_layout calls to register_sx_layout across 6 services
Layout defcomps are now fully self-contained via IO-primitive auto-fetch macros, eliminating Python layout functions that manually threaded context values through SxExpr wrappers. Services converted: - Federation (1 layout): social - Blog (7 layouts): blog, blog-settings, blog-cache, blog-snippets, blog-menu-items, blog-tag-groups, blog-tag-group-edit - SX docs (2 layouts): sx, sx-section - Cart (2 layouts): cart-page, cart-admin + orders/order-detail - Events (9 layouts): calendar-admin, slots, slot, day-admin, entry, entry-admin, ticket-types, ticket-type, markets - Market (2 layouts): market, market-admin New IO primitives added to shared/sx/primitives_io.py: - federation-actor-ctx, cart-page-ctx, request-view-args - events-calendar-ctx, events-day-ctx, events-entry-ctx, events-slot-ctx, events-ticket-type-ctx - market-header-ctx (pre-builds desktop/mobile nav as SxExpr) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,92 @@
|
||||
;; SX docs layout defcomps — root header via ~root-header-auto,
|
||||
;; sx-specific headers passed as &key params.
|
||||
;; SX docs layout defcomps — fully self-contained via IO primitives.
|
||||
;; Registered via register_sx_layout in __init__.py.
|
||||
|
||||
;; --- SX home layout: root + sx menu row ---
|
||||
;; --- Main nav defcomp: static nav items from MAIN_NAV ---
|
||||
;; @css aria-selected:bg-violet-200 aria-selected:text-violet-900
|
||||
|
||||
(defcomp ~sx-layout-full (&key sx-row)
|
||||
(defcomp ~sx-main-nav (&key section)
|
||||
(let* ((sc "aria-selected:bg-violet-200 aria-selected:text-violet-900")
|
||||
(items (list
|
||||
(dict :label "Docs" :href "/docs/introduction")
|
||||
(dict :label "Reference" :href "/reference/")
|
||||
(dict :label "Protocols" :href "/protocols/wire-format")
|
||||
(dict :label "Examples" :href "/examples/click-to-load")
|
||||
(dict :label "Essays" :href "/essays/sx-sucks"))))
|
||||
(<> (map (lambda (item)
|
||||
(~nav-link
|
||||
:href (get item "href")
|
||||
:label (get item "label")
|
||||
:is-selected (when (= (get item "label") section) "true")
|
||||
:select-colours sc))
|
||||
items))))
|
||||
|
||||
;; --- SX header row ---
|
||||
|
||||
(defcomp ~sx-header-row (&key nav child oob)
|
||||
(~menu-row-sx :id "sx-row" :level 1 :colour "violet"
|
||||
:link-href "/" :link-label "sx"
|
||||
:link-label-content (~sx-docs-label)
|
||||
:nav nav
|
||||
:child-id "sx-header-child"
|
||||
:child child
|
||||
:oob oob))
|
||||
|
||||
;; --- Sub-row for section pages ---
|
||||
|
||||
(defcomp ~sx-sub-row (&key sub-label sub-href sub-nav selected oob)
|
||||
(~menu-row-sx :id "sx-sub-row" :level 2 :colour "violet"
|
||||
:link-href sub-href :link-label sub-label
|
||||
:selected selected
|
||||
:nav sub-nav
|
||||
:oob oob))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; SX home layout (root + sx header)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defcomp ~sx-layout-full (&key section)
|
||||
(<> (~root-header-auto)
|
||||
sx-row))
|
||||
(~sx-header-row :nav (~sx-main-nav :section section))))
|
||||
|
||||
(defcomp ~sx-layout-oob (&key root-header sx-row)
|
||||
(<> root-header sx-row))
|
||||
(defcomp ~sx-layout-oob (&key section)
|
||||
(<> (~sx-header-row
|
||||
:nav (~sx-main-nav :section section)
|
||||
:oob true)
|
||||
(~clear-oob-div :id "sx-header-child")
|
||||
(~root-header-auto true)))
|
||||
|
||||
;; --- SX section layout: root + sx row (with child sub-row) ---
|
||||
(defcomp ~sx-layout-mobile (&key section)
|
||||
(<> (~mobile-menu-section
|
||||
:label "sx" :href "/" :level 1 :colour "violet"
|
||||
:items (~sx-main-nav :section section))
|
||||
(~root-mobile-auto)))
|
||||
|
||||
(defcomp ~sx-section-layout-full (&key sx-row)
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; SX section layout (root + sx header + sub-row)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defcomp ~sx-section-layout-full (&key section sub-label sub-href sub-nav selected)
|
||||
(<> (~root-header-auto)
|
||||
sx-row))
|
||||
(~sx-header-row
|
||||
:nav (~sx-main-nav :section section)
|
||||
:child (~sx-sub-row :sub-label sub-label :sub-href sub-href
|
||||
:sub-nav sub-nav :selected selected))))
|
||||
|
||||
(defcomp ~sx-section-layout-oob (&key section sub-label sub-href sub-nav selected)
|
||||
(<> (~sx-sub-row :sub-label sub-label :sub-href sub-href
|
||||
:sub-nav sub-nav :selected selected :oob true)
|
||||
(~sx-header-row
|
||||
:nav (~sx-main-nav :section section)
|
||||
:oob true)
|
||||
(~root-header-auto true)))
|
||||
|
||||
(defcomp ~sx-section-layout-mobile (&key section sub-label sub-href sub-nav)
|
||||
(<>
|
||||
(when sub-nav
|
||||
(~mobile-menu-section
|
||||
:label (or sub-label section) :href sub-href :level 2 :colour "violet"
|
||||
:items sub-nav))
|
||||
(~mobile-menu-section
|
||||
:label "sx" :href "/" :level 1 :colour "violet"
|
||||
:items (~sx-main-nav :section section))
|
||||
(~root-mobile-auto)))
|
||||
|
||||
@@ -1,112 +1,11 @@
|
||||
"""Layout registration and header/mobile functions for sx docs."""
|
||||
"""SX docs layout registration — all layouts delegate to .sx defcomps."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .utils import _main_nav_sx, _sx_header_sx, _sub_row_sx
|
||||
|
||||
def _register_sx_layouts() -> None:
|
||||
"""Register the sx docs layout presets."""
|
||||
from shared.sx.layouts import register_custom_layout
|
||||
from shared.sx.layouts import register_sx_layout
|
||||
|
||||
register_custom_layout("sx", _sx_full_headers, _sx_oob_headers, _sx_mobile)
|
||||
register_custom_layout("sx-section", _sx_section_full_headers, _sx_section_oob_headers, _sx_section_mobile)
|
||||
|
||||
|
||||
async def _sx_full_headers(ctx: dict, **kw: Any) -> str:
|
||||
"""Full headers for sx home page: root + sx menu row."""
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
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))
|
||||
|
||||
|
||||
async def _sx_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
"""OOB headers for sx home page."""
|
||||
from shared.sx.helpers import render_to_sx_with_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
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)
|
||||
|
||||
|
||||
async def _sx_section_full_headers(ctx: dict, **kw: Any) -> str:
|
||||
"""Full headers for sx section pages: root + sx row + sub row."""
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
section = kw.get("section", "")
|
||||
sub_label = kw.get("sub_label", section)
|
||||
sub_href = kw.get("sub_href", "/")
|
||||
sub_nav = kw.get("sub_nav", "")
|
||||
selected = kw.get("selected", "")
|
||||
|
||||
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))
|
||||
|
||||
|
||||
async def _sx_section_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
"""OOB headers for sx section pages."""
|
||||
from shared.sx.helpers import render_to_sx_with_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
section = kw.get("section", "")
|
||||
sub_label = kw.get("sub_label", section)
|
||||
sub_href = kw.get("sub_href", "/")
|
||||
sub_nav = kw.get("sub_nav", "")
|
||||
selected = kw.get("selected", "")
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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, sx_call, SxExpr,
|
||||
)
|
||||
|
||||
main_nav = _main_nav_sx(kw.get("section"))
|
||||
return mobile_menu_sx(
|
||||
sx_call("mobile-menu-section",
|
||||
label="sx", href="/", level=1, colour="violet",
|
||||
items=SxExpr(main_nav)),
|
||||
await mobile_root_nav_sx(ctx),
|
||||
)
|
||||
|
||||
|
||||
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, 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 = _main_nav_sx(section)
|
||||
|
||||
parts = []
|
||||
if sub_nav:
|
||||
parts.append(sx_call("mobile-menu-section",
|
||||
label=sub_label, href=sub_href, level=2, colour="violet",
|
||||
items=SxExpr(sub_nav)))
|
||||
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))
|
||||
return mobile_menu_sx(*parts)
|
||||
register_sx_layout("sx", "sx-layout-full", "sx-layout-oob", "sx-layout-mobile")
|
||||
register_sx_layout("sx-section", "sx-section-layout-full",
|
||||
"sx-section-layout-oob", "sx-section-layout-mobile")
|
||||
|
||||
Reference in New Issue
Block a user