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>
43 lines
2.0 KiB
Plaintext
43 lines
2.0 KiB
Plaintext
;; Market link-card fragment handler
|
|
;;
|
|
;; Renders product preview card(s) by slug.
|
|
;; Supports single mode (?slug=x) and batch mode (?keys=x,y,z).
|
|
|
|
(defhandler link-card (&key slug keys)
|
|
(if keys
|
|
(let ((slugs (filter (fn (s) (not (empty? s)))
|
|
(map trim (split keys ",")))))
|
|
(<> (map (fn (s)
|
|
(let ((product (service "market" "product-by-slug" :slug s)))
|
|
(<> (str "<!-- fragment:" s " -->")
|
|
(when (not (nil? product))
|
|
(let ((link (app-url "market" (str "/product/" (get product "slug") "/")))
|
|
(subtitle (or (get product "brand") ""))
|
|
(detail (if (get product "special_price")
|
|
(str (get product "regular_price") " → " (get product "special_price"))
|
|
(if (get product "regular_price")
|
|
(str (get product "regular_price"))
|
|
""))))
|
|
(~link-card
|
|
:title (get product "title")
|
|
:image (get product "image")
|
|
:subtitle subtitle
|
|
:detail detail
|
|
:link link)))))) slugs)))
|
|
(when slug
|
|
(let ((product (service "market" "product-by-slug" :slug slug)))
|
|
(when (not (nil? product))
|
|
(let ((link (app-url "market" (str "/product/" (get product "slug") "/")))
|
|
(subtitle (or (get product "brand") ""))
|
|
(detail (if (get product "special_price")
|
|
(str (get product "regular_price") " → " (get product "special_price"))
|
|
(if (get product "regular_price")
|
|
(str (get product "regular_price"))
|
|
""))))
|
|
(~link-card
|
|
:title (get product "title")
|
|
:image (get product "image")
|
|
:subtitle subtitle
|
|
:detail detail
|
|
:link link)))))))
|