summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2024-06-22 14:26:31 -0700
committercolin <colin@cicadas.surf>2024-06-22 14:26:31 -0700
commit4602591267732858e7125fdfabb781d8f23d6d2f (patch)
treebf5c48838530a0652b01fcd1367d28a0c8c4b4cc
parentf625fb3b056652fe36909ccd0d23baf0a1e9f99e (diff)
Add: data-id; bare constructor function in contents; ps macros
-rw-r--r--src/hypnotisml.lisp25
1 files 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> (elem)
+ `(ps:@ document (get-element-by-id (ps:lisp (elem-id ,elem)))))
+
+(ps:defpsmacro <replace-elem> (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> ,elem) (replace-with (ps:@ ,template content))))))