summaryrefslogtreecommitdiff
path: root/src/dompa
diff options
context:
space:
mode:
authorAsko Nõmm <asko@apesrc.com>2026-02-11 01:53:02 +0200
committerAsko Nõmm <asko@apesrc.com>2026-02-11 01:53:02 +0200
commitba9005587b045d417b460f59145032f569c95cba (patch)
treec1a1d97710f896d519ed5679353c4955251604a5 /src/dompa
parentd23410f547608deae53ed8e028b46f8572552ef3 (diff)
Allow docstrings in `defhtml` (closes #2)allow-docstrings-in-defhtml
Diffstat (limited to 'src/dompa')
-rw-r--r--src/dompa/nodes.cljc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/dompa/nodes.cljc b/src/dompa/nodes.cljc
index 58ff045..7e8f769 100644
--- a/src/dompa/nodes.cljc
+++ b/src/dompa/nodes.cljc
@@ -95,10 +95,14 @@
(defmacro defhtml
"Creates a new function with `name` that outputs HTML.
+ Optionally accepts a docstring between the name and the argument vector.
+
Example usage:
```clojure
- (defhtml about-page [who]
+ (defhtml about-page
+ \"Renders the about page for the given person.\"
+ [who]
($ :div
($ \"hello \" who)))
@@ -106,8 +110,11 @@
```
"
[name & args-and-elements]
- (let [[args & elements] args-and-elements]
- `(defn ~name ~args
+ (let [[maybe-doc & rest] args-and-elements
+ [docstring args elements] (if (string? maybe-doc)
+ [maybe-doc (first rest) (next rest)]
+ [nil maybe-doc rest])]
+ `(defn ~name ~@(when docstring [docstring]) ~args
(->html (vector ~@elements)))))
(defn- list-of-one?