Migrate all apps to defpage declarative page routes
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m41s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m41s
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:
109
federation/sxc/pages/__init__.py
Normal file
109
federation/sxc/pages/__init__.py
Normal file
@@ -0,0 +1,109 @@
|
||||
"""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", "")
|
||||
49
federation/sxc/pages/social.sx
Normal file
49
federation/sxc/pages/social.sx
Normal file
@@ -0,0 +1,49 @@
|
||||
;; Federation social pages
|
||||
|
||||
(defpage home-timeline
|
||||
:path "/"
|
||||
:auth :login
|
||||
:layout :social
|
||||
:content (home-timeline-content))
|
||||
|
||||
(defpage public-timeline
|
||||
:path "/public"
|
||||
:auth :public
|
||||
:layout :social
|
||||
:content (public-timeline-content))
|
||||
|
||||
(defpage compose-form
|
||||
:path "/compose"
|
||||
:auth :login
|
||||
:layout :social
|
||||
:content (compose-content))
|
||||
|
||||
(defpage search
|
||||
:path "/search"
|
||||
:auth :public
|
||||
:layout :social
|
||||
:content (search-content))
|
||||
|
||||
(defpage following-list
|
||||
:path "/following"
|
||||
:auth :login
|
||||
:layout :social
|
||||
:content (following-content))
|
||||
|
||||
(defpage followers-list
|
||||
:path "/followers"
|
||||
:auth :login
|
||||
:layout :social
|
||||
:content (followers-content))
|
||||
|
||||
(defpage actor-timeline
|
||||
:path "/actor/<int:id>"
|
||||
:auth :public
|
||||
:layout :social
|
||||
:content (actor-timeline-content))
|
||||
|
||||
(defpage notifications
|
||||
:path "/notifications"
|
||||
:auth :login
|
||||
:layout :social
|
||||
:content (notifications-content))
|
||||
Reference in New Issue
Block a user