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:
@@ -1,4 +1,8 @@
|
||||
"""SX docs page routes."""
|
||||
"""SX docs page routes.
|
||||
|
||||
Page GET routes are defined declaratively in sxc/pages/docs.sx via defpage.
|
||||
This file contains only redirect routes and example API endpoints.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
@@ -14,122 +18,6 @@ from shared.browser.app.csrf import csrf_exempt
|
||||
def register(url_prefix: str = "/") -> Blueprint:
|
||||
bp = Blueprint("pages", __name__, url_prefix=url_prefix)
|
||||
|
||||
def _is_sx_request() -> bool:
|
||||
return bool(request.headers.get("SX-Request") or request.headers.get("HX-Request"))
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Home
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/")
|
||||
async def index():
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import home_oob_sx
|
||||
return sx_response(await home_oob_sx())
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_home_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_home_page_sx(ctx)
|
||||
return await make_response(html, 200)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Docs
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/docs/")
|
||||
async def docs_index():
|
||||
from quart import redirect
|
||||
return redirect("/docs/introduction")
|
||||
|
||||
@bp.get("/docs/<slug>")
|
||||
async def docs_page(slug: str):
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import docs_oob_sx
|
||||
return sx_response(await docs_oob_sx(slug))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_docs_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_docs_page_sx(ctx, slug)
|
||||
return await make_response(html, 200)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Reference
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/reference/")
|
||||
async def reference_index():
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import reference_oob_sx
|
||||
return sx_response(await reference_oob_sx(""))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_reference_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_reference_page_sx(ctx, "")
|
||||
return await make_response(html, 200)
|
||||
|
||||
@bp.get("/reference/<slug>")
|
||||
async def reference_page(slug: str):
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import reference_oob_sx
|
||||
return sx_response(await reference_oob_sx(slug))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_reference_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_reference_page_sx(ctx, slug)
|
||||
return await make_response(html, 200)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Protocols
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/protocols/")
|
||||
async def protocols_index():
|
||||
from quart import redirect
|
||||
return redirect("/protocols/wire-format")
|
||||
|
||||
@bp.get("/protocols/<slug>")
|
||||
async def protocol_page(slug: str):
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import protocol_oob_sx
|
||||
return sx_response(await protocol_oob_sx(slug))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_protocol_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_protocol_page_sx(ctx, slug)
|
||||
return await make_response(html, 200)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Examples
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/examples/")
|
||||
async def examples_index():
|
||||
from quart import redirect
|
||||
return redirect("/examples/click-to-load")
|
||||
|
||||
@bp.get("/examples/<slug>")
|
||||
async def examples_page(slug: str):
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import examples_oob_sx
|
||||
return sx_response(await examples_oob_sx(slug))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_examples_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_examples_page_sx(ctx, slug)
|
||||
return await make_response(html, 200)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Example API endpoints (for live demos)
|
||||
# ------------------------------------------------------------------
|
||||
@@ -821,26 +709,4 @@ def register(url_prefix: str = "/") -> Blueprint:
|
||||
oob_comp = _oob_code("retry-comp", comp_text)
|
||||
return sx_response(f'(<> {sx_src} {oob_wire} {oob_comp})')
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Essays
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@bp.get("/essays/")
|
||||
async def essays_index():
|
||||
from quart import redirect
|
||||
return redirect("/essays/sx-sucks")
|
||||
|
||||
@bp.get("/essays/<slug>")
|
||||
async def essay_page(slug: str):
|
||||
if _is_sx_request():
|
||||
from shared.sx.helpers import sx_response
|
||||
from sxc.sx_components import essay_oob_sx
|
||||
return sx_response(await essay_oob_sx(slug))
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sxc.sx_components import render_essay_page_sx
|
||||
ctx = await get_template_context()
|
||||
html = await render_essay_page_sx(ctx, slug)
|
||||
return await make_response(html, 200)
|
||||
|
||||
return bp
|
||||
|
||||
Reference in New Issue
Block a user