Clarification on CSS "^^" modifier

53 views
Skip to first unread message

Derek Chen-Becker

unread,
Jan 14, 2011, 3:43:34 PM1/14/11
to liftweb
So, I can use it to select a given element out of multiple, but then can you do anything further with it? Looking at the code it appears the the node is simply returned from treatElem but I'm not 100% positive. I tried a sample template:

<p>Total: <span id="total">$0</span></p>

And a binding:

"#total ^^" #> "$42"

And the result is

<span id="total">$0</span>

I also tried

"#total ^^" #> {
  "#total" #> "$42"
}

With the same result.

Thanks,

Derek

Naftoli Gugenheim

unread,
Jan 14, 2011, 3:52:52 PM1/14/11
to liftweb
Does this help at all?

scala> import net.liftweb.util.Helpers._
import net.liftweb.util.Helpers._

scala> val b = "#total ^^" #> {ns: xml.NodeSeq => println(ns); ns}
b: net.liftweb.util.CssBind = <function1>

scala> b(<p>Total: <span id="total">$0</span></p>)
res0: scala.xml.NodeSeq = NodeSeq(<span id="total">$0</span>)

scala> val b1 = "#total" #> {ns: xml.NodeSeq => println(ns); ns}
b1: net.liftweb.util.CssBind = <function1>

scala> b1(<p>Total: <span id="total">$0</span></p>)
<span id="total">$0</span>
res1: scala.xml.NodeSeq = NodeSeq(<p>Total: <span id="total">$0</span></p>)

Derek Chen-Becker

unread,
Jan 14, 2011, 4:04:45 PM1/14/11
to lif...@googlegroups.com
Well, no :(

I know that it promotes the selected element to be the root of the returned element from the transform. I was just confirming that you can't achieve any further transform with it.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

David Pollak

unread,
Jan 14, 2011, 5:42:27 PM1/14/11
to lif...@googlegroups.com
On Fri, Jan 14, 2011 at 12:43 PM, Derek Chen-Becker <dchen...@gmail.com> wrote:
So, I can use it to select a given element out of multiple, but then can you do anything further with it? Looking at the code it appears the the node is simply returned from treatElem but I'm not 100% positive. I tried a sample template:

<p>Total: <span id="total">$0</span></p>

And a binding:

"#total ^^" #> "$42"

The ^^ operation is a replacement for selectTemplate... it allows you to select the subsection of the template and then applies the rest of the CSS Selector Transforms to that... the parameter is ignored.

<div><span id="a">howdy</span><div id="b">dude</div></div>

"#a ^^" #> "ignore" & "* *" #> "hello" // <span id="a">hello</span>

"#b ^^" #> "ignore" & "* [style]" #> "woof" // <div style="woof">dude</div>

 

And the result is

<span id="total">$0</span>

I also tried

"#total ^^" #> {
  "#total" #> "$42"
}

With the same result.

Thanks,

Derek

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Derek Chen-Becker

unread,
Jan 14, 2011, 7:22:57 PM1/14/11
to lif...@googlegroups.com
Ah, cool. I didn't think about the "* *" selector.

Naftoli Gugenheim

unread,
Jan 16, 2011, 6:48:15 PM1/16/11
to liftweb
Oh that's what it does! Is it new? I really have to use it. :)

drwho

unread,
Feb 15, 2011, 7:52:09 AM2/15/11
to lif...@googlegroups.com
puzzled.

On Friday, January 14, 2011 11:42:27 PM UTC+1, David Pollak wrote:


On Fri, Jan 14, 2011 at 12:43 PM, Derek Chen-Becker <dchen...@gmail.com> wrote:

...
 
The ^^ operation is a replacement for selectTemplate... it allows you to select the subsection of the template and then applies the rest of the CSS Selector Transforms to that... the parameter is ignored.

...

but why do i get the following:


scala> val x = <div><div id="red">red branch and span <span id="redcolor">XXX</span></div>
     | <div id="blue">blue branch and span <span id="bluecolor">XXX</span></div></div>
x: scala.xml.Elem =
<div><div id="red">red branch and span <span id="redcolor">XXX</span></div>
<div id="blue">blue branch and span <span id="bluecolor">XXX</span></div></div>

scala> ("#red ^^" #> "ignore" & "#redcolor *" #> Text("RED"))(x)
res17: scala.xml.NodeSeq = NodeSeq(<div id="red">red branch and span <span id="redcolor">XXX</span></div>)

 instead of

res18: scala.xml.NodeSeq = NodeSeq(<div id="red">red branch and span <span id="redcolor">RED</span></div>)

from your comment i'd expected the "#redcolor *" #> Text("RED") to apply to the <span id="redcolor">XXX</span> then. puzzled.
Reply all
Reply to author
Forward
0 new messages