Migrate all apps to defpage declarative page routes
Replace Python GET page handlers with declarative defpage definitions in .sx files across all 8 apps (sx docs, orders, account, market, cart, federation, events, blog). Each app now has sxc/pages/ with setup functions, layout registrations, page helpers, and .sx defpage declarations. Core infrastructure: add g I/O primitive, PageDef support for auth/layout/ data/content/filter/aside/menu slots, post_author auth level, and custom layout registration. Remove ~1400 lines of render_*_page/render_*_oob boilerplate. Update all endpoint references in routes, sx_components, and templates to defpage_* naming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,8 +30,8 @@ def _register_sx_layouts() -> None:
|
||||
"""Register the sx docs layout presets."""
|
||||
from shared.sx.layouts import register_custom_layout
|
||||
|
||||
register_custom_layout("sx", _sx_full_headers, _sx_oob_headers)
|
||||
register_custom_layout("sx-section", _sx_section_full_headers, _sx_section_oob_headers)
|
||||
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)
|
||||
|
||||
|
||||
def _sx_full_headers(ctx: dict, **kw: Any) -> str:
|
||||
@@ -98,6 +98,47 @@ def _sx_section_oob_headers(ctx: dict, **kw: Any) -> str:
|
||||
return oob_header_sx("root-header-child", "sx-header-child", rows)
|
||||
|
||||
|
||||
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,
|
||||
)
|
||||
from sxc.sx_components import _main_nav_sx
|
||||
|
||||
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)),
|
||||
mobile_root_nav_sx(ctx),
|
||||
)
|
||||
|
||||
|
||||
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,
|
||||
)
|
||||
from sxc.sx_components import _main_nav_sx
|
||||
|
||||
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(mobile_root_nav_sx(ctx))
|
||||
return mobile_menu_sx(*parts)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Page helpers — Python functions callable from defpage content expressions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -15,6 +15,17 @@
|
||||
;; Docs section
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defpage docs-index
|
||||
:path "/docs/"
|
||||
:auth :public
|
||||
:layout (:sx-section
|
||||
:section "Docs"
|
||||
:sub-label "Docs"
|
||||
:sub-href "/docs/introduction"
|
||||
:sub-nav (docs-nav "Introduction")
|
||||
:selected "Introduction")
|
||||
:content (docs-content "introduction"))
|
||||
|
||||
(defpage docs-page
|
||||
:path "/docs/<slug>"
|
||||
:auth :public
|
||||
@@ -56,6 +67,17 @@
|
||||
;; Protocols section
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defpage protocols-index
|
||||
:path "/protocols/"
|
||||
:auth :public
|
||||
:layout (:sx-section
|
||||
:section "Protocols"
|
||||
:sub-label "Protocols"
|
||||
:sub-href "/protocols/wire-format"
|
||||
:sub-nav (protocols-nav "Wire Format")
|
||||
:selected "Wire Format")
|
||||
:content (protocol-content "wire-format"))
|
||||
|
||||
(defpage protocol-page
|
||||
:path "/protocols/<slug>"
|
||||
:auth :public
|
||||
@@ -71,6 +93,17 @@
|
||||
;; Examples section
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defpage examples-index
|
||||
:path "/examples/"
|
||||
:auth :public
|
||||
:layout (:sx-section
|
||||
:section "Examples"
|
||||
:sub-label "Examples"
|
||||
:sub-href "/examples/click-to-load"
|
||||
:sub-nav (examples-nav "Click to Load")
|
||||
:selected "Click to Load")
|
||||
:content (examples-content "click-to-load"))
|
||||
|
||||
(defpage examples-page
|
||||
:path "/examples/<slug>"
|
||||
:auth :public
|
||||
@@ -86,6 +119,17 @@
|
||||
;; Essays section
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defpage essays-index
|
||||
:path "/essays/"
|
||||
:auth :public
|
||||
:layout (:sx-section
|
||||
:section "Essays"
|
||||
:sub-label "Essays"
|
||||
:sub-href "/essays/sx-sucks"
|
||||
:sub-nav (essays-nav "sx sucks")
|
||||
:selected "sx sucks")
|
||||
:content (essay-content "sx-sucks"))
|
||||
|
||||
(defpage essay-page
|
||||
:path "/essays/<slug>"
|
||||
:auth :public
|
||||
|
||||
Reference in New Issue
Block a user