Skip to content

Commit 7ce7751

Browse files
committed
Use cl-str instead
1 parent 53a6a8f commit 7ce7751

File tree

6 files changed

+26
-34
lines changed

6 files changed

+26
-34
lines changed

qlfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
ql alexandria
2-
ql mstrings
2+
ql cl-str
3+
34
github rove fukamachi/rove
45
github dissect Shinmera/dissect ; workaround
6+
ql mstrings

qlfile.lock

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(:class qlot/source/ql:source-ql
77
:initargs (:%version :latest)
88
:version "ql-2023-10-21"))
9-
("mstrings" .
9+
("cl-str" .
1010
(:class qlot/source/ql:source-ql
1111
:initargs (:%version :latest)
1212
:version "ql-2023-10-21"))
@@ -18,3 +18,7 @@
1818
(:class qlot/source/github:source-github
1919
:initargs (:repos "Shinmera/dissect" :ref nil :branch nil :tag nil)
2020
:version "github-a70cabcd748cf7c041196efd711e2dcca2bbbb2c"))
21+
("mstrings" .
22+
(:class qlot/source/ql:source-ql
23+
:initargs (:%version :latest)
24+
:version "ql-2023-10-21"))

src/element.lisp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
(defpackage #:hsx/element
22
(:use #:cl)
3+
(:import-from #:str
4+
#:collapse-whitespaces)
35
(:import-from #:hsx/utils
46
#:defgroup
57
#:escape-html-attribute
6-
#:escape-html-text-content
7-
#:minify)
8+
#:escape-html-text-content)
89
(:export #:element
910
#:tag
1011
#:html-tag
@@ -126,7 +127,7 @@
126127
(string-downcase (element-type element)))
127128

128129
(defmethod render-props ((element tag))
129-
(minify
130+
(collapse-whitespaces
130131
(with-output-to-string (stream)
131132
(loop
132133
:for (key value) :on (element-props element) :by #'cddr

src/utils.lisp

-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#:symbolicate)
77
(:export #:escape-html-attribute
88
#:escape-html-text-content
9-
#:minify
109
#:defgroup))
1110
(in-package #:hsx/utils)
1211

@@ -43,23 +42,6 @@
4342
(defun escape-html-attribute (str)
4443
(escape-string str *attribute-escape-map*))
4544

46-
(defun minify (str)
47-
(with-output-to-string (out)
48-
(let ((previous-space-p nil))
49-
(loop
50-
:for char :across str
51-
:do (cond
52-
((whitespace-p char)
53-
(unless previous-space-p
54-
(write-char #\Space out))
55-
(setf previous-space-p t))
56-
(t
57-
(write-char char out)
58-
(setf previous-space-p nil)))))))
59-
60-
(defun whitespace-p (char)
61-
(member char '(#\Space #\Newline #\Tab #\Return) :test #'char=))
62-
6345
(defun make-keyword-hash-table (symbols)
6446
(let ((ht (make-hash-table)))
6547
(mapcar (lambda (sym)

tests/element.lisp

+13-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
nil
9090
"bar")))
9191
:pretty t))))
92+
9293
(testing "self-closing-tag"
9394
(ok (string= "<img src=\"/background.png\">"
9495
(render-to-string (create-element :img
@@ -137,7 +138,18 @@
137138
(create-element :li
138139
nil
139140
(list "brah"))))
140-
:pretty t))))))
141+
:pretty t)))))
142+
143+
(testing "minify-props-text"
144+
(let ((elm (create-element :div
145+
'(:x-data "{
146+
open: false,
147+
get isOpen() { return this.open },
148+
toggle() { this.open = ! this.open },
149+
}")
150+
nil)))
151+
(ok (string= (render-to-string elm)
152+
"<div x-data=\"{ open: false, get isOpen() { return this.open }, toggle() { this.open = ! this.open }, }\"></div>")))))
141153

142154
(defun comp1 (&key prop children)
143155
(create-element :div

tests/utils.lisp

+1-10
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@
1111

1212
(testing "escape-html-text-content"
1313
(ok (string= "&amp;&lt;&gt;&quot;&#x27;&#x2F;&grave;&#x3D;"
14-
(escape-html-text-content "&<>\"'/`="))))
15-
16-
(testing "minify"
17-
;; Test with Alpine.js
18-
(ok (string= (minify "{
19-
open: false,
20-
get isOpen() { return this.open },
21-
toggle() { this.open = ! this.open },
22-
}")
23-
"{ open: false, get isOpen() { return this.open }, toggle() { this.open = ! this.open }, }"))))
14+
(escape-html-text-content "&<>\"'/`=")))))
2415

2516
(defgroup fruit
2617
apple banana)

0 commit comments

Comments
 (0)