[cl-who-devel] Generating HTML using the result of a function call

Taylor Venable taylor at metasyntax.net
Sun Jul 27 15:10:03 UTC 2008


Hello,

I've been trying to figure out how to do something in CL-WHO and
haven't been able to get it yet, so I thought perhaps somebody on here
might be able to help me out.

I'm working on an RSS / blog component on my website which is written
in Lisp (running on top of Hunchentoot, specifically).  Each entry in
the blog consists of a file located in a hierarchy that composes a
date: e.g. /blog/2008/05/02 for the entry of May 2nd, 2008.  Each entry
file is a Lisp file with the following structure:

((title . "The Title Goes Here")
 (description . "This is what gets shown in the RSS feed.")
 (body . (:div :id "content"
             (:p "This is the first paragraph in the entry.")
             (:p "Here's another paragraph with "
                 (:a :href "/foo" "a link")
               " inside of it."))))

My goal is to use the Lisp reader to read the list into a variable,
let's call it "content", and to pull out of "content" the things that I
need to render.  With RSS this was possible by using something like:

(cl-who:with-html-output (output)
  (:item
    (:title (cl-who:str (cdr (assoc :title content))))
    (:description (cl-who:str (cdr (assoc :description content))))))

But I also want to render HTML pages constructed from the "body" part
of the entry, something that would work like:

(with-open-file (input (site-file path))
  (let ((content (read input)))
    (cl-who:with-html-output (output) (cdr (assoc :body content)))))

But evaluate (cdr (assoc :body content)) and use the result [in this
case it would turn into the HTML template code that I wanted] rather
than doing what seems to be the default behaviour of evaluating the
expression but then outputting nothing.  Is this possible with CL-WHO
at this time?  If not, would it be difficult to add such feature in a
manner similar to how CL-WHO:STR and CL-WHO:HTM work?

Thanks for any help or ideas.  I'm using version 0.11.1 running under
SBCL 1.0.11 on Ubuntu GNU/Linux 8.04.1

-- 
Taylor Venable            http://real.metasyntax.net:2357/

foldr = lambda f, i, l: (len(l) == 1 and [f(l[0], i)] or
                         [f(l[0], foldr(f, i, l[1:]))])[0]



More information about the Cl-who-devel mailing list