
Ahh. Dawn begins to break over Marblehead. Thank you all. Bryan On Wed, Jun 17, 2009 at 9:35 AM, Jens Teich <info@jensteich.de> wrote:
Now I'm really confused. Ken's example does exactly what I want when I create a gridify function and call it from a page macro (defmacro templates at the bottom of the email). But if I put the function body into the page macro, (see second example), it doesn't work. Rather, it prints the entire
Both use exactly the same macros to generate the page and it is a cut and
Bryan Emrys schrieb: table, complete with tr and td with no string - then drops the list of strings after the table paste job. Somehow putting the function body into the macro is changing how the loops work:
WORKS (defun gridify (x &optional (col 5)) "given a list of strings, put them in an html table (returned as a
string) with |col| columns."
(with-html-output-to-string (var nil) (:table (loop for xp on x by (lambda (p) (nthcdr col p)) do (htm (:tr (loop for i upto (1- col) for (id name) in xp do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name)))))))))))
(defpage-easy-slp gridify-countries "Countries Grid" "/gridify-countries" () (let* ((data-query "select id,name from countries order by name ") (results (query data-query)) (col 5)) (gridify results col)))
DOESNT WORK
(defpage-easy-slp countries-grid "Countries Grid" "/countries-grid" () (let* ((data-query "select id,name from countries order by name ") (x (query data-query)) (col 5)) (with-html-output-to-string (var nil) (:table (loop for xp on x by (lambda (p) (nthcdr col p)) do (htm (:tr (loop for i upto (1- col) for (id name) in xp do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name))))))))))))
DEF MACROS
(defmacro page-template (title &body body) `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) (:html (:head (:link :rel "stylesheet" :type "text/css" :href "/css/screen.css" :media "screen") (:title (str (format nil " ~a" ,title)))) (:body (:div :class "container" (:div :class "column span-24" (str ,@body))))))))
(defmacro defpage-easy-slp (name title uri parameter-list &body body) `(define-easy-handler (,name :uri ,uri :default-request-type :both) ,parameter-list (page-template ,title ,@body)))
see http://lisp-univ-etc.blogspot.com/2009/03/cl-who-macros.html
Jens
_______________________________________________ cl-who-devel site list cl-who-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cl-who-devel