summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-09-22 01:32:40 +0300
committerAsko Nõmm <asko@nmm.ee>2025-09-22 01:32:40 +0300
commit2362996d9788638e139c3102117dcd2f43e9466b (patch)
tree9f25266c6e8d75d2a43380620a131b9715ce4933 /src
parent42d7a2063b9a923b6538bee9c61eda04f1242d85 (diff)
Refactor into a macro
Diffstat (limited to 'src')
-rw-r--r--src/dompa/utils.cljc47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/dompa/utils.cljc b/src/dompa/utils.cljc
index 5e57e2c..1a6bff7 100644
--- a/src/dompa/utils.cljc
+++ b/src/dompa/utils.cljc
@@ -1,36 +1,21 @@
(ns dompa.utils)
-(defn- make-node
- [name & opts]
- (let [node {:name name}]
- (if (get (first opts) :name)
- (merge
- node
- (when-not (empty? opts)
- {:children opts}))
- (let [attrs (first opts)
- [_ & children] opts]
- (merge
- node
- {:attrs attrs}
- (when-not (empty? children)
- {:children children}))))))
-
-(defn doctype []
- (make-node :!DOCTYPE {:html true}))
-
-(defn head [& opts]
- (make-node :head opts))
-
-(defn body [& opts]
- (make-node :body opts))
-
-(defn span [& opts]
- (make-node :span opts))
+(defmacro $ [name & opts]
+ (let [node# {:name (keyword name)}
+ attrs? (map? (first opts))
+ attrs (if attrs? (first opts) {})
+ children (if attrs? (rest opts) opts)]
+ (merge
+ node#
+ (when attrs?
+ {:attrs attrs})
+ (when-not (empty? children)
+ {:children (into [] children)}))))
(comment
(list
- (doctype)
- (head)
- (body
- (span {:class "test"} (span {:class "test2"}))))) \ No newline at end of file
+ ($ doctype {:html true})
+ ($ head)
+ ($ body
+ ($ span {:class "test"}
+ ($ span {:class "test2"}))))) \ No newline at end of file