From simply.nitaai at gmail.com Thu Jul 28 07:12:46 2011 From: simply.nitaai at gmail.com (Matus Kmit) Date: Thu, 28 Jul 2011 09:12:46 +0200 Subject: [cl-who-devel] Interpolate lisp code inside the tag body Message-ID: Hello i just starting working with cl-who and i have one very basic question: How does one properly embed and evaluate lisp code inside the tag body? Let's say i have a function "fn" which returns a string and i want to embed its value in a tag, like: (: p (fn)) -> that does not work. Thanks for help Matus From sebyte at smolny.plus.com Thu Jul 28 08:06:06 2011 From: sebyte at smolny.plus.com (Sebastian Tennant) Date: Thu, 28 Jul 2011 08:06:06 +0000 Subject: [cl-who-devel] Interpolate lisp code inside the tag body References: Message-ID: <62mmvngx.fsf@chimera.gnukahvesi.net> Quoth Matus Kmit : > How does one properly embed and evaluate lisp code inside the tag body? You can 'embed' the *value* of an attribute, but not attributes themselves. In practice this is not a serious limitation. > (:p (fn)) does not work. No, but this does: (flet ((fn () "value")) (with-html-output-to-string (s) (:p :attribute (fn)))) => "

" Note, that to do something similar in the text node of an element, you should use one of the exported symbols; esc, fmt or str. http://weitz.de/cl-who/#esc For example: (flet ((fn () "Attributes and their values")) (with-html-output-to-string (s) (:h1 (str (fn))))) => "

Attributes and their values

" Hope this helps, Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap From simply.nitaai at gmail.com Thu Jul 28 08:23:44 2011 From: simply.nitaai at gmail.com (Matus Kmit) Date: Thu, 28 Jul 2011 10:23:44 +0200 Subject: [cl-who-devel] Interpolate lisp code inside the tag body In-Reply-To: References: Message-ID: Let me specify further my question. if i do: (with-html-output (*standard-output*) (:body (:p (str (fn)))) then the generated html code is correct but the return string is not complete:

text

"

" Thus if i publish this function the web page is blank. If i do the same with with-html-output-to-string however, i get the correct string and the published webpage is displayed correctly: "

text

" (the code is only a snippet of the web page) Does that mean that one should use only with-html-output-to-string for publishing or is there something wrong with the way i am embedding the lisp code? Thanks Matus On Thu, Jul 28, 2011 at 9:12 AM, Matus Kmit wrote: > Hello > > i just starting working with cl-who and i have one very basic question: > > How does one properly embed and evaluate lisp code inside the tag body? > > Let's say i have a function "fn" which returns a string and i want to > embed its value in a tag, like: > > (: p (fn)) -> that does not work. > > Thanks for help > Matus > From simply.nitaai at gmail.com Thu Jul 28 08:44:31 2011 From: simply.nitaai at gmail.com (Matus Kmit) Date: Thu, 28 Jul 2011 10:44:31 +0200 Subject: [cl-who-devel] Interpolate lisp code inside the tag body In-Reply-To: <62mmvngx.fsf@chimera.gnukahvesi.net> References: <62mmvngx.fsf@chimera.gnukahvesi.net> Message-ID: Yes, this helps. i think it also answers my second post -> one should use "with-html-output-to-string"... Right? Matus On Thu, Jul 28, 2011 at 10:06 AM, Sebastian Tennant wrote: > Quoth Matus Kmit : >> How does one properly embed and evaluate lisp code inside the tag body? > > You can 'embed' the *value* of an attribute, but not attributes themselves. > > In practice this is not a serious limitation. > >> (:p (fn)) does not work. > > No, but this does: > > ?(flet ((fn () "value")) > ? (with-html-output-to-string (s) > ? ? (:p :attribute (fn)))) > ?=> "

" > > Note, that to do something similar in the text node of an element, you should > use one of the exported symbols; esc, fmt or str. > > ?http://weitz.de/cl-who/#esc > > For example: > > ?(flet ((fn () "Attributes and their values")) > ? (with-html-output-to-string (s) > ? ? (:h1 (str (fn))))) > ?=> "

Attributes and their values

" > > Hope this helps, > > Sebastian > -- > Emacs' AlsaPlayer - Music Without Jolts > Lightweight, full-featured and mindful of your idyllic happiness. > http://home.gna.org/eap > > > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel >