fix core test; web/dom: provide rendering of self closing (empty) element
This commit is contained in:
parent
a43de69210
commit
473616860f
2 changed files with 24 additions and 22 deletions
|
@ -61,8 +61,6 @@
|
||||||
(t:show-result))))
|
(t:show-result))))
|
||||||
|
|
||||||
(deftest test-util ()
|
(deftest test-util ()
|
||||||
(== (util:trunc "hello world" 5) "hello...")
|
|
||||||
(== (util:trunc "hello world" 11) "hello world")
|
|
||||||
(== (util:to-keyword "hello-kitty") :hello-kitty))
|
(== (util:to-keyword "hello-kitty") :hello-kitty))
|
||||||
|
|
||||||
(deftest test-send ()
|
(deftest test-send ()
|
||||||
|
|
42
web/dom.lisp
42
web/dom.lisp
|
@ -17,12 +17,11 @@
|
||||||
|
|
||||||
(defclass element ()
|
(defclass element ()
|
||||||
((tag :reader tag :initarg :tag)
|
((tag :reader tag :initarg :tag)
|
||||||
(attrs :reader attrs :initarg :attrs)
|
(attrs :reader attrs :initarg :attrs :initform nil)
|
||||||
(body :reader body :initarg :body)))
|
(body :reader body :initarg :body :initform nil)))
|
||||||
|
|
||||||
(defun elem (tag attrs body)
|
(defun elem (tag &optional attrs body)
|
||||||
(make-instance 'element :tag (string-downcase tag)
|
(make-instance 'element :tag tag :attrs attrs :body body))
|
||||||
:attrs attrs :body body))
|
|
||||||
|
|
||||||
(defun element (tag attrs &rest body)
|
(defun element (tag attrs &rest body)
|
||||||
(elem tag attrs body))
|
(elem tag attrs body))
|
||||||
|
@ -31,10 +30,13 @@
|
||||||
(format stream "<~a ~s>~s" (tag el) (attrs el) (body el)))
|
(format stream "<~a ~s>~s" (tag el) (attrs el) (body el)))
|
||||||
|
|
||||||
(defmethod put ((el element))
|
(defmethod put ((el element))
|
||||||
(start (tag el) (attrs el))
|
(let ((tag (string-downcase (tag el)))
|
||||||
(dolist (c (body el))
|
(body (body el)))
|
||||||
|
(start tag (attrs el) :close (not body))
|
||||||
|
(when body
|
||||||
|
(dolist (c body)
|
||||||
(put c))
|
(put c))
|
||||||
(end (tag el)))
|
(end tag))))
|
||||||
|
|
||||||
;;;; elements with specific functionality
|
;;;; elements with specific functionality
|
||||||
|
|
||||||
|
@ -58,6 +60,19 @@
|
||||||
(put el))
|
(put el))
|
||||||
(get-output-stream-string *output*)))
|
(get-output-stream-string *output*)))
|
||||||
|
|
||||||
|
(defun start (tag attrs &key close)
|
||||||
|
(put-char #\<)
|
||||||
|
(put-string tag)
|
||||||
|
(put-attrs attrs)
|
||||||
|
(if close
|
||||||
|
(put-char #\/))
|
||||||
|
(put-char #\>))
|
||||||
|
|
||||||
|
(defun end (tag)
|
||||||
|
(put-string "</")
|
||||||
|
(put-string tag)
|
||||||
|
(put-char #\>))
|
||||||
|
|
||||||
(defun put-string (s)
|
(defun put-string (s)
|
||||||
(write-string s *output*))
|
(write-string s *output*))
|
||||||
|
|
||||||
|
@ -79,17 +94,6 @@
|
||||||
((:id :class) (util:to-string val :lower-case t))
|
((:id :class) (util:to-string val :lower-case t))
|
||||||
(t (util:to-string val))))
|
(t (util:to-string val))))
|
||||||
|
|
||||||
(defun start (tag &optional attrs)
|
|
||||||
(put-char #\<)
|
|
||||||
(put-string tag)
|
|
||||||
(put-attrs attrs)
|
|
||||||
(put-char #\>))
|
|
||||||
|
|
||||||
(defun end (tag)
|
|
||||||
(put-string "</")
|
|
||||||
(put-string tag)
|
|
||||||
(put-char #\>))
|
|
||||||
|
|
||||||
(defun newline ()
|
(defun newline ()
|
||||||
(put-char #\Newline))
|
(put-char #\Newline))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue