Merge hsx/group into hsx/utils
This commit is contained in:
parent
b430b42699
commit
8c539dc879
6 changed files with 46 additions and 50 deletions
|
@ -4,6 +4,5 @@
|
||||||
:depends-on ("rove"
|
:depends-on ("rove"
|
||||||
"hsx-test/utils"
|
"hsx-test/utils"
|
||||||
"hsx-test/element"
|
"hsx-test/element"
|
||||||
"hsx-test/group"
|
|
||||||
"hsx-test/hsx")
|
"hsx-test/hsx")
|
||||||
:perform (test-op (o c) (symbol-call :rove :run c :style :dot)))
|
:perform (test-op (o c) (symbol-call :rove :run c :style :dot)))
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
(defpackage #:hsx/element
|
(defpackage #:hsx/element
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:import-from #:hsx/utils
|
(:import-from #:hsx/utils
|
||||||
|
#:defgroup
|
||||||
#:escape-html-attribute
|
#:escape-html-attribute
|
||||||
#:escape-html-text-content
|
#:escape-html-text-content
|
||||||
#:minify)
|
#:minify)
|
||||||
(:import-from #:hsx/group
|
|
||||||
#:self-closing-tag-p
|
|
||||||
#:non-escaping-tag-p)
|
|
||||||
(:export #:element
|
(:export #:element
|
||||||
#:tag
|
#:tag
|
||||||
#:html-tag
|
#:html-tag
|
||||||
|
@ -22,6 +20,15 @@
|
||||||
#:render-to-string))
|
#:render-to-string))
|
||||||
(in-package #:hsx/element)
|
(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
|
;;;; class definitions
|
||||||
|
|
||||||
(defclass element ()
|
(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
|
(defpackage #:hsx/utils
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:import-from #:alexandria
|
(:import-from #:alexandria
|
||||||
#:alist-hash-table)
|
#:alist-hash-table
|
||||||
|
#:make-keyword
|
||||||
|
#:symbolicate)
|
||||||
(:export #:escape-html-attribute
|
(:export #:escape-html-attribute
|
||||||
#:escape-html-text-content
|
#:escape-html-text-content
|
||||||
#:minify))
|
#:minify
|
||||||
|
#:defgroup))
|
||||||
(in-package #:hsx/utils)
|
(in-package #:hsx/utils)
|
||||||
|
|
||||||
(defparameter *text-content-escape-map*
|
(defparameter *text-content-escape-map*
|
||||||
|
@ -55,3 +58,18 @@
|
||||||
|
|
||||||
(defun whitespace-p (char)
|
(defun whitespace-p (char)
|
||||||
(member char '(#\Space #\Newline #\Tab #\Return) :test #'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)))))
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
(defpackage #:hsx-test/group
|
|
||||||
(:use #:cl
|
|
||||||
#:rove
|
|
||||||
#:hsx/group))
|
|
||||||
(in-package #:hsx-test/group)
|
|
||||||
|
|
||||||
(defgroup fruit
|
|
||||||
apple banana orange)
|
|
||||||
|
|
||||||
(deftest group-test
|
|
||||||
(testing "defgroup"
|
|
||||||
(ok (hash-table-p *fruit*))
|
|
||||||
(ok (fruit-p :apple))
|
|
||||||
(ng (fruit-p :tomato))))
|
|
|
@ -21,3 +21,19 @@
|
||||||
toggle() { this.open = ! this.open },
|
toggle() { this.open = ! this.open },
|
||||||
}")
|
}")
|
||||||
"{ open: false, get isOpen() { return this.open }, toggle() { this.open = ! this.open }, }"))))
|
"{ open: false, get isOpen() { return this.open }, toggle() { this.open = ! this.open }, }"))))
|
||||||
|
|
||||||
|
(defgroup fruit
|
||||||
|
apple banana)
|
||||||
|
|
||||||
|
(deftest group-util-test
|
||||||
|
(testing "defgroup"
|
||||||
|
(ok (expands '(defgroup fruit apple banana)
|
||||||
|
'(progn
|
||||||
|
(defparameter *fruit*
|
||||||
|
(hsx/utils::make-keyword-hash-table '(apple banana)))
|
||||||
|
(defun fruit-p (keyword)
|
||||||
|
(gethash keyword *fruit*)))))
|
||||||
|
(ok (hash-table-p *fruit*))
|
||||||
|
(ok (fboundp 'fruit-p))
|
||||||
|
(ok (fruit-p :apple))
|
||||||
|
(ng (fruit-p :tomato))))
|
||||||
|
|
Loading…
Reference in a new issue