Rename class names
This commit is contained in:
parent
ab1d321cab
commit
e4c0e0f597
4 changed files with 24 additions and 24 deletions
|
@ -13,7 +13,7 @@
|
||||||
names)))
|
names)))
|
||||||
|
|
||||||
(define-and-export-builtin-elements
|
(define-and-export-builtin-elements
|
||||||
; tag-elements
|
; tags
|
||||||
a abbr address area article aside audio b base bdi bdo blockquote
|
a abbr address area article aside audio b base bdi bdo blockquote
|
||||||
body br button canvas caption cite code col colgroup data datalist
|
body br button canvas caption cite code col colgroup data datalist
|
||||||
dd del details dfn dialog div dl dt em embed fieldset figcaption
|
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
|
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
|
style sub summary sup svg table tbody td template textarea tfoot th
|
||||||
thead |time| title tr track u ul var video wbr
|
thead |time| title tr track u ul var video wbr
|
||||||
; html-tag-element
|
; html-tag
|
||||||
html
|
html
|
||||||
; fragment-element
|
; fragment
|
||||||
<>)
|
<>)
|
||||||
|
|
|
@ -21,22 +21,22 @@
|
||||||
:reader element-children
|
:reader element-children
|
||||||
:initarg :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
|
;;;; factory
|
||||||
|
|
||||||
(defun create-element (type props &rest children)
|
(defun create-element (type props &rest children)
|
||||||
(let ((elm (make-instance (cond ((functionp type) 'component-element)
|
(let ((elm (make-instance (cond ((functionp type) 'component)
|
||||||
((eq type :<>) 'fragment-element)
|
((eq type :<>) 'fragment)
|
||||||
((eq type :html) 'html-tag-element)
|
((eq type :html) 'html-tag)
|
||||||
((keywordp type) 'tag-element)
|
((keywordp type) 'tag)
|
||||||
(t (error "element-type must be either a keyword or a function.")))
|
(t (error "element-type must be either a keyword or a function.")))
|
||||||
:type type
|
:type type
|
||||||
:props props
|
:props props
|
||||||
|
@ -55,18 +55,18 @@
|
||||||
|
|
||||||
(defmethod create-element-hook ((elm element)))
|
(defmethod create-element-hook ((elm element)))
|
||||||
|
|
||||||
(defmethod create-element-hook ((elm fragment-element))
|
(defmethod create-element-hook ((elm fragment))
|
||||||
(when (element-props elm)
|
(when (element-props elm)
|
||||||
(error "Cannot pass props to fragment.")))
|
(error "Cannot pass props to fragment.")))
|
||||||
|
|
||||||
(defmethod create-element-hook ((elm component-element))
|
(defmethod create-element-hook ((elm component))
|
||||||
;dry-run to validate props
|
;dry-run to validate props
|
||||||
(expand-component elm))
|
(expand-component elm))
|
||||||
|
|
||||||
|
|
||||||
;;;; methods
|
;;;; methods
|
||||||
|
|
||||||
(defmethod print-object ((elm tag-element) stream)
|
(defmethod print-object ((elm tag) stream)
|
||||||
(with-accessors ((type element-type)
|
(with-accessors ((type element-type)
|
||||||
(props element-props)
|
(props element-props)
|
||||||
(children element-children)) elm
|
(children element-children)) elm
|
||||||
|
@ -94,11 +94,11 @@
|
||||||
(string-downcase key)
|
(string-downcase key)
|
||||||
value))))
|
value))))
|
||||||
|
|
||||||
(defmethod print-object ((elm html-tag-element) stream)
|
(defmethod print-object ((elm html-tag) stream)
|
||||||
(format stream "<!DOCTYPE html>~%")
|
(format stream "<!DOCTYPE html>~%")
|
||||||
(call-next-method))
|
(call-next-method))
|
||||||
|
|
||||||
(defmethod print-object ((elm fragment-element) stream)
|
(defmethod print-object ((elm fragment) stream)
|
||||||
(with-accessors ((children element-children)) elm
|
(with-accessors ((children element-children)) elm
|
||||||
(if children
|
(if children
|
||||||
(format stream (if (rest children)
|
(format stream (if (rest children)
|
||||||
|
@ -106,10 +106,10 @@
|
||||||
"~<~a~:>")
|
"~<~a~:>")
|
||||||
children))))
|
children))))
|
||||||
|
|
||||||
(defmethod print-object ((elm component-element) stream)
|
(defmethod print-object ((elm component) stream)
|
||||||
(print-object (expand-component elm) stream))
|
(print-object (expand-component elm) stream))
|
||||||
|
|
||||||
(defmethod expand-component ((elm component-element))
|
(defmethod expand-component ((elm component))
|
||||||
(with-accessors ((type element-type)
|
(with-accessors ((type element-type)
|
||||||
(props element-props)
|
(props element-props)
|
||||||
(children element-children)) elm
|
(children element-children)) elm
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
(deftag custom)
|
(deftag custom)
|
||||||
|
|
||||||
(test hsx-for-custom-tag-element
|
(test hsx-for-custom-tag
|
||||||
(is (equal (macroexpand-1
|
(is (equal (macroexpand-1
|
||||||
'(custom :prop1 "value1" :prop2 "value2"
|
'(custom :prop1 "value1" :prop2 "value2"
|
||||||
"child1"
|
"child1"
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
(defcomp comp (&key prop1 prop2 children)
|
(defcomp comp (&key prop1 prop2 children)
|
||||||
(declare (ignore prop1 prop2 children)))
|
(declare (ignore prop1 prop2 children)))
|
||||||
|
|
||||||
(test hsx-for-component-element
|
(test hsx-for-component
|
||||||
(is (equal (macroexpand-1
|
(is (equal (macroexpand-1
|
||||||
'(comp :prop1 "value1" :prop2 "value2"
|
'(comp :prop1 "value1" :prop2 "value2"
|
||||||
"child1"
|
"child1"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(def-suite element-test)
|
(def-suite element-test)
|
||||||
(in-suite element-test)
|
(in-suite element-test)
|
||||||
|
|
||||||
(test tag-element
|
(test tag
|
||||||
(let ((elm (create-element :p
|
(let ((elm (create-element :p
|
||||||
'(:class "red")
|
'(:class "red")
|
||||||
"Hello,"
|
"Hello,"
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
title
|
title
|
||||||
children))
|
children))
|
||||||
|
|
||||||
(test component-elment-with-keyword-args
|
(test component-accepting-keyword-args
|
||||||
(let* ((elm (create-element #'comp1
|
(let* ((elm (create-element #'comp1
|
||||||
'(:title "foo")
|
'(:title "foo")
|
||||||
"bar"))
|
"bar"))
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
(getf props :title)
|
(getf props :title)
|
||||||
(getf props :children)))
|
(getf props :children)))
|
||||||
|
|
||||||
(test component-element-with-property-list
|
(test component-accepting-property-list
|
||||||
(let* ((elm (create-element #'comp2
|
(let* ((elm (create-element #'comp2
|
||||||
'(:title "foo")
|
'(:title "foo")
|
||||||
"bar"))
|
"bar"))
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
children
|
children
|
||||||
(getf props :other-key)))
|
(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
|
(let* ((elm (create-element #'comp3
|
||||||
'(:title "foo" :other-key "baz")
|
'(:title "foo" :other-key "baz")
|
||||||
"bar"))
|
"bar"))
|
||||||
|
|
Loading…
Reference in a new issue