diff --git a/lib/host/blog.sx b/lib/host/blog.sx index ea13c316..ad4d7608 100644 --- a/lib/host/blog.sx +++ b/lib/host/blog.sx @@ -527,11 +527,36 @@ (fn (slug body) (let ((r (host/blog-get slug))) (when r (host/blog--write! slug (merge r {:body body})))))) +;; The resolver for the composition `each` graph-query source (compose.sx asks the context +;; for "query"). `(query REL TYPE)` -> the objects related to TYPE by REL, as full records +;; so the per-item template can field them. Today the supported relation is is-a (TYPE's +;; transitive instances, via host/blog-instances-of); the dispatch leaves room for more. +;; This is the DATA-DRIVEN each source — the object's `each` is the query, the render is +;; the run over whatever the graph currently holds. +(define host/blog--comp-query + (fn (qargs ctx) + (let ((rel (str (first qargs))) (type (str (first (rest qargs))))) + (cond + ((= rel "is-a") (map host/blog-get (host/blog-instances-of type))) + (else (list)))))) +;; the render context for a :body: auth from the principal + the graph-query resolver. +(define host/blog--comp-ctx + (fn (principal) + (merge (if (nil? principal) {} {"auth" "yes"}) + {"query" host/blog--comp-query}))) ;; Seed a live demo of the composition fold: one object, rendered by host/comp-render, that ;; shows seq + alt(when auth) + row(par) + each — and renders DIFFERENTLY logged-in vs out. (define host/blog-seed-compose-demo! (fn () (begin + ;; a demo type + two instances, so the each(query …) below iterates REAL graph data — + ;; the list isn't baked into the body, it's whatever is-a compose-item right now. + (host/blog-seed! "compose-item" "Compose Item" "(article (h1 \"Compose Item\"))" "published") + (host/blog-relate! "compose-item" "type" "subtype-of") + (host/blog-seed! "compose-item-revel" "Revel Show" "(article (h1 \"Revel Show\"))" "published") + (host/blog-seed! "compose-item-pub" "Pub Night" "(article (h1 \"Pub Night\"))" "published") + (host/blog-relate! "compose-item-revel" "compose-item" "is-a") + (host/blog-relate! "compose-item-pub" "compose-item" "is-a") (host/blog-seed! "compose-demo" "Composition Demo" "(article (h1 \"Composition Demo\") (p \"Rendered via the composition fold.\"))" "published") (host/blog--set-body! "compose-demo" @@ -542,9 +567,9 @@ (text "

Two columns (par)

") (row (text "
Column A
") (text "
Column B
")) - (text "

A list (each)