summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--resources/clj-kondo/config.edn6
-rw-r--r--resources/clj-kondo/hooks/dompa.clj16
-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
-rw-r--r--test/dompa/nodes_test.cljc6
7 files changed, 38 insertions, 67 deletions
diff --git a/.gitignore b/.gitignore
index 4f6e667..99d59fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ dompa.iml
target/
.lsp/
cljs-test-runner-out/
+.calva/ \ No newline at end of file
diff --git a/resources/clj-kondo/config.edn b/resources/clj-kondo/config.edn
index 8ee11e4..e6b8708 100644
--- a/resources/clj-kondo/config.edn
+++ b/resources/clj-kondo/config.edn
@@ -1,5 +1,5 @@
{:hooks {:analyze-call {dompa.nodes/$ hooks.dompa/$
- dompa.nodes.shared/defhtml hooks.dompa/defhtml}}
+ dompa.nodes/defhtml hooks.dompa/defhtml}}
:linters {:dompa.nodes/$-arg-validation {:level :warning}
- :dompa.nodes.shared/defhtml-arg-validation {:level :warning}}
- :lint-as {dompa.nodes.shared/defhtml clojure.core/defn}}
+ :dompa.nodes/defhtml-arg-validation {:level :warning}}
+ :lint-as {dompa.nodes/defhtml clojure.core/defn}}
diff --git a/resources/clj-kondo/hooks/dompa.clj b/resources/clj-kondo/hooks/dompa.clj
index dac5762..1712a02 100644
--- a/resources/clj-kondo/hooks/dompa.clj
+++ b/resources/clj-kondo/hooks/dompa.clj
@@ -41,8 +41,8 @@
(doseq [arg (filter #(not (api/list-node? %)) rest-args)]
(api/reg-finding!
(assoc (meta arg)
- :message (str "Invalid argument type. Argument must be a $ macro "
- "or a sequence of $ macros.")
+ :message (str "Invalid argument type. Argument must be a $ node "
+ "or a sequence of $ nodes.")
:type :dompa.nodes/$-arg-validation)))
; if the first arg is a keyword, the second arg is a map, then from
@@ -52,8 +52,8 @@
(not (every? #(api/list-node? %) (rest rest-args))))
(api/reg-finding!
(assoc (meta (second rest-args))
- :message (str "Invalid argument type. Argument must be a $ macro "
- "or a sequence of $ macros.")
+ :message (str "Invalid argument type. Argument must be a $ node. "
+ "or a sequence of $ nodes.")
:type :dompa.nodes/$-arg-validation)))))
(defn defhtml [{:keys [node]}]
@@ -64,20 +64,20 @@
(api/reg-finding!
(assoc (meta first-arg)
:message "Invalid argument type. Binding name must be a symbol."
- :type :dompa.templates/defhtml-arg-validation))
+ :type :dompa.nodes/defhtml-arg-validation))
; second argument should be a vector
(not (api/vector-node? second-arg))
(api/reg-finding!
(assoc (meta second-arg)
:message "Invalid argument type. Must be a vector of arguments."
- :type :dompa.templates/defhtml-arg-validation))
+ :type :dompa.nodes/defhtml-arg-validation))
; rest of the arguments should be a list
(not (every? #(api/list-node? %) rest-args))
(doseq [arg rest-args]
(api/reg-finding!
(assoc (meta arg)
- :message (str "Invalid argument type. Argument must be a $ macro "
- "or a sequence of $ macros.")))))))
+ :message (str "Invalid argument type. Argument must be a $ node "
+ "or a sequence of $ nodes")))))))
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)))))
-
diff --git a/test/dompa/nodes_test.cljc b/test/dompa/nodes_test.cljc
index eb86c7a..8d39da1 100644
--- a/test/dompa/nodes_test.cljc
+++ b/test/dompa/nodes_test.cljc
@@ -1,11 +1,9 @@
(ns dompa.nodes-test
#?(:clj (:require [clojure.test :refer [deftest is testing]]
- [dompa.nodes :refer [$]]
- [dompa.nodes.shared :refer [defhtml traverse ->html]]
+ [dompa.nodes :refer [$ defhtml traverse ->html]]
[dompa.html :as html]))
#?(:cljs (:require [cljs.test :refer-macros [deftest testing is]]
- [dompa.nodes :refer [$]]
- [dompa.nodes.shared :refer [traverse ->html] :refer-macros [defhtml]]
+ [dompa.nodes :refer [$ traverse ->html] :refer-macros [defhtml]]
[dompa.html :as html])))
(defhtml hello [who]