Merge branch 'worktree-sx-layout-conversion' into macros

# Conflicts:
#	blog/sxc/pages/layouts.py
#	cart/sxc/pages/layouts.py
#	events/sxc/pages/helpers.py
#	events/sxc/pages/layouts.py
#	market/sxc/pages/layouts.py
#	sx/sxc/pages/layouts.py
This commit is contained in:
2026-03-04 22:25:52 +00:00
18 changed files with 1289 additions and 1180 deletions

View File

@@ -1,17 +1,17 @@
;; Federation layout defcomps — read ctx values from env free variables.
;; `actor` is injected into env by the layout registration in __init__.py.
;; Federation layout defcomps — fully self-contained via IO primitives.
;; Registered via register_sx_layout("social", ...) in __init__.py.
;; Full page: root header + social header in header-child
(defcomp ~social-layout-full ()
(<> (~root-header-auto)
(~header-child-sx
:inner (~federation-social-header
:nav (~federation-social-nav :actor actor)))))
:nav (~federation-social-nav :actor (federation-actor-ctx))))))
;; OOB (HTMX): social header oob + root header oob
(defcomp ~social-layout-oob ()
(<> (~oob-header-sx
:parent-id "root-header-child"
:row (~federation-social-header
:nav (~federation-social-nav :actor actor)))
:nav (~federation-social-nav :actor (federation-actor-ctx))))
(~root-header-auto true)))

View File

@@ -15,6 +15,5 @@ def _load_federation_page_files() -> None:
def _register_federation_layouts() -> None:
from shared.sx.layouts import register_custom_layout
from .utils import _social_full, _social_oob
register_custom_layout("social", _social_full, _social_oob)
from shared.sx.layouts import register_sx_layout
register_sx_layout("social", "social-layout-full", "social-layout-oob")

View File

@@ -1,8 +1,6 @@
"""Federation page utilities — serializers, actor helpers, social page builder."""
from __future__ import annotations
from typing import Any
def _serialize_actor(actor) -> dict | None:
"""Serialize an actor profile to a dict for sx defcomps."""
@@ -24,7 +22,7 @@ def _serialize_remote_actor(a) -> dict:
async def _social_page(ctx: dict, actor, *, content: str,
title: str = "Rose Ash", meta_html: str = "") -> str:
"""Build a full social page with social header."""
"""Build a full social page with social header (non-defpage routes)."""
from shared.sx.helpers import render_to_sx_with_env, full_page_sx
from markupsafe import escape
@@ -47,22 +45,3 @@ def _require_actor():
if not actor:
abort(403, "You need to choose a federation username first")
return actor
def _actor_data(ctx: dict) -> dict | None:
actor = ctx.get("actor")
if not actor:
return None
return _serialize_actor(actor)
async def _social_full(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import render_to_sx_with_env
env = {"actor": kw.get("actor") or _actor_data(ctx)}
return await render_to_sx_with_env("social-layout-full", env)
async def _social_oob(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import render_to_sx_with_env
env = {"actor": kw.get("actor") or _actor_data(ctx)}
return await render_to_sx_with_env("social-layout-oob", env)