Discussion:
CL-WHO transformation rule not working?
Nico de Jager
2006-11-14 16:00:34 UTC
Permalink
Hi

It seems that the last transformation rule (and example) for attribute values
described in CL-WHO's documentation is not working.

I am using:
LispWorks 5.0 for Linux (Debian Sarge)
CL-WHO-0.6.2
HUNCHENTOOT-0.4.9

E.g.
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border "3" ; Going to change this!
(:tr (:td "1-1") (:td "1-2")))))))

gives the following in 2 browsers:
Some text
1-1 1-2

html:
<html><head><title>test</title></head><body>Some text<table
border='3'><tr><td>1-1</td><td>1-2</td></tr></table></body></html>

While:
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2) ;Substituted (+ 1 2) for "3".
(:tr (:td "1-1") (:td "1-2")))))))
1-11-2
<tr><td>1-1</td><td>1-2</td></tr></table></body></html>
The output of both cl-who:show-html-expansion and cl-who:with-html-output
appear correct in the listener, though:
CL-USER 11 > (cl-who:show-html-expansion (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2)
(:tr (:td "1-1") (:td "1-2"))))))

(LET ((*STANDARD-OUTPUT* *STANDARD-OUTPUT*))
(PROGN
NIL
(WRITE-STRING "<html><head><title>test</title></head><body>Some
text<table" *STANDARD-OUTPUT*)
(LET ((#:G4088 (+ 1 2)))
(COND ((NULL #:G4088))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :XML)) (PROGN
(WRITE-STRING " border='border'" *STANDARD-OUTPUT*)))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :SGML)) (PROGN
(WRITE-STRING " border" *STANDARD-OUTPUT*)))
(T (PROGN (WRITE-STRING " border='" *STANDARD-OUTPUT*) (PRINC
#:G4088 *STANDARD-OUTPUT*) (WRITE-STRING "'" *STANDARD-OUTPUT*)))))
(WRITE-STRING "><tr><td>1-1</td><td>1-2</td></tr></table></body></html>"
*STANDARD-OUTPUT*)))

It seems that only the output of the last "write-string" is sent to the
browser for the second example.

Thanks.
Nico
Edi Weitz
2006-11-14 19:28:19 UTC
Permalink
Hi!
Post by Nico de Jager
It seems that the last transformation rule (and example) for
attribute values described in CL-WHO's documentation is not working.
No, it is working. See below.
Post by Nico de Jager
LispWorks 5.0 for Linux (Debian Sarge)
CL-WHO-0.6.2
HUNCHENTOOT-0.4.9
E.g.
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border "3" ; Going to change this!
(:tr (:td "1-1") (:td "1-2")))))))
Some text
1-1 1-2
<html><head><title>test</title></head><body>Some text<table
border='3'><tr><td>1-1</td><td>1-2</td></tr></table></body></html>
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2) ;Substituted (+ 1 2) for "3".
(:tr (:td "1-1") (:td "1-2")))))))
1-11-2
<tr><td>1-1</td><td>1-2</td></tr></table></body></html>
The output of both cl-who:show-html-expansion and cl-who:with-html-output
CL-USER 11 > (cl-who:show-html-expansion (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2)
(:tr (:td "1-1") (:td "1-2"))))))
(LET ((*STANDARD-OUTPUT* *STANDARD-OUTPUT*))
(PROGN
NIL
(WRITE-STRING "<html><head><title>test</title></head><body>Some
text<table" *STANDARD-OUTPUT*)
(LET ((#:G4088 (+ 1 2)))
(COND ((NULL #:G4088))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :XML)) (PROGN
(WRITE-STRING " border='border'" *STANDARD-OUTPUT*)))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :SGML)) (PROGN
(WRITE-STRING " border" *STANDARD-OUTPUT*)))
(T (PROGN (WRITE-STRING " border='" *STANDARD-OUTPUT*) (PRINC
#:G4088 *STANDARD-OUTPUT*) (WRITE-STRING "'" *STANDARD-OUTPUT*)))))
(WRITE-STRING "><tr><td>1-1</td><td>1-2</td></tr></table></body></html>"
*STANDARD-OUTPUT*)))
It seems that only the output of the last "write-string" is sent to
the browser for the second example.
Your problem is that handlers in Hunchentoot are expected to return a
string and the string your first handler returns is only by pure
coincidence the result you wanted to have. You're sending the "real"
page to *STANDARD-OUTPUT* where it is not seen by Hunchentoot.

Try to use WITH-HTML-OUTPUT-TO-STRING instead. That should result in
the same page in both cases. Take a look at test/test.lisp in
Hunchentoot to see how it's done there.

HTH,
Edi.
Nico de Jager
2006-11-15 06:58:12 UTC
Permalink
Post by Edi Weitz
Hi!
Post by Nico de Jager
It seems that the last transformation rule (and example) for
attribute values described in CL-WHO's documentation is not working.
No, it is working. See below.
Post by Nico de Jager
LispWorks 5.0 for Linux (Debian Sarge)
CL-WHO-0.6.2
HUNCHENTOOT-0.4.9
E.g.
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border "3" ; Going to change this!
(:tr (:td "1-1") (:td "1-2")))))))
Some text
1-1 1-2
<html><head><title>test</title></head><body>Some text<table
border='3'><tr><td>1-1</td><td>1-2</td></tr></table></body></html>
(defun logon-page-html () ;logon-action)
(with-html-output (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2) ;Substituted (+ 1 2) for "3".
(:tr (:td "1-1") (:td "1-2")))))))
1-11-2
<tr><td>1-1</td><td>1-2</td></tr></table></body></html>
The output of both cl-who:show-html-expansion and cl-who:with-html-output
CL-USER 11 > (cl-who:show-html-expansion (*standard-output*)
(:html
(:head
(:title "test"))
(:body
"Some text"
(:table :border (+ 1 2)
(:tr (:td "1-1") (:td "1-2"))))))
(LET ((*STANDARD-OUTPUT* *STANDARD-OUTPUT*))
(PROGN
NIL
(WRITE-STRING "<html><head><title>test</title></head><body>Some
text<table" *STANDARD-OUTPUT*)
(LET ((#:G4088 (+ 1 2)))
(COND ((NULL #:G4088))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :XML)) (PROGN
(WRITE-STRING " border='border'" *STANDARD-OUTPUT*)))
((AND (EQ #:G4088 T) (EQ CL-WHO::*HTML-MODE* :SGML)) (PROGN
(WRITE-STRING " border" *STANDARD-OUTPUT*)))
(T (PROGN (WRITE-STRING " border='" *STANDARD-OUTPUT*) (PRINC
#:G4088 *STANDARD-OUTPUT*) (WRITE-STRING "'" *STANDARD-OUTPUT*)))))
(WRITE-STRING
"><tr><td>1-1</td><td>1-2</td></tr></table></body></html>"
*STANDARD-OUTPUT*)))
It seems that only the output of the last "write-string" is sent to
the browser for the second example.
Your problem is that handlers in Hunchentoot are expected to return a
string and the string your first handler returns is only by pure
coincidence the result you wanted to have. You're sending the "real"
page to *STANDARD-OUTPUT* where it is not seen by Hunchentoot.
Try to use WITH-HTML-OUTPUT-TO-STRING instead. That should result in
the same page in both cases. Take a look at test/test.lisp in
Hunchentoot to see how it's done there.
HTH,
Edi.
Doh! Shame on me! I used TBNL and CL-WHO long ago and did not read the docs
and examples again to get a proper grasp of it.

Anyway, thanks Edi, and special thanks for all your great work.

Nico

Loading...