diff --git a/src/builtin.lisp b/src/builtin.lisp index 61779a2..931e8bb 100644 --- a/src/builtin.lisp +++ b/src/builtin.lisp @@ -13,7 +13,7 @@ names))) (define-and-export-builtin-elements - ; tag-elements + ; tags a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption @@ -23,7 +23,7 @@ q rp rt ruby s samp script section select small source span strong style sub summary sup svg table tbody td template textarea tfoot th thead |time| title tr track u ul var video wbr - ; html-tag-element + ; html-tag html - ; fragment-element + ; fragment <>) diff --git a/src/element.lisp b/src/element.lisp index b7896c6..748ae04 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -21,22 +21,22 @@ :reader element-children :initarg :children))) -(defclass tag-element (element) ()) +(defclass tag (element) ()) -(defclass html-tag-element (tag-element) ()) +(defclass html-tag (tag) ()) -(defclass fragment-element (element) ()) +(defclass fragment (element) ()) -(defclass component-element (element) ()) +(defclass component (element) ()) ;;;; factory (defun create-element (type props &rest children) - (let ((elm (make-instance (cond ((functionp type) 'component-element) - ((eq type :<>) 'fragment-element) - ((eq type :html) 'html-tag-element) - ((keywordp type) 'tag-element) + (let ((elm (make-instance (cond ((functionp type) 'component) + ((eq type :<>) 'fragment) + ((eq type :html) 'html-tag) + ((keywordp type) 'tag) (t (error "element-type must be either a keyword or a function."))) :type type :props props @@ -55,18 +55,18 @@ (defmethod create-element-hook ((elm element))) -(defmethod create-element-hook ((elm fragment-element)) +(defmethod create-element-hook ((elm fragment)) (when (element-props elm) (error "Cannot pass props to fragment."))) -(defmethod create-element-hook ((elm component-element)) +(defmethod create-element-hook ((elm component)) ;dry-run to validate props (expand-component elm)) ;;;; methods -(defmethod print-object ((elm tag-element) stream) +(defmethod print-object ((elm tag) stream) (with-accessors ((type element-type) (props element-props) (children element-children)) elm @@ -94,11 +94,11 @@ (string-downcase key) value)))) -(defmethod print-object ((elm html-tag-element) stream) +(defmethod print-object ((elm html-tag) stream) (format stream "~%") (call-next-method)) -(defmethod print-object ((elm fragment-element) stream) +(defmethod print-object ((elm fragment) stream) (with-accessors ((children element-children)) elm (if children (format stream (if (rest children) @@ -106,10 +106,10 @@ "~<~a~:>") children)))) -(defmethod print-object ((elm component-element) stream) +(defmethod print-object ((elm component) stream) (print-object (expand-component elm) stream)) -(defmethod expand-component ((elm component-element)) +(defmethod expand-component ((elm component)) (with-accessors ((type element-type) (props element-props) (children element-children)) elm diff --git a/tests/defhsx.lisp b/tests/defhsx.lisp index 38edc98..a134230 100644 --- a/tests/defhsx.lisp +++ b/tests/defhsx.lisp @@ -49,7 +49,7 @@ (deftag custom) -(test hsx-for-custom-tag-element +(test hsx-for-custom-tag (is (equal (macroexpand-1 '(custom :prop1 "value1" :prop2 "value2" "child1" @@ -63,7 +63,7 @@ (defcomp comp (&key prop1 prop2 children) (declare (ignore prop1 prop2 children))) -(test hsx-for-component-element +(test hsx-for-component (is (equal (macroexpand-1 '(comp :prop1 "value1" :prop2 "value2" "child1" diff --git a/tests/element.lisp b/tests/element.lisp index 51ab77c..ee04fe0 100644 --- a/tests/element.lisp +++ b/tests/element.lisp @@ -8,7 +8,7 @@ (def-suite element-test) (in-suite element-test) -(test tag-element +(test tag (let ((elm (create-element :p '(:class "red") "Hello," @@ -32,7 +32,7 @@ title children)) -(test component-elment-with-keyword-args +(test component-accepting-keyword-args (let* ((elm (create-element #'comp1 '(:title "foo") "bar")) @@ -53,7 +53,7 @@ (getf props :title) (getf props :children))) -(test component-element-with-property-list +(test component-accepting-property-list (let* ((elm (create-element #'comp2 '(:title "foo") "bar")) @@ -78,7 +78,7 @@ children (getf props :other-key))) -(test component-element-with-keyword-args-and-property-list +(test component-accepting-keyword-args-and-property-list (let* ((elm (create-element #'comp3 '(:title "foo" :other-key "baz") "bar"))