summaryrefslogtreecommitdiff
path: root/src/hypnotisml.lisp
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2024-11-28 08:18:30 -0800
committercolin <colin@cicadas.surf>2024-11-28 08:18:30 -0800
commita2e97a1a16807858b9743ba42043e978297b0bb5 (patch)
tree4a6223ce0aed1838f7a59ed8f34651a87ab1444c /src/hypnotisml.lisp
parent17647db69cb8451009d338c01304d525b647d447 (diff)
Only generate data-ids for elements that need them
Diffstat (limited to 'src/hypnotisml.lisp')
-rw-r--r--src/hypnotisml.lisp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/hypnotisml.lisp b/src/hypnotisml.lisp
index fdc1e9e..e63f43b 100644
--- a/src/hypnotisml.lisp
+++ b/src/hypnotisml.lisp
@@ -77,10 +77,10 @@
:type keyword
:initform (error 'tag-required)
:documentation "HTML tag.")
- (id :prefix :ro :noarg
- :type string
- :initform (make-uid)
- :documentation "A unique id, because id attribute.")
+ (id :prefix :noarg
+ :type (or null string)
+ :initform nil
+ :documentation "A unique id, because id attribute.")
(style attributes
:prefix
:initform nil)
@@ -115,6 +115,8 @@
(defun elem-query-selector (elem)
"Returns a CSS query selector string for the ELEM. ELEMs can be
uniquely quried in the dom by passing string to .querySelector()"
+ (unless (elem-id elem)
+ (setf (elem-id elem) (make-uid)))
(format nil "[data-hypno-id='~a']" (elem-id elem)))
(defun style (elem property)
@@ -303,7 +305,9 @@ already present in the element."
(*print-case* :downcase))
(indent stream)
(with-slots (attributes style tag children id) elem
- (format t "<~a data-hypno-id=~s" tag id)
+ (if id
+ (format t "<~a data-hypno-id=~s" tag id)
+ (format t "<~a" tag))
(when (and attributes (attribs-list attributes))
(format t " ~{~a=~s~^ ~}"
(attribs-list attributes)))
@@ -630,6 +634,8 @@ E.g. :1/2, :1, :3/4"
`(ps:chain document (query-selector (ps:lisp (elem-query-selector ,elem)))))
(ps:defpsmacro <elem> (elem)
+ "Generate Parenscript to get the DOM Node corresponding to an in-page
+rendered HYPNOTISML ELEMENT instance."
`(ps:chain document (query-selector (ps:lisp (elem-query-selector ,elem)))))