From ba9005587b045d417b460f59145032f569c95cba Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Wed, 11 Feb 2026 01:53:02 +0200 Subject: Allow docstrings in `defhtml` (closes #2) --- src/dompa/nodes.cljc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/dompa') 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? -- cgit v1.2.3