Discussion:
Runtime HTML generation
Ron Garret
2010-01-23 17:51:36 UTC
Permalink
Is there a Right Way to use CL-WHO to generate HTML at run time? For example, suppose I want to do something like this:

(defun make-table (l)
`(:table ,@(mapcar (lambda (row) `(:tr ,@(mapcar (lambda (cell) `(:td (str ,cell)))
row)))
l)))

(cl-who:with-html-output-to-string (*standard-output* nil :prologue t)
... (make-table l) ...)

This doesn't work because CL-WHO normally does all its work at compile time, but L is not known until run time. I can hack this using a macro that calls EVAL, or by hacking the CL-WHO code to add another specially handled symbol, but before diving into that rabbit hole I thought I'd ask if there was already a way of doing this that I've overlooked.

Thanks,
rg
Joubert Nel
2010-01-23 19:45:33 UTC
Permalink
Hi Ron,

You can use the with-html-output-to-string function to generate HTML at run-time.
Using it in a macro, you can then do data-driven HTML construction using mapcar, loop, etc.

Joubert
Post by Ron Garret
(defun make-table (l)
row)))
l)))
(cl-who:with-html-output-to-string (*standard-output* nil :prologue t)
... (make-table l) ...)
This doesn't work because CL-WHO normally does all its work at compile time, but L is not known until run time. I can hack this using a macro that calls EVAL, or by hacking the CL-WHO code to add another specially handled symbol, but before diving into that rabbit hole I thought I'd ask if there was already a way of doing this that I've overlooked.
Thanks,
rg
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Stas Boukarev
2010-01-23 19:51:15 UTC
Permalink
Post by Joubert Nel
Hi Ron,
You can use the with-html-output-to-string function to generate HTML at run-time.
Using it in a macro, you can then do data-driven HTML construction using mapcar, loop, etc.
with-html-output-to-string is a macro.
--
With Best Regards, Stas.
Ron Garret
2010-01-23 20:20:22 UTC
Permalink
No, that won't work. with-html-output-to-string is a macro, not a function. It does its work at macroexpansion time, not run-time. (You might want to re-read my original message.)

rg
Post by Joubert Nel
Hi Ron,
You can use the with-html-output-to-string function to generate HTML at run-time.
Using it in a macro, you can then do data-driven HTML construction using mapcar, loop, etc.
Joubert
Post by Ron Garret
(defun make-table (l)
row)))
l)))
(cl-who:with-html-output-to-string (*standard-output* nil :prologue t)
... (make-table l) ...)
This doesn't work because CL-WHO normally does all its work at compile time, but L is not known until run time. I can hack this using a macro that calls EVAL, or by hacking the CL-WHO code to add another specially handled symbol, but before diving into that rabbit hole I thought I'd ask if there was already a way of doing this that I've overlooked.
Thanks,
rg
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
J. K. Cunningham
2010-01-23 20:56:42 UTC
Permalink
Post by Ron Garret
No, that won't work. with-html-output-to-string is a macro, not a function. It does its work at macroexpansion time, not run-time. (You might want to re-read my original message.)
This works - I just put an example up on a website to try it - code is
there:

http://jandmworks.com/test.html

(defun make-table (l)
(with-html-output (*standard-output*)
(:table :border 1 (mapcar (lambda (row) (htm
(:tr (mapcar (lambda (cell)
(htm (:td (str cell)))) row)))) l))))

The list I'm passing it could have come from anywhere - a file, a posted response, etc.

Jeff
Post by Ron Garret
rg
Post by Joubert Nel
Hi Ron,
You can use the with-html-output-to-string function to generate HTML at run-time.
Using it in a macro, you can then do data-driven HTML construction using mapcar, loop, etc.
Joubert
Post by Ron Garret
(defun make-table (l)
row)))
l)))
(cl-who:with-html-output-to-string (*standard-output* nil :prologue t)
... (make-table l) ...)
This doesn't work because CL-WHO normally does all its work at compile time, but L is not known until run time. I can hack this using a macro that calls EVAL, or by hacking the CL-WHO code to add another specially handled symbol, but before diving into that rabbit hole I thought I'd ask if there was already a way of doing this that I've overlooked.
Thanks,
rg
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Ron Garret
2010-01-23 23:11:00 UTC
Permalink
Ah. I think I get it now. Thanks!

rg
Post by J. K. Cunningham
Post by Ron Garret
No, that won't work. with-html-output-to-string is a macro, not a function. It does its work at macroexpansion time, not run-time. (You might want to re-read my original message.)
This works - I just put an example up on a website to try it - code is
http://jandmworks.com/test.html
(defun make-table (l)
(with-html-output (*standard-output*)
(:table :border 1 (mapcar (lambda (row) (htm
(:tr (mapcar (lambda (cell)
(htm (:td (str cell)))) row)))) l))))
The list I'm passing it could have come from anywhere - a file, a posted response, etc.
Jeff
Post by Ron Garret
rg
Post by Joubert Nel
Hi Ron,
You can use the with-html-output-to-string function to generate HTML at run-time.
Using it in a macro, you can then do data-driven HTML construction using mapcar, loop, etc.
Joubert
Post by Ron Garret
(defun make-table (l)
row)))
l)))
(cl-who:with-html-output-to-string (*standard-output* nil :prologue t)
... (make-table l) ...)
This doesn't work because CL-WHO normally does all its work at compile time, but L is not known until run time. I can hack this using a macro that calls EVAL, or by hacking the CL-WHO code to add another specially handled symbol, but before diving into that rabbit hole I thought I'd ask if there was already a way of doing this that I've overlooked.
Thanks,
rg
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Loading...