diff options
| author | eltrac <hi@eltr.ac> | 2026-09-09 23:21:07 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-09-09 23:21:07 +0800 |
| commit | f9831ef8972a71eb20e8a52de6ed02c747428bf4 (patch) | |
| tree | f531b9a7730357ea7a50ef9d1cf020bf91e59623 | |
| parent | 0ca8be1d4005eb536132fbb970565669a5787672 (diff) | |
macros: refactor MUIF and MUWHENmain
now MUWHEN depends on MUIF just like Lisp itself.
| -rw-r--r-- | macros.lisp | 19 |
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) |
