Add macros, declarative handlers (defhandler), and convert all fragment routes to sx
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Phase 1 — Macros: defmacro + quasiquote syntax (`, ,, ,@) in parser,
evaluator, HTML renderer, and JS mirror. Macro type, expansion, and
round-trip serialization.
Phase 2 — Expanded primitives: app-url, url-for, asset-url, config,
format-date, parse-int (pure); service, request-arg, request-path,
nav-tree, get-children (I/O); jinja-global, relations-from (pure).
Updated _io_service to accept (service "registry-name" "method" :kwargs)
with auto kebab→snake conversion. DTO-to-dict now expands datetime fields
into year/month/day convenience keys. Tuple returns converted to lists.
Phase 3 — Declarative handlers: HandlerDef type, defhandler special form,
handler registry (service → name → HandlerDef), async evaluator+renderer
(async_eval.py) that awaits I/O primitives inline within control flow.
Handler loading from .sx files, execute_handler, blueprint factory.
Phase 4 — Convert all fragment routes: 13 Python fragment handlers across
8 services replaced with declarative .sx handler files. All routes.py
simplified to uniform sx dispatch pattern. Two Jinja HTML handlers
(events/container-cards, events/account-page) kept as Python.
New files: shared/sx/async_eval.py, shared/sx/handlers.py,
shared/sx/tests/test_handlers.py, plus 13 handler .sx files under
{service}/sx/handlers/. MarketService.product_by_slug() added.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
40
federation/sx/handlers/link-card.sx
Normal file
40
federation/sx/handlers/link-card.sx
Normal file
@@ -0,0 +1,40 @@
|
||||
;; Federation link-card fragment handler
|
||||
;;
|
||||
;; Renders actor profile preview card(s) by username.
|
||||
;; Supports single mode (?slug=x or ?username=x) and batch mode (?keys=x,y,z).
|
||||
|
||||
(defhandler link-card (&key username slug keys)
|
||||
(if keys
|
||||
(let ((usernames (filter (fn (u) (not (empty? u)))
|
||||
(map trim (split keys ",")))))
|
||||
(<> (map (fn (u)
|
||||
(let ((actor (service "federation" "get-actor-by-username" :username u)))
|
||||
(<> (str "<!-- fragment:" u " -->")
|
||||
(when (not (nil? actor))
|
||||
(~link-card
|
||||
:link (app-url "federation"
|
||||
(str "/users/" (get actor "preferred_username")))
|
||||
:title (or (get actor "display_name")
|
||||
(get actor "preferred_username"))
|
||||
:image nil
|
||||
:icon "fas fa-user"
|
||||
:subtitle (when (get actor "preferred_username")
|
||||
(str "@" (get actor "preferred_username")))
|
||||
:detail (get actor "summary")
|
||||
:data-app "federation"))))) usernames)))
|
||||
(let ((lookup (or username slug)))
|
||||
(when (not (empty? (or lookup "")))
|
||||
(let ((actor (service "federation" "get-actor-by-username"
|
||||
:username lookup)))
|
||||
(when (not (nil? actor))
|
||||
(~link-card
|
||||
:link (app-url "federation"
|
||||
(str "/users/" (get actor "preferred_username")))
|
||||
:title (or (get actor "display_name")
|
||||
(get actor "preferred_username"))
|
||||
:image nil
|
||||
:icon "fas fa-user"
|
||||
:subtitle (when (get actor "preferred_username")
|
||||
(str "@" (get actor "preferred_username")))
|
||||
:detail (get actor "summary")
|
||||
:data-app "federation")))))))
|
||||
@@ -17,8 +17,9 @@ from shared.sx.helpers import (
|
||||
root_header_sx, full_page_sx, header_child_sx,
|
||||
)
|
||||
|
||||
# Load federation-specific .sx components at import time
|
||||
load_service_components(os.path.dirname(os.path.dirname(__file__)))
|
||||
# Load federation-specific .sx components + handlers at import time
|
||||
load_service_components(os.path.dirname(os.path.dirname(__file__)),
|
||||
service_name="federation")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user