Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
filling rows from struct-map
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vesna Petkovic  
View profile  
 More options Dec 22 2011, 2:41 pm
From: Vesna Petkovic <vesna.petko...@gmail.com>
Date: Thu, 22 Dec 2011 11:41:52 -0800 (PST)
Local: Thurs, Dec 22 2011 2:41 pm
Subject: filling rows from struct-map

Hello everybody,

I have a question, I want to fill rows in html table from a struct-map. I
have a problem with row snippet, because I don't know how to define cell
selectors. Each key value pair from my struct map is for one cell in a row.
So my question is how do I define cell selectors, do I have to go one by
one cell, or is there any other way to do it (there probably is one but I
just can't seem to find it). I would probably need some kind of dynamic
selector...

Here is my row html from the file index.html
<tr>
                <td>Event Title</td>
                <td>Type of event</td>
                <td>Performer</td>
                <td>About</td>
                <td>Date</td>
                <td>Start time</td>
                <td>End time</td>
                <td>Place</td>
                <td>Video</td>        </tr> Here are my selectors, snippets
and template (def *first-cell-sel* [[:tr (html/nth-child 1)][:td
html/first-child]]) (def *rest-cell-sel* [[:table] [:tr (html/nth-child
2)][:td (html/nth-child 2)]]) (defsnippet second-cell
"eventsmashup/index.html" [[:table] [:tr (html/nth-child 1)][:td
(html/nth-child 2)]] [{value :performer}] [:td] (html/content value))
(defsnippet cell-model "eventsmashup/index.html" *first-cell-sel* [{value
:value}] [:td] (html/content value)) (defsnippet row-model
"eventsmashup/index.html" *row-sel* [{:keys [event-data]} model] [:tr]
(html/content (map model event-data))) (deftemplate index
"eventsmashup/index.html" [{:keys [event-data]}] [:tbody] (html/content
(map #(row-model % cell-model % second-cell)rows))) and here is part of
dummy-content struct-map, that I use for testing (def *dummy-content*
{:title "Events Mashup" :rows [ { :event-data [{:event-name "event name 1"
:performer "performer 1" :date "date 1" :start-time "start time 1"
:end-time "start time 1"}]}]}) When I start the app, the table is blank, my
code doesn't insert any content, and I can't seem to get the reason why. If
anybody can give me the answer I'd be really grateful. Thanks Vesna


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Mar 29 2012, 2:02 pm
From: gwanwyn <vesna.petko...@gmail.com>
Date: Thu, 29 Mar 2012 11:02:34 -0700 (PDT)
Local: Thurs, Mar 29 2012 2:02 pm
Subject: Re: filling rows from struct-map

I found the solution, and here it is , if anyone is interested

(html/defsnippet row-snippet table-template [[:tr (attr= :title "event")]]
  [{:keys [event-name performers date start-time end-time]}]

  [[:td (attr= :title "event-title")]] (html/content event-name)
  [[:td (attr= :title "performer")]] (html/content performers)
  [[:td (attr= :title "date")]] (html/content date)
  [[:td (attr= :title "start-time")]] (html/content start-time)
  [[:td (attr= :title "end-time")]] (html/content end-time))

(deftemplate indeks table-template
  [{:keys  [title event-data]}]
  [:title] (html/content title)
  [:tbody]  (html/content (map #(row-snippet %) (create-map-of-events)
                            )))

Also I added some changes to the html file
<tbody title="events">
<tr title="event">
<td title="event-title">Event Title 1</td>
<td title="performer">Performer1</td>
<td title="date">Date1</td>
<td title="start-time">Start time1</td>
<td title="end-time">End time1</td>

</tr>
Cheers.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Snikeris  
View profile  
 More options Mar 29 2012, 5:31 pm
From: Joe Snikeris <j...@snikeris.com>
Date: Thu, 29 Mar 2012 17:31:04 -0400
Local: Thurs, Mar 29 2012 5:31 pm
Subject: Re: [enlive] Re: filling rows from struct-map

If you name your map keys exactly as you name your titles, you can define a
transformation that will reduce a lot of the repetition found in your
solution. I did something similar w/ the 'class-as-kw-content'
transformation found here:

https://github.com/jsnikeris/mtg-store/blob/master/src/mtg_store/web/...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christophe Grand  
View profile  
 More options Mar 30 2012, 3:51 am
From: Christophe Grand <christo...@cgrand.net>
Date: Fri, 30 Mar 2012 09:51:47 +0200
Local: Fri, Mar 30 2012 3:51 am
Subject: Re: [enlive] Re: filling rows from struct-map

Using your latest HTML, something like this should also work (untested).
Doing something purely positional (without the title attributes) is doable
but more verbose.

(def mapping
  {"event-title" :event-name
   "performer" :performers
   "date" :date
   "start-time" :start-time
   "end-time" :end-time})

(deftemplate indeks table-template [{:keys  [title event-data]}]
  [:title] (html/content title)
  [:tr (nth-child 2)] (clone-for [event (event-data)]
                        [:td] #(-> % :attrs :title mapping event)))

Christophe

--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Mar 30 2012, 9:10 am
From: gwanwyn <vesna.petko...@gmail.com>
Date: Fri, 30 Mar 2012 06:10:59 -0700 (PDT)
Local: Fri, Mar 30 2012 9:10 am
Subject: Re: filling rows from struct-map

I changed one thing in the template bellow, and this is more elegant now :

(deftemplate indeks table-template [{:keys  [title event-data]}]
  [:title] (html/content title)
  [:tr (html/nth-child 2)] (html/clone-for [event event-data]
                        [:td] #(-> % :attrs :title mapping event)))

event-data was in brackets, and it shouldn't have been, it was giving null
pointer exception. However, now it won't fill the tds with content. I am
looking for the solution.

Joe, I will definitely try your solution.

Thank you both, and if you anyone can find the bug in the template above,
I'd be most grateful.

Cheers

Vesna


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Snikeris  
View profile  
 More options Mar 30 2012, 9:13 am
From: Joe Snikeris <j...@snikeris.com>
Date: Fri, 30 Mar 2012 09:13:27 -0400
Local: Fri, Mar 30 2012 9:13 am
Subject: Re: [enlive] Re: filling rows from struct-map

Very nice.

What's the purpose of the (nth-child 2) selector-step in this case?

On Fri, Mar 30, 2012 at 3:51 AM, Christophe Grand <christo...@cgrand.net>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christophe Grand  
View profile  
 More options Mar 30 2012, 9:16 am
From: Christophe Grand <christo...@cgrand.net>
Date: Fri, 30 Mar 2012 15:16:39 +0200
Local: Fri, Mar 30 2012 9:16 am
Subject: Re: [enlive] Re: filling rows from struct-map

Hi,

On Fri, Mar 30, 2012 at 3:10 PM, gwanwyn <vesna.petko...@gmail.com> wrote:

> event-data was in brackets, and it shouldn't have been, it was giving null
> pointer exception.

Indeed.

> However, now it won't fill the tds with content. I am looking for the
> solution.

Doh! (and it's also a side effect from writing code right in the mail)

(deftemplate indeks table-template [{:keys  [title event-data]}]
  [:title] (html/content title)
  [:tr (html/nth-child 2)] (html/clone-for [event event-data]
                        [:td] (fn [td] (assoc td :content [(-> td :attrs
:title mapping event str)]))))

I hope this works this time.

Christophe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christophe Grand  
View profile  
 More options Mar 30 2012, 9:18 am
From: Christophe Grand <christo...@cgrand.net>
Date: Fri, 30 Mar 2012 15:18:13 +0200
Local: Fri, Mar 30 2012 9:18 am
Subject: Re: [enlive] Re: filling rows from struct-map

On Fri, Mar 30, 2012 at 3:13 PM, Joe Snikeris <j...@snikeris.com> wrote:
> Very nice.

> What's the purpose of the (nth-child 2) selector-step in this case?

oops, another error:

(deftemplate indeks table-template [{:keys  [title event-data]}]
  [:title] (html/content title)
   [[:tr (html/nth-child 2)]] (html/clone-for [event event-data]
                        [:td] (fn [td] (assoc td :content [(-> td :attrs
:title mapping event str)]))))

 It is there to select (and clone) teh 2nd row.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Snikeris  
View profile  
 More options Mar 30 2012, 9:22 am
From: Joe Snikeris <j...@snikeris.com>
Date: Fri, 30 Mar 2012 09:22:06 -0400
Local: Fri, Mar 30 2012 9:22 am
Subject: Re: [enlive] Re: filling rows from struct-map

Isn't there only one row in the template?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christophe Grand  
View profile  
 More options Mar 30 2012, 9:25 am
From: Christophe Grand <christo...@cgrand.net>
Date: Fri, 30 Mar 2012 15:25:59 +0200
Local: Fri, Mar 30 2012 9:25 am
Subject: Re: [enlive] Re: filling rows from struct-map

On Fri, Mar 30, 2012 at 3:22 PM, Joe Snikeris <j...@snikeris.com> wrote:
> >  It is there to select (and clone) teh 2nd row.

> Isn't there only one row in the template?

Not from what I inferred  from his original code.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Snikeris  
View profile  
 More options Mar 30 2012, 9:29 am
From: Joe Snikeris <j...@snikeris.com>
Date: Fri, 30 Mar 2012 09:29:58 -0400
Local: Fri, Mar 30 2012 9:29 am
Subject: Re: [enlive] Re: filling rows from struct-map

On Fri, Mar 30, 2012 at 9:25 AM, Christophe Grand <christo...@cgrand.net> wrote:
> On Fri, Mar 30, 2012 at 3:22 PM, Joe Snikeris <j...@snikeris.com> wrote:

>> >  It is there to select (and clone) teh 2nd row.

>> Isn't there only one row in the template?

> Not from what I inferred  from his original code.

Ah, gotcha. Thanks for the solution and subsequent discussion.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Mar 30 2012, 9:38 am
From: gwanwyn <vesna.petko...@gmail.com>
Date: Fri, 30 Mar 2012 06:38:10 -0700 (PDT)
Local: Fri, Mar 30 2012 9:38 am
Subject: Re: filling rows from struct-map

I tried this

[[:tr (attr= :title "event")]]

to select the row, but now it's completely out. Trying some more....


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Apr 3 2012, 12:17 pm
From: gwanwyn <vesna.petko...@gmail.com>
Date: Tue, 3 Apr 2012 09:17:51 -0700 (PDT)
Local: Tues, Apr 3 2012 12:17 pm
Subject: Re: filling rows from struct-map

I'd answer sooner, but was heavy with flu.
This is what deftemplate should look like, it works fine.

(deftemplate indeks table-template [{:keys  [title event-data]}]
  [:title] (html/content title)
  [[:tr (nth-child 2)]] (html/clone-for [event event-data]
                        [:td] (fn [td] (assoc td :content [(-> td :attrs
:title mapping event)]))));show the page


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierre-Henry Perret  
View profile  
 More options Apr 17 2012, 9:01 am
From: Pierre-Henry Perret <phper...@gmail.com>
Date: Tue, 17 Apr 2012 06:01:07 -0700 (PDT)
Local: Tues, Apr 17 2012 9:01 am
Subject: Re: filling rows from struct-map

Hi gwanwyn,

I've tried indexks template with this event-data:
_________________________________
(def content-t
  {:title "Events Mashup"
   :event-data
              {:event-name "event name 1"
                :performer "performer 1"
                :date "date 1"
                :start-time "start time 1"
                :end-time "start time 1"}
   })
_______________________

And it doesnt work. Is there something incorrect in the data ?

Le mardi 3 avril 2012 18:17:51 UTC+2, gwanwyn a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierre-Henry Perret  
View profile  
 More options Apr 17 2012, 9:34 am
From: Pierre-Henry Perret <phper...@gmail.com>
Date: Tue, 17 Apr 2012 06:34:40 -0700 (PDT)
Local: Tues, Apr 17 2012 9:34 am
Subject: Re: filling rows from struct-map

I've tried gwanwyn's code with that content:
__________________________
(def content-t
  {:title "Events Mashup"
   :cont "voici le contenu"
   :event-data
              {:event-name "event name 1"
                :performer "performer 1"
                :date "date 1"
                :start-time "start time 1"
                :end-time "start time 1"}
   })
______________________________

But it produces nothing.

Am I correct ?

Le mardi 3 avril 2012 18:17:51 UTC+2, gwanwyn a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Apr 17 2012, 9:48 am
From: gwanwyn <vesna.petko...@gmail.com>
Date: Tue, 17 Apr 2012 06:48:38 -0700 (PDT)
Local: Tues, Apr 17 2012 9:48 am
Subject: Re: filling rows from struct-map

You should put event-data in square brackets, like this
[{ :event-name "event name 1"
                         :performer "performer 1"
                         :date "date 1"
                          :start-time "start time 1"
                         :end-time "end time 1"}]

Hope this solves your problem...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierre-Henry Perret  
View profile  
 More options Apr 17 2012, 10:12 am
From: Pierre-Henry Perret <phper...@gmail.com>
Date: Tue, 17 Apr 2012 07:12:51 -0700 (PDT)
Local: Tues, Apr 17 2012 10:12 am
Subject: Re: filling rows from struct-map

Nope.. yest not !

Does your template only contains a tr like that :
_________________________
<tr>
<td title="event-name">Event Title 1</td>
<td title="performer">Performer1</td>
<td title="date">Date1</td>
<td title="start-time">Start time1</td>
<td title="end-time">End time1</td>

</tr>
___________________

?
Le mardi 17 avril 2012 15:48:38 UTC+2, gwanwyn a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Apr 17 2012, 3:31 pm
From: gwanwyn <vesna.petko...@gmail.com>
Date: Tue, 17 Apr 2012 12:31:49 -0700 (PDT)
Local: Tues, Apr 17 2012 3:31 pm
Subject: Re: filling rows from struct-map

it works for me, my template contains 2 trs, one for the header, and the
other for the row, here it is
<tr class="main">
<td >Event Title</td>
 <td>Performer</td>
 <td>Date</td>
 <td>Start time</td>
 <td>End time</td>
<tr title="event">
<td title="event-title">Event Title 1</td>
<td title="performer">Performer1</td>
<td title="date">Date1</td>
<td title="start-time">Start time1</td>
<td title="end-time">End time1</td>

</tr>

hope, you'll find the solution.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierre-Henry Perret  
View profile  
 More options Apr 17 2012, 4:10 pm
From: Pierre-Henry Perret <phper...@gmail.com>
Date: Tue, 17 Apr 2012 13:10:03 -0700 (PDT)
Local: Tues, Apr 17 2012 4:10 pm
Subject: Re: filling rows from struct-map

Thanks, and sorry for the spam, the groups client told me a message was
suppressed, so I wrote another...
which resulted in two posts!

Le mardi 17 avril 2012 21:31:49 UTC+2, gwanwyn a écrit :

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gwanwyn  
View profile  
 More options Apr 17 2012, 4:13 pm
From: gwanwyn <vesna.petko...@gmail.com>
Date: Tue, 17 Apr 2012 13:13:26 -0700 (PDT)
Local: Tues, Apr 17 2012 4:13 pm
Subject: Re: filling rows from struct-map

everything is ok. bonne chance!

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »