Files
rose-ash/federation/sxc/pages/__init__.py
giles c243d17eeb
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m41s
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>
2026-03-03 14:52:34 +00:00

110 lines
3.2 KiB
Python

"""Federation defpage setup — registers layouts, page helpers, and loads .sx pages."""
from __future__ import annotations
from typing import Any
def setup_federation_pages() -> None:
"""Register federation-specific layouts, page helpers, and load page definitions."""
_register_federation_layouts()
_register_federation_helpers()
_load_federation_page_files()
def _load_federation_page_files() -> None:
import os
from shared.sx.pages import load_page_dir
load_page_dir(os.path.dirname(__file__), "federation")
# ---------------------------------------------------------------------------
# Layouts
# ---------------------------------------------------------------------------
def _register_federation_layouts() -> None:
from shared.sx.layouts import register_custom_layout
register_custom_layout("social", _social_full, _social_oob)
def _social_full(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, header_child_sx
from sx.sx_components import _social_header_sx
actor = ctx.get("actor")
root_hdr = root_header_sx(ctx)
social_hdr = _social_header_sx(actor)
child = header_child_sx(social_hdr)
return "(<> " + root_hdr + " " + child + ")"
def _social_oob(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, sx_call, SxExpr
from sx.sx_components import _social_header_sx
actor = ctx.get("actor")
social_hdr = _social_header_sx(actor)
child_oob = sx_call("oob-header-sx",
parent_id="root-header-child",
row=SxExpr(social_hdr))
root_hdr_oob = root_header_sx(ctx, oob=True)
return "(<> " + child_oob + " " + root_hdr_oob + ")"
# ---------------------------------------------------------------------------
# Page helpers
# ---------------------------------------------------------------------------
def _register_federation_helpers() -> None:
from shared.sx.pages import register_page_helpers
register_page_helpers("federation", {
"home-timeline-content": _h_home_timeline_content,
"public-timeline-content": _h_public_timeline_content,
"compose-content": _h_compose_content,
"search-content": _h_search_content,
"following-content": _h_following_content,
"followers-content": _h_followers_content,
"actor-timeline-content": _h_actor_timeline_content,
"notifications-content": _h_notifications_content,
})
def _h_home_timeline_content():
from quart import g
return getattr(g, "home_timeline_content", "")
def _h_public_timeline_content():
from quart import g
return getattr(g, "public_timeline_content", "")
def _h_compose_content():
from quart import g
return getattr(g, "compose_content", "")
def _h_search_content():
from quart import g
return getattr(g, "search_content", "")
def _h_following_content():
from quart import g
return getattr(g, "following_content", "")
def _h_followers_content():
from quart import g
return getattr(g, "followers_content", "")
def _h_actor_timeline_content():
from quart import g
return getattr(g, "actor_timeline_content", "")
def _h_notifications_content():
from quart import g
return getattr(g, "notifications_content", "")