From 29c5b153843a29d5e0a7acf4fc78cd00a2c4f02f Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Wed, 8 Oct 2025 20:48:49 +0300 Subject: Fix CLJS nodes test --- src/dompa/nodes.clj | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/dompa/nodes.clj (limited to 'src/dompa/nodes.clj') diff --git a/src/dompa/nodes.clj b/src/dompa/nodes.clj new file mode 100644 index 0000000..53020ba --- /dev/null +++ b/src/dompa/nodes.clj @@ -0,0 +1,26 @@ +(ns dompa.nodes) + +(defmacro $ + "Creates a new node. Particularly useful + where you need compile-time composition over run-time, like when + combined with the `defhtml` macro to create HTML string outputs. + + Usage: + + ```clojure + ($ :div + ($ \"hello world\" )) + ```" + [name & opts] + `(if (string? ~name) + {:node/name :dompa/text + :node/value (str ~name ~@opts)} + (let [opts# (list ~@opts) + first-opt# (first opts#) + attrs?# (and (map? first-opt#) + (not (contains? first-opt# :node/name))) + attrs# (if attrs?# first-opt# {}) + children# (if attrs?# (rest opts#) opts#)] + (cond-> {:node/name ~name} + attrs?# (assoc :node/attrs attrs#) + (seq children#) (assoc :node/children children#))))) -- cgit v1.2.3