[Lift] CssSel and NodeSeq Question

50 views
Skip to first unread message

Daymo Brooks

unread,
Apr 16, 2012, 3:49:09 PM4/16/12
to lif...@googlegroups.com
Hi,

I have trouble finding out why my content is not being properly replaced. The only thing that is working in doLine is the addId stuff. None of the rest is being selected nor replaced. Can anyone say what am I missing?

Thanks in advance.
D.

<lift:comet type="articleUpdater">
<ul id="articles">
<div class="article">
<li class="entry">
<a href="#" class="link"></a> : <span id="category">Category</span>
</li>
</div>
</ul>
</lift:comet>

def render = "#articles *" #> lines _

private def lines(xml: NodeSeq): NodeSeq = {
bindLine = xml
for {
m <- articles.reverse
node <- doLine(m)
} yield node
}

private def doLine(m: Article): NodeSeq = {
( "*" #> addId(bindLine, m.id.is.toString) &
".link *" #> m.title.is &
".link [href]" #> "/article/%s".format(m.id.is) &
"#category" #> m.category.is)(bindLine)
}

private def addId(in: NodeSeq, id: String): NodeSeq = in map {
case e: Elem => e % ("id" -> id)
case x => x
}

Chenguang He

unread,
Apr 16, 2012, 4:27:53 PM4/16/12
to lif...@googlegroups.com
Hello guys,
Is there a download copy of this API http://scala-tools.org/mvnsites/liftweb-2.4-M5/#package  ?
i want to print it out.



Chenguang He




Antonio Salazar Cardozo

unread,
Apr 16, 2012, 5:33:03 PM4/16/12
to lif...@googlegroups.com
Lift's transforms don't apply twice to the elements when joined by &. You'll want to change the & after the "*" selector to andThen instead, which is a higher-level function combinator provided by Scala. It's slower (transforms joined by & are run at the same time, while andThen runs the function to the left and then the one to the right on its results), but in this case necessary.
Thanks,
Antonio

Daymo Brooks

unread,
Apr 17, 2012, 3:03:44 AM4/17/12
to lif...@googlegroups.com
Ah, I see. Works like a charm. Thank you. Is there a way to circumvent the situation with andThen and still using CssSel instead of the bind method in my particular situation?

Thanks,
D.


--- On Mon, 4/16/12, Antonio Salazar Cardozo wrote:

>Lift's transforms don't apply twice to the elements when joined by &.
>You'll want to change the & after the "*" selector to andThen instead,
>which is a higher-level function combinator provided by Scala. It's slower
>(transforms joined by & are run at the same time, while andThen runs the
>function to the left and then the one to the right on its results), but in
>this case necessary.
>Thanks,
>Antonio

Antonio Salazar Cardozo

unread,
Apr 17, 2012, 12:14:34 PM4/17/12
to lif...@googlegroups.com
You may be able to do "* [id]" #> m.id.toString, but I'm not sure.
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages