Files
rose-ash/relations/sx/handlers/container-nav.sx
giles ab75e505a8
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Add macros, declarative handlers (defhandler), and convert all fragment routes to sx
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>
2026-03-03 00:22:18 +00:00

48 lines
2.2 KiB
Plaintext

;; Relations container-nav fragment handler
;;
;; Generic navigation fragment driven by the relation registry.
;; Renders nav items for all related entities of a container.
(defhandler container-nav (&key container_type container_id post_slug nav_class exclude)
(let ((ct (or container_type "page"))
(cid (parse-int (or container_id "0")))
(slug (or post_slug ""))
(ncls (or nav_class ""))
(excl-raw (or exclude ""))
(excl-set (filter (fn (e) (not (empty? e)))
(map trim (split excl-raw ","))))
;; URL builders per child type
(url-builders (dict :calendar "events" :market "market"))
;; Filter relation defs: visible + not excluded
(nav-defs (filter (fn (d)
(and (!= (get d "nav") "hidden")
(not (contains? excl-set (get d "name")))))
(relations-from ct))))
(when (not (empty? nav-defs))
(let ((parts (map (fn (defn)
(let ((children (get-children
:parent-type ct
:parent-id cid
:child-type (get defn "to_type")
:relation-type (get defn "name"))))
(<> (map (fn (child)
(let ((child-slug (or (get (or (get child "metadata_") (dict)) "slug") "")))
(when (not (empty? child-slug))
(let ((path (if (not (empty? slug))
(str "/" slug "/" child-slug "/")
(str "/" child-slug "/")))
(svc-name (get url-builders (get defn "to_type")))
(href (if svc-name
(app-url svc-name path)
path)))
(~relation-nav
:href href
:name (or (get child "label") "")
:icon (or (get defn "nav_icon") "")
:nav-class ncls
:relation-type (get defn "name")))))) children)))) nav-defs)))
(<> parts)))))