summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dompa/nodes.clj26
-rw-r--r--src/dompa/nodes.cljc (renamed from src/dompa/nodes/shared.cljc)26
-rw-r--r--src/dompa/nodes.cljs24
3 files changed, 24 insertions, 52 deletions
diff --git a/src/dompa/nodes.clj b/src/dompa/nodes.clj
deleted file mode 100644
index 53020ba..0000000
--- a/src/dompa/nodes.clj
+++ /dev/null
@@ -1,26 +0,0 @@
-(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#)))))
diff --git a/src/dompa/nodes/shared.cljc b/src/dompa/nodes.cljc
index b876048..236271d 100644
--- a/src/dompa/nodes/shared.cljc
+++ b/src/dompa/nodes.cljc
@@ -1,4 +1,4 @@
-(ns dompa.nodes.shared)
+(ns dompa.nodes)
(def ^:private default-void-nodes
#{:!doctype :area :base :br :col :embed :hr :img :input
@@ -30,7 +30,7 @@
(str html (-> node :node/value))
(contains? void-nodes (-> node :node/name))
- (str html "<" node-name node-attrs">")
+ (str html "<" node-name node-attrs ">")
:else
(let [value (nodes->html-fn (-> node :node/children))]
@@ -93,3 +93,25 @@
(let [[args & elements] args-and-elements]
`(defn ~name ~args
(->html [~@elements]))))
+
+(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)))))
diff --git a/src/dompa/nodes.cljs b/src/dompa/nodes.cljs
deleted file mode 100644
index 8e19e2f..0000000
--- a/src/dompa/nodes.cljs
+++ /dev/null
@@ -1,24 +0,0 @@
-(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)))))
-