diff options
Diffstat (limited to 'src/hypnotisml.lisp')
-rw-r--r-- | src/hypnotisml.lisp | 16 |
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))))) |