Rename class names

This commit is contained in:
paku 2024-05-28 20:48:39 +09:00
parent ab1d321cab
commit e4c0e0f597
4 changed files with 24 additions and 24 deletions

View file

@ -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
<>)

View file

@ -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 "<!DOCTYPE html>~%")
(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

View file

@ -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"

View file

@ -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"))