From 4602591267732858e7125fdfabb781d8f23d6d2f Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 22 Jun 2024 14:26:31 -0700 Subject: Add: data-id; bare constructor function in contents; ps macros --- src/hypnotisml.lisp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/hypnotisml.lisp b/src/hypnotisml.lisp index 729841a..5b0a7dd 100644 --- a/src/hypnotisml.lisp +++ b/src/hypnotisml.lisp @@ -163,7 +163,7 @@ (*print-case* :downcase)) (indent stream) (with-slots (attributes style tag children id) elem - (format t "<~a" tag) + (format t "<~a data-hypno-id=~s" tag id) (when (and attributes (attribs-list attributes)) (format t " ~{~a=~s~^ ~}" (attribs-list attributes))) @@ -190,15 +190,20 @@ ;;; ELEM BUILDERS +;; TODO: Make elem constructor stheir own funcallable class for better +;; type csae handling and therefore better debugging experience down +;; the road. + (defun ensure-node (thing) (etypecase thing (dom-node thing) - (string (make-instance 'text :content thing)))) + (string (make-instance 'text :content thing)) + (function (funcall thing)))) (defun filter-nodes (contents) (cl:loop :for c :in contents - :when (or (stringp c) (dom-node-p c)) + :when (or (stringp c) (dom-node-p c) (functionp c)) :collect (ensure-node c))) (defun parse-contents (contents) @@ -223,7 +228,9 @@ :tag ,(a:make-keyword tag) :style ,styles :attributes ,attribs - :children ,children)))))))) + :children ,children))) + :collect `(defvar ,fname) + :collect `(setf ,fname #',fname)))))) (defelems a abbr @@ -402,3 +409,13 @@ (vert vertical div))) +;;; Parenscript + +(ps:defpsmacro (elem) + `(ps:@ document (get-element-by-id (ps:lisp (elem-id ,elem))))) + +(ps:defpsmacro (elem innerhtml) + (let ((template (ps:ps-gensym))) + `(let ((,template (ps:chain document (create-element "template")))) + (setf (ps:@ ,template inner-h-t-m-l) ,innerhtml) + (ps:chain ( ,elem) (replace-with (ps:@ ,template content)))))) -- cgit v1.2.3