Skip to content

Commit

Permalink
Merge hsx/group into hsx/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
skyizwhite committed Oct 3, 2024
1 parent b430b42 commit 8c539dc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 50 deletions.
1 change: 0 additions & 1 deletion hsx-test.asd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
:depends-on ("rove"
"hsx-test/utils"
"hsx-test/element"
"hsx-test/group"
"hsx-test/hsx")
:perform (test-op (o c) (symbol-call :rove :run c :style :dot)))
13 changes: 10 additions & 3 deletions src/element.lisp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ()
Expand Down
30 changes: 0 additions & 30 deletions src/group.lisp

This file was deleted.

22 changes: 20 additions & 2 deletions src/utils.lisp
Original file line number Diff line number Diff line change
@@ -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*
Expand Down Expand Up @@ -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)))))
14 changes: 0 additions & 14 deletions tests/group.lisp

This file was deleted.

16 changes: 16 additions & 0 deletions tests/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@
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))))

0 comments on commit 8c539dc

Please sign in to comment.