diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-09-22 17:41:54 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-09-22 17:41:54 +0300 |
| commit | 1cde4cbae25e4cd1a79e882f0858f44b664a453b (patch) | |
| tree | 46ab0102f787b71c9f6dac737ee4c2156cbc536f /src/dompa/utils.cljc | |
| parent | 2362996d9788638e139c3102117dcd2f43e9466b (diff) | |
Improvements to turning nodes into a HTML string, namely added support for attributes, and improvements to the $ macro.
Diffstat (limited to 'src/dompa/utils.cljc')
| -rw-r--r-- | src/dompa/utils.cljc | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/dompa/utils.cljc b/src/dompa/utils.cljc index 1a6bff7..285566d 100644 --- a/src/dompa/utils.cljc +++ b/src/dompa/utils.cljc @@ -1,21 +1,34 @@ -(ns dompa.utils) +(ns dompa.utils + (:require [dompa.nodes :as nodes])) (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)})))) + (if (string? name) + {:name :dompa/text + :value name} + (let [node {:name 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 +(defn- page [] (list - ($ doctype {:html true}) - ($ head) - ($ body - ($ span {:class "test"} - ($ span {:class "test2"})))))
\ No newline at end of file + ($ :!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."))))))) + +(comment + ($ "asdasd") + (page) + (nodes/->html (page)))
\ No newline at end of file |
