Discussion:
Interpolate lisp code inside the tag body
Matus Kmit
2011-07-28 07:12:46 UTC
Permalink
Content preview: 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? [...]

Content analysis details: (-0.7 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[209.85.210.179 listed in list.dnswl.org]
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(simply.nitaai[at]gmail.com)
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/261>

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
Sebastian Tennant
2011-07-28 08:06:06 UTC
Permalink
Content preview: Quoth Matus Kmit <***@gmail.com>: > 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. [...]

Content analysis details: (-3.5 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium
trust
[80.91.229.12 listed in list.dnswl.org]
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
-0.0 SPF_PASS SPF: sender matches SPF record
-1.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/262>
Post by 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.
Post by Matus Kmit
(:p (fn)) does not work.
No, but this does:

(flet ((fn () "value"))
(with-html-output-to-string (s)
(:p :attribute (fn))))
=> "<p attribute='value'></p>"

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)))))
=> "<h1>Attributes and their values</h1>"

Hope this helps,

Sebastian
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
Matus Kmit
2011-07-28 08:44:31 UTC
Permalink
Content preview: 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 <***@smolny.plus.com> wrote: > Quoth
Matus Kmit <***@gmail.com>: >> 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
(flet ((fn () "value")) > (with-html-output-to-string (s) > (:p :attribute
(fn)))) > => "<p attribute='value'></p>" > > 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))))) > => "<h1>Attributes and their values</h1>" > > Hope
this helps, > > Sebastian > -- > Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness. > http://home.gna.org/eap
[...]
Content analysis details: (0.8 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
1.5 SINGLE_HEADER_2K A single header contains 2K-3K characters
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(simply.nitaai[at]gmail.com)
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[209.85.210.179 listed in list.dnswl.org]
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/264>

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
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.
 (flet ((fn () "value"))
  (with-html-output-to-string (s)
    (:p :attribute (fn))))
 => "<p attribute='value'></p>"
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
 (flet ((fn () "Attributes and their values"))
  (with-html-output-to-string (s)
    (:h1 (str (fn)))))
 => "<h1>Attributes and their values</h1>"
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
http://common-lisp.net/mailman/listinfo/cl-who-devel
Matus Kmit
2011-07-28 08:23:44 UTC
Permalink
Content preview: 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: [...]

Content analysis details: (-0.7 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(simply.nitaai[at]gmail.com)
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[209.85.210.179 listed in list.dnswl.org]
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/263>

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:

<body><p>text</p></body>
"</p></body>"

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:

"<body><p>text</p></body>" (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
Post by Matus Kmit
Hello
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
(: p (fn)) -> that does not work.
Thanks for help
Matus
Sebastian Tennant
2011-08-01 18:23:15 UTC
Permalink
Content preview: Quoth Matus Kmit <***@gmail.com>: > Does that mean
that one should use only with-html-output-to-string for > publishing Yes.
Let's say your dispatch handler (a hunchentoot term) calls function home-page,
then home-page should look like this: [...]

Content analysis details: (-3.1 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium
trust
[80.91.229.12 listed in list.dnswl.org]
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
-0.0 SPF_PASS SPF: sender matches SPF record
-0.8 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/269>
Post by Matus Kmit
Does that mean that one should use only with-html-output-to-string for
publishing
Yes. Let's say your dispatch handler (a hunchentoot term) calls function
home-page, then home-page should look like this:

(defun home-page ()
(with-html-output-to-string (*http-stream*)
(:p ...)
...))

where *http-stream* is defined as a special variable, like so:

(defun *http-stream* nil)

Now, let's assume home-page includes a call to function navbar.

navbar doesn't need to use w-h-o-t-s. This will suffice:

(defun (navbar ()
(with-html-output (*http-stream*)
(:div :id "navbar" ...)
...))

In short, only the 'top-level' function called by your dispatch handler
needs to use w-h-o-t-s.

Hope this helps.

Sebastian
Matus Kmit
2011-08-01 20:42:00 UTC
Permalink
Content preview: Excellent. THANKS. Matus On Mon, Aug 1, 2011 at 8:23 PM, Sebastian
Post by Matus Kmit
Does that mean that one should use only with-html-output-to-string for
publishing > > Yes. Let's say your dispatch handler (a hunchentoot term)
calls function > home-page, then home-page should look like this: > > (defun
home-page () > (with-html-output-to-string (*http-stream*) > (:p ...) > ...))
Post by Matus Kmit
where *http-stream* is defined as a special variable, like so: > > (defun
*http-stream* nil) > > Now, let's assume home-page includes a call to function
navbar. > > navbar doesn't need to use w-h-o-t-s. This will suffice: > >
(defun (navbar () > (with-html-output (*http-stream*) > (:div :id "navbar"
...) > ...)) > > In short, only the 'top-level' function called by your dispatch
handler > needs to use w-h-o-t-s. > > Hope this helps. > > Sebastian > >
[...]
Content analysis details: (-0.7 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(simply.nitaai[at]gmail.com)
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[74.125.82.179 listed in list.dnswl.org]
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/270>

Excellent. THANKS.

Matus

On Mon, Aug 1, 2011 at 8:23 PM, Sebastian Tennant
Post by Matus Kmit
Does that mean that one should use only with-html-output-to-string for
publishing
Yes.  Let's say your dispatch handler (a hunchentoot term) calls function
(defun home-page ()
 (with-html-output-to-string (*http-stream*)
   (:p ...)
   ...))
(defun *http-stream* nil)
Now, let's assume home-page includes a call to function navbar.
(defun (navbar ()
 (with-html-output (*http-stream*)
   (:div :id "navbar" ...)
   ...))
In short, only the 'top-level' function called by your dispatch handler
needs to use w-h-o-t-s.
Hope this helps.
Sebastian
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Sebastian Tennant
2011-08-04 11:46:03 UTC
Permalink
Content preview: Quoth Matus Kmit <***@gmail.com>: > Excellent. THANKS.
I hope you spotted my deliberate mistake. Special variables are declared
with defvar (not defun). [...]

Content analysis details: (-3.0 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium
trust
[80.91.229.12 listed in list.dnswl.org]
-0.0 SPF_HELO_PASS SPF: HELO matches SPF record
-0.0 SPF_PASS SPF: sender matches SPF record
-0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/271>
Post by Matus Kmit
Excellent. THANKS.
I hope you spotted my deliberate mistake.

Special variables are declared with defvar (not defun).

Sebastian
Matus Kmit
2011-08-04 12:03:25 UTC
Permalink
Content preview: i wondered, but thought it might be another of lisp's elastic
features, known only to the advanced lisp hackers :-) Matus On Thu, Aug 4,
2011 at 1:46 PM, Sebastian Tennant <***@smolny.plus.com> wrote: > Quoth
Matus Kmit <***@gmail.com>: >> Excellent. THANKS. > > I hope you
spotted my deliberate mistake. > > Special variables are declared with defvar
http://common-lisp.net/mailman/listinfo/cl-who-devel > [...]
Content analysis details: (-0.7 points, 5.0 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low
trust
[74.125.82.53 listed in list.dnswl.org]
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(simply.nitaai[at]gmail.com)
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid
Archived-At: <http://permalink.gmane.org/gmane.lisp.who.general/272>

i wondered, but thought it might be another of lisp's elastic
features, known only to the advanced lisp hackers :-)

Matus

On Thu, Aug 4, 2011 at 1:46 PM, Sebastian Tennant
Post by Matus Kmit
Excellent. THANKS.
I hope you spotted my deliberate mistake.
Special variables are declared with defvar (not defun).
Sebastian
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Loading...