Use cl-str instead

This commit is contained in:
paku 2024-10-04 08:44:27 +09:00
parent 53a6a8f50e
commit 7ce7751900
6 changed files with 26 additions and 34 deletions

4
qlfile
View file

@ -1,4 +1,6 @@
ql alexandria ql alexandria
ql mstrings ql cl-str
github rove fukamachi/rove github rove fukamachi/rove
github dissect Shinmera/dissect ; workaround github dissect Shinmera/dissect ; workaround
ql mstrings

View file

@ -6,7 +6,7 @@
(:class qlot/source/ql:source-ql (:class qlot/source/ql:source-ql
:initargs (:%version :latest) :initargs (:%version :latest)
:version "ql-2023-10-21")) :version "ql-2023-10-21"))
("mstrings" . ("cl-str" .
(:class qlot/source/ql:source-ql (:class qlot/source/ql:source-ql
:initargs (:%version :latest) :initargs (:%version :latest)
:version "ql-2023-10-21")) :version "ql-2023-10-21"))
@ -18,3 +18,7 @@
(:class qlot/source/github:source-github (:class qlot/source/github:source-github
:initargs (:repos "Shinmera/dissect" :ref nil :branch nil :tag nil) :initargs (:repos "Shinmera/dissect" :ref nil :branch nil :tag nil)
:version "github-a70cabcd748cf7c041196efd711e2dcca2bbbb2c")) :version "github-a70cabcd748cf7c041196efd711e2dcca2bbbb2c"))
("mstrings" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))

View file

@ -1,10 +1,11 @@
(defpackage #:hsx/element (defpackage #:hsx/element
(:use #:cl) (:use #:cl)
(:import-from #:str
#:collapse-whitespaces)
(:import-from #:hsx/utils (:import-from #:hsx/utils
#:defgroup #:defgroup
#:escape-html-attribute #:escape-html-attribute
#:escape-html-text-content #:escape-html-text-content)
#:minify)
(:export #:element (:export #:element
#:tag #:tag
#:html-tag #:html-tag
@ -126,7 +127,7 @@
(string-downcase (element-type element))) (string-downcase (element-type element)))
(defmethod render-props ((element tag)) (defmethod render-props ((element tag))
(minify (collapse-whitespaces
(with-output-to-string (stream) (with-output-to-string (stream)
(loop (loop
:for (key value) :on (element-props element) :by #'cddr :for (key value) :on (element-props element) :by #'cddr

View file

@ -6,7 +6,6 @@
#:symbolicate) #:symbolicate)
(:export #:escape-html-attribute (:export #:escape-html-attribute
#:escape-html-text-content #:escape-html-text-content
#:minify
#:defgroup)) #:defgroup))
(in-package #:hsx/utils) (in-package #:hsx/utils)
@ -43,23 +42,6 @@
(defun escape-html-attribute (str) (defun escape-html-attribute (str)
(escape-string str *attribute-escape-map*)) (escape-string str *attribute-escape-map*))
(defun minify (str)
(with-output-to-string (out)
(let ((previous-space-p nil))
(loop
:for char :across str
:do (cond
((whitespace-p char)
(unless previous-space-p
(write-char #\Space out))
(setf previous-space-p t))
(t
(write-char char out)
(setf previous-space-p nil)))))))
(defun whitespace-p (char)
(member char '(#\Space #\Newline #\Tab #\Return) :test #'char=))
(defun make-keyword-hash-table (symbols) (defun make-keyword-hash-table (symbols)
(let ((ht (make-hash-table))) (let ((ht (make-hash-table)))
(mapcar (lambda (sym) (mapcar (lambda (sym)

View file

@ -89,6 +89,7 @@
nil nil
"bar"))) "bar")))
:pretty t)))) :pretty t))))
(testing "self-closing-tag" (testing "self-closing-tag"
(ok (string= "<img src=\"/background.png\">" (ok (string= "<img src=\"/background.png\">"
(render-to-string (create-element :img (render-to-string (create-element :img
@ -137,7 +138,18 @@
(create-element :li (create-element :li
nil nil
(list "brah")))) (list "brah"))))
:pretty t)))))) :pretty t)))))
(testing "minify-props-text"
(let ((elm (create-element :div
'(:x-data "{
open: false,
get isOpen() { return this.open },
toggle() { this.open = ! this.open },
}")
nil)))
(ok (string= (render-to-string elm)
"<div x-data=\"{ open: false, get isOpen() { return this.open }, toggle() { this.open = ! this.open }, }\"></div>")))))
(defun comp1 (&key prop children) (defun comp1 (&key prop children)
(create-element :div (create-element :div

View file

@ -11,16 +11,7 @@
(testing "escape-html-text-content" (testing "escape-html-text-content"
(ok (string= "&amp;&lt;&gt;&quot;&#x27;&#x2F;&grave;&#x3D;" (ok (string= "&amp;&lt;&gt;&quot;&#x27;&#x2F;&grave;&#x3D;"
(escape-html-text-content "&<>\"'/`=")))) (escape-html-text-content "&<>\"'/`=")))))
(testing "minify"
;; Test with Alpine.js
(ok (string= (minify "{
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 (defgroup fruit
apple banana) apple banana)