[cl-who-devel] Generating html tree with dynamic structure
Dmitry V'yal
akamaus at gmail.com
Tue Nov 24 08:47:22 UTC 2009
Ken Harris wrote:
> Hi Dmitry,
>
> I had the same problem about a year ago. After looking at cl-who, my
> conclusion was that it's really designed for efficiently writing fixed
> structure with variable content, not variable structure.
I have the same feeling now
>
> My first attempt was simply string concatenation on the result of
> multiple with-html-output-to-string calls. It worked fine, but with
> bigger inputs it became unusably slow due to all the consing.
> A second option I considered was to slap a big ol' EVAL (or
> MACROEXPAND? I can't remember, offhand) in there. This is a little
> weird, since cl-who transforms the input sexp into code to efficiently
> write it, but then I'm only using it once. Also, due to the weird
> call structure (to-macro-and-back), I recall it being somewhat hard to
> debug.
>
> The thing I finally settled on was writing my own function that took
> as input something that looked like cl-who's input, and wrote it out
> to a stream. It was surprisingly simple to write (I think it was
> 10-15 lines, but I don't have it in front of me right now), though it
> obviously doesn't handle every case cl-who does. It wouldn't handle
> htm/str/txt or prologues or inline code or whatever -- I just pass in
> a complete sexp, and it walks the tree and writes to a stream.
>
> In your case, you'd just need to generate a value like (:strong
> (:italic "text")) to pass in -- and Lisp tends to be pretty good at
> letting you build lists. :-)
>
> (I hooked it up to write to my web server's response stream directly,
> and it screamed. Well, at least compared to the old "cons a few
> gigabytes every request" method.)
>
> I can dig up that function tonight if it sounds useful to you.
Yes, please, share it. I thought about such approach and was sure
someone already faced that problem and has a solution.
P.S. After some search I found htmlgen library. It seems to have built
in functions for generate html from s-expressions. Probably it better
suited for my use case.
More information about the Cl-who-devel
mailing list