Merge hsx/group into hsx/utils
This commit is contained in:
parent
b430b42699
commit
8c539dc879
6 changed files with 46 additions and 50 deletions
|
@ -1,12 +1,10 @@
|
|||
(defpackage #:hsx/element
|
||||
(:use #:cl)
|
||||
(:import-from #:hsx/utils
|
||||
#:defgroup
|
||||
#:escape-html-attribute
|
||||
#:escape-html-text-content
|
||||
#:minify)
|
||||
(:import-from #:hsx/group
|
||||
#:self-closing-tag-p
|
||||
#:non-escaping-tag-p)
|
||||
(:export #:element
|
||||
#:tag
|
||||
#:html-tag
|
||||
|
@ -22,6 +20,15 @@
|
|||
#:render-to-string))
|
||||
(in-package #:hsx/element)
|
||||
|
||||
;;; tag group definitions
|
||||
|
||||
(defgroup self-closing-tag
|
||||
area base br col embed hr img input
|
||||
link meta param source track wbr)
|
||||
|
||||
(defgroup non-escaping-tag
|
||||
script style)
|
||||
|
||||
;;;; class definitions
|
||||
|
||||
(defclass element ()
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
(defpackage #:hsx/group
|
||||
(:use #:cl)
|
||||
(:import-from #:alexandria
|
||||
#:make-keyword
|
||||
#:symbolicate)
|
||||
(:export #:defgroup
|
||||
#:self-closing-tag-p
|
||||
#:non-escaping-tag-p))
|
||||
(in-package #:hsx/group)
|
||||
|
||||
(defun make-keyword-hash-table (symbols)
|
||||
(let ((ht (make-hash-table)))
|
||||
(mapcar (lambda (sym)
|
||||
(setf (gethash (make-keyword sym) ht) t))
|
||||
symbols)
|
||||
ht))
|
||||
|
||||
(defmacro defgroup (name &body symbols)
|
||||
(let ((p-name (symbolicate '* name '*)))
|
||||
`(progn
|
||||
(defparameter ,p-name (make-keyword-hash-table ',symbols))
|
||||
(defun ,(symbolicate name '-p) (keyword)
|
||||
(gethash keyword ,p-name)))))
|
||||
|
||||
(defgroup self-closing-tag
|
||||
area base br col embed hr img input
|
||||
link meta param source track wbr)
|
||||
|
||||
(defgroup non-escaping-tag
|
||||
script style)
|
|
@ -1,10 +1,13 @@
|
|||
(defpackage #:hsx/utils
|
||||
(:use #:cl)
|
||||
(:import-from #:alexandria
|
||||
#:alist-hash-table)
|
||||
#:alist-hash-table
|
||||
#:make-keyword
|
||||
#:symbolicate)
|
||||
(:export #:escape-html-attribute
|
||||
#:escape-html-text-content
|
||||
#:minify))
|
||||
#:minify
|
||||
#:defgroup))
|
||||
(in-package #:hsx/utils)
|
||||
|
||||
(defparameter *text-content-escape-map*
|
||||
|
@ -55,3 +58,18 @@
|
|||
|
||||
(defun whitespace-p (char)
|
||||
(member char '(#\Space #\Newline #\Tab #\Return) :test #'char=))
|
||||
|
||||
(defun make-keyword-hash-table (symbols)
|
||||
(let ((ht (make-hash-table)))
|
||||
(mapcar (lambda (sym)
|
||||
(setf (gethash (make-keyword sym) ht) t))
|
||||
symbols)
|
||||
ht))
|
||||
|
||||
(defmacro defgroup (name &body symbols)
|
||||
(let ((param-name (symbolicate '* name '*))
|
||||
(pred-name (symbolicate name '-p)))
|
||||
`(progn
|
||||
(defparameter ,param-name (make-keyword-hash-table ',symbols))
|
||||
(defun ,pred-name (keyword)
|
||||
(gethash keyword ,param-name)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue