diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-05-31 22:26:04 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-05-31 22:26:04 -0700 |
commit | 1426a6c942b6fdbdb28a78c61f73aab31c7f83c6 (patch) | |
tree | af31bb32ddd7a96f381243106391068977af6355 | |
parent | 7a0634b5ad9abb0e0a88b97cb087554fb0e0238b (diff) | |
download | tl-who-1426a6c942b6fdbdb28a78c61f73aab31c7f83c6.tar.gz tl-who-1426a6c942b6fdbdb28a78c61f73aab31c7f83c6.tar.bz2 tl-who-1426a6c942b6fdbdb28a78c61f73aab31c7f83c6.zip |
Allow fmt and escj to be used to calculate attributes.
* who.tl (attr-warning-macrolet): Do not warn when
fmt and escj are used on attributes. Instead, give
them a useful definition so they do what the
programmer wants: return a string.
* test/simple.tl: Trim it
to just the tags that should warn now. Also
fix a bug that rendered this case invalid:
unquote occurred with no backquote, and this
produced an undefined variable warning on
sym, which was treated by the test case's handler
as a false positive that made it pass.
New test case 45 testing fmt and escj in
attributes.
* README.md: Added to notes on differences between
TL-WHO and CL-WHO.
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | test/simple.tl | 11 | ||||
-rw-r--r-- | who.tl | 14 |
3 files changed, 24 insertions, 7 deletions
@@ -195,6 +195,12 @@ Here are the differences to be aware of: * TL-WHO's `esc` accepts arguments which are not strings. They are turned to a string using `tostringp`, and HTML-escaped. +* TL-WHO allows `fmt` as well as `escj` to be used to calculate attributes. + These local macros have alternative definitions when used in attributes. + The remaining local macros don't make sense in attributes, and make + a mess of the output if used; unlike CL-WHO, TL-WHO warns when they + are used in attributes. + Additionally, users (of CL-WHO and TL-WHO alike) are advised to watch for the following issue: the CL-WHO documentation is not accurately maintained and makes some references to material that no longer exists in CL-WHO, such as the diff --git a/test/simple.tl b/test/simple.tl index 3ed4685..4dc5b88 100644 --- a/test/simple.tl +++ b/test/simple.tl @@ -453,9 +453,9 @@ ;;; 41 ;;; Test that warning is produced when any of the WHO local macros are used in ;;; an Lisp expression that calculates an attribute -(each ((sym '(htm noesc-fmt fmt esc escq escj str))) +(each ((sym '(htm noesc-fmt esc escq str))) (test (catch - (eval '(progn + (eval ^(progn (with-html-output-to-string (out) (:foo :attr (,sym "abc"))) nil)) @@ -480,3 +480,10 @@ (test (with-html-output-to-string (out) (:p (esc 5) (escq 6) (escj 7))) "<p>567</p>") + +;;; 45 +;;; Test that we can use fmt and escj on attributes +(test (with-html-output-to-string (out) + (:div :span (fmt "~a&" 42) + :color (escj "</script>"))) + "<div span='42&' color='<\\/script>'></div>") @@ -88,11 +88,15 @@ (defun attr-warning-macrolet (form) (with-gensyms (warn) ^(macrolet ((,warn (f . rest) - ^(compile-warning ,f - "not recommended in attribute expr"))) - (macrolet ,(collect-each ((sym '(htm noesc-fmt fmt esc escq escj str))) - ^(,sym (:form f . rest) (,warn f) f)) - ,form)))) + ^(compile-warning ,f + "not recommended in attribute expr"))) + (macrolet ((fmt (. args) + ^(usr:fmt ,*args)) + (escj (thing) + ^[(tojson (tostringp ,thing)) 1..-1]) + ,*(collect-each ((sym '(htm noesc-fmt esc escq str))) + ^(,sym (:form f . rest) (,warn f) f))) + ,form)))) ;; Helper function for convert-tag-to-string-list which converts the ;; alist attr-list of attributes into a list of strings and/or Lisp |