diff --git a/qlfile b/qlfile index 8fe6a9d..4f02666 100644 --- a/qlfile +++ b/qlfile @@ -1,4 +1,6 @@ ql alexandria -ql mstrings +ql cl-str + github rove fukamachi/rove github dissect Shinmera/dissect ; workaround +ql mstrings diff --git a/qlfile.lock b/qlfile.lock index a072ede..8cadf24 100644 --- a/qlfile.lock +++ b/qlfile.lock @@ -6,7 +6,7 @@ (:class qlot/source/ql:source-ql :initargs (:%version :latest) :version "ql-2023-10-21")) -("mstrings" . +("cl-str" . (:class qlot/source/ql:source-ql :initargs (:%version :latest) :version "ql-2023-10-21")) @@ -18,3 +18,7 @@ (:class qlot/source/github:source-github :initargs (:repos "Shinmera/dissect" :ref nil :branch nil :tag nil) :version "github-a70cabcd748cf7c041196efd711e2dcca2bbbb2c")) +("mstrings" . + (:class qlot/source/ql:source-ql + :initargs (:%version :latest) + :version "ql-2023-10-21")) diff --git a/src/element.lisp b/src/element.lisp index 1656253..5bc3ea4 100644 --- a/src/element.lisp +++ b/src/element.lisp @@ -1,10 +1,11 @@ (defpackage #:hsx/element (:use #:cl) + (:import-from #:str + #:collapse-whitespaces) (:import-from #:hsx/utils #:defgroup #:escape-html-attribute - #:escape-html-text-content - #:minify) + #:escape-html-text-content) (:export #:element #:tag #:html-tag @@ -126,7 +127,7 @@ (string-downcase (element-type element))) (defmethod render-props ((element tag)) - (minify + (collapse-whitespaces (with-output-to-string (stream) (loop :for (key value) :on (element-props element) :by #'cddr diff --git a/src/utils.lisp b/src/utils.lisp index 7285969..0d8c66d 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -6,7 +6,6 @@ #:symbolicate) (:export #:escape-html-attribute #:escape-html-text-content - #:minify #:defgroup)) (in-package #:hsx/utils) @@ -43,23 +42,6 @@ (defun escape-html-attribute (str) (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) (let ((ht (make-hash-table))) (mapcar (lambda (sym) diff --git a/tests/element.lisp b/tests/element.lisp index 36bd31c..211777e 100644 --- a/tests/element.lisp +++ b/tests/element.lisp @@ -89,6 +89,7 @@ nil "bar"))) :pretty t)))) + (testing "self-closing-tag" (ok (string= "" (render-to-string (create-element :img @@ -137,7 +138,18 @@ (create-element :li nil (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) + "
"))))) (defun comp1 (&key prop children) (create-element :div diff --git a/tests/utils.lisp b/tests/utils.lisp index 2997521..bd6f722 100644 --- a/tests/utils.lisp +++ b/tests/utils.lisp @@ -11,16 +11,7 @@ (testing "escape-html-text-content" (ok (string= "&<>"'/`=" - (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 }, }")))) + (escape-html-text-content "&<>\"'/`="))))) (defgroup fruit apple banana)