diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-10-09 22:05:47 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-10-09 22:05:47 +0300 |
| commit | d654135ffebe935317a1f946c123bd25e4fb6aa3 (patch) | |
| tree | 4568d42e8732c0f80b55afee1e5efa302b8007c9 /src | |
| parent | 06085b955bb2959a88844dae9f77a0f35ee6a8c5 (diff) | |
Do away with the $ macro for runtime-agnostic purposes
Diffstat (limited to 'src')
| -rw-r--r-- | src/dompa/nodes.clj | 26 | ||||
| -rw-r--r-- | src/dompa/nodes.cljc (renamed from src/dompa/nodes/shared.cljc) | 26 | ||||
| -rw-r--r-- | src/dompa/nodes.cljs | 24 |
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))))) - |
