[Bese-devel] How to use tal-templates

Marco Baringer mb at bese.it
Mon Aug 15 08:34:09 UTC 2005


Marco Simon <marco_simon at web.de> writes:

> Hi William,
>
> I fear I didn't explain correctly what's my need.
> Perhaps I should tell what I wanna do:
>
> I want to embed some html or js snippets directly into
> my ucw-code. (something like
> (<:as-is code_snippet)
>
> An easy example would be:
> (<:as-is "<script type=\"text/javascript\"> alert(\"Hello
> World\")</script)")

grab a very recent ucw and parenscript (see other email to
bese-devel):

(<ucw:script
  (alert "Hello World"))

that is sooooo much better.

having said that, what you probably want is just an easy way to read
in a string and setup the delimiting chars based on the content of the
string:

CL-USER> (defun |#/ reader| (stream sub-char prefix)
           (declare (ignore sub-char prefix))
           (with-output-to-string (string)
             (loop
                with delimiter = (read-char stream t nil t)
                for char = (read-char stream t nil t)
                until (char= delimiter char)
                do (write-char char string))))
                
|#/ reader|
CL-USER> (set-dispatch-macro-character #\# #\/ #'|#/ reader|)
T
CL-USER> #/"foo"
"foo"
CL-USER> #/!foo!
"foo"
CL-USER> #/'foo'
"foo"
CL-USER> 

You could just as well make it always use #\/ and avoid the extra
chars.

> As you can see I had to escape several double-quotation-marks in
> order to make lisp handle this as one Sting. This "escaping by hand"
> might be ok for short and handwritten snippets, but if I've got some
> longer js-code with lots of " in it, it will become some work to
> escape all all of them " by hand (if even possible).

you could also just put everything in an external js file and pass the
:javascript arg to simple-window-component.

> This is why I'am looking for some function which escapes all " within
> that snipped.
> In php I'd easyly write someting like this:
>  <? echo addslashes($snipped) ?> or
> <? $mysnipped = '<script type="text/javascript"> alert ("Hello World")
> </script>' ?>
>
> I'm absolutely sure that something similar is even possible with
> lisp, but I didn't realize how to do so far.

hth.

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list