diff --git a/src/hsx.lisp b/src/hsx.lisp index 3b3bf08..1ba7a5c 100644 --- a/src/hsx.lisp +++ b/src/hsx.lisp @@ -5,27 +5,26 @@ #:make-keyword) (:import-from #:hsx/element #:create-element) - (:export #:defcomp + (:export #:defhsx + #:defcomp #:hsx)) (in-package #:hsx/hsx) ;;;; hsx definitions -(defparameter *builtin-elements* (make-hash-table)) - -(defmacro define-builtin-element (name) +(defmacro defhsx (name element-type) `(defmacro ,name (&body body) (multiple-value-bind (props children) (parse-body body) - `(create-element ,',(string-downcase name) - (list ,@props) - ,@children)))) + `(create-element ,',element-type (list ,@props) ,@children)))) + +(defparameter *builtin-elements* (make-hash-table)) (defmacro define-and-export-builtin-elements (&body names) `(progn ,@(mapcan (lambda (name) - (list `(define-builtin-element ,name) + (list `(defhsx ,name ,(string-downcase name)) `(setf (gethash (make-keyword ',name) *builtin-elements*) t) `(export ',name))) names))) @@ -51,12 +50,7 @@ `(eval-when (:compile-toplevel :load-toplevel :execute) (defun ,%name ,props ,@body) - (defmacro ,name (&body body) - (multiple-value-bind (props children) - (parse-body body) - `(create-element #',',%name - (list ,@props) - ,@children)))))) + (defhsx ,name (fdefinition ',%name))))) (defun parse-body (body) (if (keywordp (first body)) diff --git a/tests/hsx.lisp b/tests/hsx.lisp index 2d0c6da..7cfe79e 100644 --- a/tests/hsx.lisp +++ b/tests/hsx.lisp @@ -8,6 +8,7 @@ (def-suite hsx-test) (in-suite hsx-test) + (test empty-hsx (is (equal (macroexpand-1 '(div)) @@ -44,16 +45,42 @@ "child1" "child2")))) -(defcomp comp (&key prop1 prop2 children) - (declare (ignore prop1 prop2 children))) +(defhsx custom "custom") -(test component-hsx +(test hsx-for-custom-tag-element (is (equal (macroexpand-1 - '(comp :prop1 "value1" :prop2 "value2" + '(custom :prop1 "value1" :prop2 "value2" "child1" "child2")) '(create-element - #'%comp + "custom" + (list :prop1 "value1" :prop2 "value2") + "child1" + "child2")))) + +(defun %comp1 (&key prop1 prop2 children) + (declare (ignore prop1 prop2 children))) +(defhsx comp1 #'%comp1) + +(defcomp comp2 (&key prop1 prop2 children) + (declare (ignore prop1 prop2 children))) + +(test hsx-for-component-element + (is (equal (macroexpand-1 + '(comp1 :prop1 "value1" :prop2 "value2" + "child1" + "child2")) + '(create-element + #'%comp1 + (list :prop1 "value1" :prop2 "value2") + "child1" + "child2"))) + (is (equal (macroexpand-1 + '(comp2 :prop1 "value1" :prop2 "value2" + "child1" + "child2")) + '(create-element + (fdefinition '%comp2) (list :prop1 "value1" :prop2 "value2") "child1" "child2"))))