clj all the things

This commit is contained in:
Adam Jeniski 2025-07-23 10:31:40 -09:00
parent 7b0b0673b4
commit b83287fb76
2 changed files with 14 additions and 23 deletions

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello world d*</title>
<script type="module" src="https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js"></script>
<link rel="icon" type="image/x-icon" href="https://data-star.dev/cdn-cgi/image/format=auto,width=24/static/images/rocket-48x48-4c739bfaffe86a6ffcc3a6d77e3c5547730f03d74c11aa460209596d1811f7a3.png">
</head>
<body>
%%content%%
</body>
</html>

View File

@ -10,8 +10,7 @@
[starfederation.datastar.clojure.api :as d*] [starfederation.datastar.clojure.api :as d*]
[starfederation.datastar.clojure.adapter.ring :refer [->sse-response on-open on-close] :as dr] [starfederation.datastar.clojure.adapter.ring :refer [->sse-response on-open on-close] :as dr]
[clojure.data.json :as json] [clojure.data.json :as json]
[starfederation.datastar.clojure.expressions :refer [->expr]] [starfederation.datastar.clojure.expressions :refer [->expr]]))
))
(declare conns add-elements! sse-navigate! disconnect-sse!) (declare conns add-elements! sse-navigate! disconnect-sse!)
@ -22,18 +21,21 @@
;; html utils ;; html utils
(defn html->str [hiccup-forms] (defn html->str [hiccup-forms]
(h/html (h/html (hc/compile hiccup-forms)))
(hc/compile
hiccup-forms)))
(defn html-template [content] (defn html-template [content]
(-> (io/resource "public/index.html") (html->str
slurp [:html {:lang "en"}
(string/split-lines) [:head
(->> (drop 3) [:title "hello world d*"]
(apply str)) [:script {:type "module"
(str "<div data-on-load=\"@get('/connect')\"></div>") :src "https://cdn.jsdelivr.net/gh/starfederation/datastar@main/bundles/datastar.js"}]
(string/replace "%%content%%" content))) [:link {:rel "icon"
:type "image/x-icon"
:href "https://data-star.dev/cdn-cgi/image/format=auto,width=24/static/images/rocket-48x48-4c739bfaffe86a6ffcc3a6d77e3c5547730f03d74c11aa460209596d1811f7a3.png"}]]
[:body
(h/raw content)
[:div {:data-on-load (->expr (@get "/connect"))}]]]))
(defn at-get [page-or-action] (defn at-get [page-or-action]
(format "@get('%s')" (:url page-or-action))) (format "@get('%s')" (:url page-or-action)))