From jim.barrows at gmail.com Thu Nov 17 15:47:32 2011 From: jim.barrows at gmail.com (Jim Barrows) Date: Thu, 17 Nov 2011 08:47:32 -0700 Subject: [cl-who-devel] Question about splitting tags in a dolist... Message-ID: I'm pulling records from a database, and I don't know how many I'll have. I need to display them in a 3 by X grid built in CSS. So it needs to look something like: (:div :class "row" (:div :class "span-one-third" "1/3") (:div :class "span-one-third" "1/3") (:div :class "span-one-third" "1/3")) Since I don't know how many rows are returning, I can't really hard code it like the above example. I'm new to lisp, so I may just be thinking about this in the wrong way. In Java, opening a tag like this and closing it is a very common pattern. Maybe I'm just thinking too much in Java... -- James A Barrows -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffrey at jkcunningham.com Thu Nov 17 17:19:19 2011 From: jeffrey at jkcunningham.com (Jeffrey Cunningham) Date: Thu, 17 Nov 2011 09:19:19 -0800 Subject: [cl-who-devel] Question about splitting tags in a dolist... In-Reply-To: References: Message-ID: On Thu, 17 Nov 2011 07:47:32 -0800, Jim Barrows wrote: > I'm pulling records from a database, and I don't know how many I'll > have. I need to display them in a 3 >by X grid built in CSS. So it > needs to look something like: > (:div :class "row" (:div :class "span-one-third" "1/3") > (:div :class "span-one-third" "1/3") > (:div :class "span-one-third" "1/3")) > > Since I don't know how many rows are returning, I can't really hard code > it like the above example. > > I'm new to lisp, so I may just be thinking about this in the wrong way. > In Java, opening a tag like this and >closing it is a very common > pattern. Maybe I'm just thinking too much in Java... > --James A Barrows Here's one way: (let ((records '((1 2 3) (4 5 6) (7 8 9)))) (with-html-output (*standard-output* nil :indent 0) (dolist (rec records) (htm (:div :class "row" (dolist (col rec) (htm (:div :class "span-one-third" (str col))))))))) Jeff Cunningham -------------- next part -------------- An HTML attachment was scrubbed... URL: From jim.barrows at gmail.com Fri Nov 18 18:13:41 2011 From: jim.barrows at gmail.com (Jim Barrows) Date: Fri, 18 Nov 2011 11:13:41 -0700 Subject: [cl-who-devel] Question about splitting tags in a dolist... In-Reply-To: References: Message-ID: I figured it out, thanks to Jeffrey. I appreciated the help, you pointed me in the right direction. What's really cool, is that by forcing me to not split the tags, I ended up with a much cleaner solution. It'll be even cleaner when I fix the hard coded list building :) (defun people-and-organizations-list () "Creates a list of people and organizations" (web-common::with-html (:section :id "people-and-organization-list" (:a :href *add-organization-url* "Add Organization") (let ((result-list (people-and-organizations-query)) (columns 3)) (loop for i from 0 to (list-length result-list) by 3 do (people-and-organizations-row (list (nth i result-list) (nth (+ 1 i) result-list) (nth (+ 2 i) result-list)))))))) On Thu, Nov 17, 2011 at 10:19 AM, Jeffrey Cunningham < jeffrey at jkcunningham.com> wrote: > ** > On Thu, 17 Nov 2011 07:47:32 -0800, Jim Barrows > wrote: > > I'm pulling records from a database, and I don't know how many I'll have. > I need to display them in a 3 by X grid built in CSS. So it needs to look > something like: > (:div :class "row" > (:div :class "span-one-third" "1/3") > (:div :class "span-one-third" "1/3") > (:div :class "span-one-third" "1/3")) > > Since I don't know how many rows are returning, I can't really hard code > it like the above example. > > I'm new to lisp, so I may just be thinking about this in the wrong way. > In Java, opening a tag like this and closing it is a very common pattern. > Maybe I'm just thinking too much in Java... > -- > James A Barrows > > > Here's one way: > > (let ((records '((1 2 3) (4 5 6) (7 8 9)))) > (with-html-output (*standard-output* nil :indent 0) > (dolist (rec records) > (htm (:div :class "row" > (dolist (col rec) > (htm (:div :class "span-one-third" (str col))))))))) > > Jeff Cunningham > > > > > -- James A Barrows -------------- next part -------------- An HTML attachment was scrubbed... URL: