summaryrefslogtreecommitdiff
path: root/macros.lisp
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-09-09 23:21:07 +0800
committereltrac <hi@eltr.ac>2026-09-09 23:21:07 +0800
commitf9831ef8972a71eb20e8a52de6ed02c747428bf4 (patch)
treef531b9a7730357ea7a50ef9d1cf020bf91e59623 /macros.lisp
parent0ca8be1d4005eb536132fbb970565669a5787672 (diff)
macros: refactor MUIF and MUWHENmain
now MUWHEN depends on MUIF just like Lisp itself.
Diffstat (limited to 'macros.lisp')
-rw-r--r--macros.lisp19
1 files changed, 11 insertions, 8 deletions
diff --git a/macros.lisp b/macros.lisp
index e9db83d..09b59f4 100644
--- a/macros.lisp
+++ b/macros.lisp
@@ -6,6 +6,7 @@
(ps ,@body))))
;; Templating macros
+;; TODO needs to be moved to another file
(defmacro mu (&rest body)
"Macro writing Mustache syntax, namely the '{{ mustache }}'"
`(list :raw (concatenate 'string "{{ " ,@body " }}")))
@@ -28,19 +29,21 @@
(defmacro mublock (name attrs &rest body)
"Macro writing a block where a '{{ end }}' is followed."
- `(list
+ `(values
(mu ,name " " ,attrs)
,@(mapcar (lambda (x) `',x) body)
(mu "end")))
-(defmacro muwhen (condition &rest body)
- `(mublock "if" ,condition ,@body))
-
(defmacro muif (condition do do-else)
- `(muwhen ,condition
- ,@do
- (:RAW `(mu "else"))
- ,@do-else))
+ `(mublock "if" ,condition
+ ,@do
+ ,@(when do-else
+ (concatenate 'list
+ (list (mu "else"))
+ do-else))))
+
+(defmacro muwhen (condition &rest do)
+ `(muif ,condition ,do nil))
(defun quote-if-string (str)
(if (stringp str)