Add hsx/builtin package
This commit is contained in:
parent
145c01a7c4
commit
7a697a1c05
4 changed files with 46 additions and 45 deletions
33
src/builtin.lisp
Normal file
33
src/builtin.lisp
Normal file
|
@ -0,0 +1,33 @@
|
|||
(uiop:define-package #:hsx/builtin
|
||||
(:use #:cl)
|
||||
(:import-from #:alexandria
|
||||
#:make-keyword)
|
||||
(:import-from #:hsx/hsx
|
||||
#:defhsx))
|
||||
(in-package #:hsx/builtin)
|
||||
|
||||
(defparameter *builtin-elements* (make-hash-table))
|
||||
|
||||
(defmacro define-and-export-builtin-elements (&rest names)
|
||||
`(progn
|
||||
,@(mapcan (lambda (name)
|
||||
(list `(defhsx ,name ,(string-downcase name))
|
||||
`(setf (gethash (make-keyword ',name) *builtin-elements*) t)
|
||||
`(export ',name)))
|
||||
names)))
|
||||
|
||||
(define-and-export-builtin-elements
|
||||
; tag-elements
|
||||
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
|
||||
figure footer form h1 h2 h3 h4 h5 h6 head header hr i iframe
|
||||
img input ins kbd label legend li link main |map| mark meta meter nav
|
||||
noscript object ol optgroup option output p param picture pre progress
|
||||
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
|
||||
; fragment-element
|
||||
<>)
|
52
src/hsx.lisp
52
src/hsx.lisp
|
@ -1,8 +1,7 @@
|
|||
(uiop:define-package #:hsx/hsx
|
||||
(:use #:cl)
|
||||
(:import-from #:alexandria
|
||||
#:symbolicate
|
||||
#:make-keyword)
|
||||
#:symbolicate)
|
||||
(:import-from #:hsx/element
|
||||
#:create-element)
|
||||
(:export #:defhsx
|
||||
|
@ -30,32 +29,6 @@
|
|||
:finally (return (values props nil)))
|
||||
(values nil body)))
|
||||
|
||||
(defparameter *builtin-elements* (make-hash-table))
|
||||
|
||||
(defmacro define-and-export-builtin-elements (&rest names)
|
||||
`(progn
|
||||
,@(mapcan (lambda (name)
|
||||
(list `(defhsx ,name ,(string-downcase name))
|
||||
`(setf (gethash (make-keyword ',name) *builtin-elements*) t)
|
||||
`(export ',name)))
|
||||
names)))
|
||||
|
||||
(define-and-export-builtin-elements
|
||||
; tag-elements
|
||||
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
|
||||
figure footer form h1 h2 h3 h4 h5 h6 head header hr i iframe
|
||||
img input ins kbd label legend li link main |map| mark meta meter nav
|
||||
noscript object ol optgroup option output p param picture pre progress
|
||||
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
|
||||
; fragment-element
|
||||
<>)
|
||||
|
||||
(defmacro defcomp (name props &body body)
|
||||
(let ((%name (symbolicate '% name)))
|
||||
`(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
|
@ -67,26 +40,17 @@
|
|||
;;;; hsx macro to find hsx symbols
|
||||
|
||||
(defmacro hsx (form)
|
||||
(modify-first-of-lists form
|
||||
#'builtin-element-p
|
||||
(lambda (node)
|
||||
(find-symbol (string node) :hsx/hsx))))
|
||||
(find-builtin-symbols form))
|
||||
|
||||
(defun modify-first-of-lists (tree test result)
|
||||
(defun find-builtin-symbols (tree)
|
||||
(if tree
|
||||
(cons (let ((first-node (first tree)))
|
||||
(cond
|
||||
((listp first-node)
|
||||
(modify-first-of-lists first-node test result))
|
||||
((funcall test first-node)
|
||||
(funcall result first-node))
|
||||
(t first-node)))
|
||||
(if (listp first-node)
|
||||
(find-builtin-symbols first-node)
|
||||
(or (find-symbol (string first-node) :hsx/builtin)
|
||||
first-node)))
|
||||
(mapcar (lambda (node)
|
||||
(if (listp node)
|
||||
(modify-first-of-lists node test result)
|
||||
(find-builtin-symbols node)
|
||||
node))
|
||||
(rest tree)))))
|
||||
|
||||
(defun builtin-element-p (node)
|
||||
(and (symbolp node)
|
||||
(gethash (make-keyword node) *builtin-elements*)))
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
(defpackage :hsx
|
||||
(:nicknames #:hsx/main)
|
||||
(:import-from #:hsx/element)
|
||||
(:import-from #:hsx/hsx)
|
||||
(:import-from #:hsx/builtin)
|
||||
(:use #:cl))
|
||||
(in-package :hsx)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(defpackage #:hsx-test/hsx
|
||||
(:use #:cl
|
||||
#:fiveam
|
||||
#:hsx/hsx)
|
||||
#:hsx/hsx
|
||||
#:hsx/builtin)
|
||||
(:import-from #:hsx/element
|
||||
#:create-element))
|
||||
(in-package #:hsx-test/hsx)
|
||||
|
|
Loading…
Reference in a new issue