summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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))))))