summaryrefslogtreecommitdiff
path: root/src/dompa/nodes.cljs
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-10-08 20:48:49 +0300
committerAsko Nõmm <asko@nmm.ee>2025-10-08 20:48:49 +0300
commit29c5b153843a29d5e0a7acf4fc78cd00a2c4f02f (patch)
treece1035969acc5ba4e5973f1a850a348bf48fa32a /src/dompa/nodes.cljs
parent64792f47f54708f9ec46ea7da691ce21981b9605 (diff)
Fix CLJS nodes test
Diffstat (limited to 'src/dompa/nodes.cljs')
-rw-r--r--src/dompa/nodes.cljs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/dompa/nodes.cljs b/src/dompa/nodes.cljs
new file mode 100644
index 0000000..8e19e2f
--- /dev/null
+++ b/src/dompa/nodes.cljs
@@ -0,0 +1,24 @@
+(ns dompa.nodes)
+
+(defn $
+ "Creates a new node
+
+ Usage:
+
+ ```clojure
+ ($ :div
+ ($ \"hello world\" ))
+ ```"
+ [name & opts]
+ (if (string? name)
+ {:node/name :dompa/text
+ :node/value (apply str name opts)}
+ (let [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)))))
+