diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-09-23 02:08:12 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-09-23 02:08:12 +0300 |
| commit | 20fa62ab90ed87e143bf9b140ba4b7708f1e91ee (patch) | |
| tree | 717c19e9e39adcd29f8e53f58dd9e71ee5447900 /src/dompa/utils.cljc | |
| parent | 1cde4cbae25e4cd1a79e882f0858f44b664a453b (diff) | |
Make nodes have namespaces keys so that we could make `$` helper macro into a function instead.
Diffstat (limited to 'src/dompa/utils.cljc')
| -rw-r--r-- | src/dompa/utils.cljc | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/dompa/utils.cljc b/src/dompa/utils.cljc index 285566d..ea25d68 100644 --- a/src/dompa/utils.cljc +++ b/src/dompa/utils.cljc @@ -1,34 +1,40 @@ (ns dompa.utils (:require [dompa.nodes :as nodes])) -(defmacro $ [name & opts] +(defmacro defhtml [name & args-and-elements] + (let [[args & elements] args-and-elements] + `(defn ~name ~args + (nodes/->html (vector ~@elements))))) + +(defn $ [name & opts] (if (string? name) - {:name :dompa/text - :value name} - (let [node {:name name} - attrs? (map? (first opts)) + {:node/name :dompa/text + :node/value (str name (apply str opts))} + (let [node {:node/name name} + attrs? (not (get (first opts) :node/name)) attrs (if attrs? (first opts) {}) children (if attrs? (rest opts) opts)] (merge node (when attrs? - {:attrs attrs}) + {:node/attrs attrs}) (when-not (empty? children) - {:children (into [] children)}))))) + {:node/children children}))))) + +(defhtml page + [test] + ($ :!doctype {:html true}) + ($ :html {:lang "en"} + ($ :head + ($ :meta {:charset "utf-8"}) + ($ :link {:rel "stylesheet" :href "style.css"})) + ($ :body + ($ :span {:class "test"}) + ($ :span {:class "test2"} + ($ "hello" test))))) -(defn- page [] - (list - ($ :!doctype {:html true}) - ($ :html {:lang "en"} - ($ :head - ($ :meta {:charset "utf-8"}) - ($ :link {:rel "stylesheet" :href "style.css"})) - ($ :body - ($ :span {:class "test"} - ($ :span {:class "test2"} - ($ "hello, world."))))))) +(prn (page "world")) (comment - ($ "asdasd") - (page) - (nodes/->html (page)))
\ No newline at end of file + ($ :div {:class "test"} + ($ "asdasd" "asd")))
\ No newline at end of file |
