[cl-who-devel] case sensitive tag

Mac Chan emailmac at gmail.com
Tue Mar 20 00:00:35 UTC 2007


Hi,

Another handy use of cl-who is to generate xml testing data, like so:

(with-html
   (loop repeat 500 do
         (htm
          (:|Item|
            (:|ASIN| (str (format nil "~D" (random 9999999999))))
            (:|DetailPageURL| "http://www.amazon.com/")
            (:|ItemAttributes|
              (:|Author| (str (conc (random-word) " " (random-word))))
              (:|Manufacturer| (str (random-word)))
              (:|ProductGroup| (str (random-word)))
              (:|Title| (str (conc (random-word) " " (random-word)" "
(random-word)))))))))


Attached is a simple patch to introduce a special var
cl-who:*downcase-tag* to control whether cl-who should downcase
tagname by default.

Originally I thought just using the (eql *html-mode* :xml) test should
be sufficient. But I see that a lot of people actually only use
lowercase xml tags for internal projects and requiring them to quote a
symbol with :|| is kind of inconvenient.

Cheers,
-- Mac
-------------- next part --------------
==== cl-who/doc/index.html#1 - cl-who/doc/index.html ====
541a542,550
> <p><br>[Special variable]
> <br><a class=none name="*downcase-tag*"><b>*downcase-tag*</b></a>
> 
> <blockquote><br>
>   If NIL, keyword symbol representing a tagname will not be
> automatically converted to lowercase.  It is useful when one needs to
> output case sensitive xml tags. Default to T.
> </blockquote>
> 
==== cl-who/packages.lisp#1 - cl-who/packages.lisp ====
37a38
>            #:*downcase-tag*
60a62
>            "*DOWNCASE-TAG*"
==== cl-who/who.lisp#1 - cl-who/who.lisp ====
49a50,54
> (defvar *downcase-tag* T
>   "If NIL, keyword symbol representing a tagname will not be
> automatically converted to lowercase.  It is useful when one needs to
> output case sensitive xml tags.")
> 
241a247
>   (let ((tag (if *downcase-tag* (string-downcase tag) (string tag))))
244,245c250,251
<        ;; indent by *INDENT* spaces
<        (list +newline+ (n-spaces *indent*)))
---
>          ;; indent by *INDENT* spaces
>          (list +newline+ (n-spaces *indent*)))
247c253
<      (list "<" (string-downcase tag))
---
>      (list "<" tag)
252,266c258,272
<        (append
<         (list ">")
<         ;; now hand over the tag's body to TREE-TO-TEMPLATE, increase
<         ;; *INDENT* by 2 if necessary
<         (if *indent*
<           (let ((*indent* (+ 2 *indent*)))
<             (funcall body-fn body))
<           (funcall body-fn body))
<         (if *indent*
<           ;; indentation
<           (list +newline+ (n-spaces *indent*)))
<         ;; closing tag
<         (list "</" (string-downcase tag) ">"))
<        ;; no body, so no closing tag
<        (list *empty-tag-end*))))
---
>          (append
>           (list ">")
>           ;; now hand over the tag's body to TREE-TO-TEMPLATE, increase
>           ;; *INDENT* by 2 if necessary
>           (if *indent*
>               (let ((*indent* (+ 2 *indent*)))
>                 (funcall body-fn body))
>               (funcall body-fn body))
>           (if *indent*
>               ;; indentation
>               (list +newline+ (n-spaces *indent*)))
>           ;; closing tag
>           (list "</" tag ">"))
>          ;; no body, so no closing tag
>          (list *empty-tag-end*)))))


More information about the Cl-who-devel mailing list