Reputation: 24052
I'm trying to work through some Lift examples using CSS Selector Transforms. I'm attempting this sort of transformation:
- NodeSeq => NodeSeq — a function that transforms the node (yes, it can be a CssBindFunc):
"#name" #> ((n: NodeSeq) => n % ("class" -> "dog")) // <span id="name"/> -> <span id="name" class="dog"/>
It's the %
that's giving me trouble right now. When I try to write code like this, I get the error value % is not a member of scala.xml.NodeSeq
. Is there an import or something that I'm missing?
Here's my snippet:
import scala.xml._
import net.liftweb.util.Helpers._
import model.User
class Users {
def show = {
".userName" #> "name replaced" &
".userEmail" #> "email replaced" &
".changePassword" #> ((n: NodeSeq) => n % ("href" -> "changePassword"))
}
}
Upvotes: 2
Views: 1229
Reputation: 1
Here is the way to do what you want. It's pretty much equivalent but it doesn't throw any error.
import scala.xml._
import net.liftweb.util.Helpers._
scala> val res1 = "#name" #> ((n:NodeSeq) => ("* [class]" #> "dog")(n))
res1: net.liftweb.util.CssSel = CssBind(Full(#name), Full(IdSelector(name,Empty)))
scala> res1(<span id="name"/>)
res2: scala.xml.NodeSeq = NodeSeq(<span id="name" class="dog"></span>)
Upvotes: 0
Reputation: 167901
Only Elem
contains the %
method. NodeSeq
is not an Elem
, but a collection of Node
s, which may or may not be Elem
s. And I'm not sure if Lift's helpers include implicits to create MetaData
, but if not, you'd need something like
myNodeSeq map {
case e: Elem => e % new UnprefixedAttribute("href","changePassword",xml.Null)
case x => x
}
to cover the generic case.
Upvotes: 5