From f9831ef8972a71eb20e8a52de6ed02c747428bf4 Mon Sep 17 00:00:00 2001 From: eltrac Date: Wed, 9 Sep 2026 23:21:07 +0800 Subject: macros: refactor MUIF and MUWHEN now MUWHEN depends on MUIF just like Lisp itself. --- macros.lisp | 19 +++++++++++-------- 1 file 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) -- cgit v1.2.3