Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Got java.lang.Number working for CSS Selector Transforms

  • Loading branch information...
commit 0b6145eb6e681c0811e7bc651e19220a1f4189b4 1 parent e3b2e10
@dpp dpp authored
View
15 core/util/src/main/scala/net/liftweb/util/CssSel.scala
@@ -723,6 +723,15 @@ object ComputeTransformRules {
def computeTransform(str: => Bindable, ns: NodeSeq): Seq[NodeSeq] = List(str.asHtml)
}
+
+ implicit def numberTransform[T <: java.lang.Number]: ComputeTransformRules[T] = new ComputeTransformRules[java.lang.Number] {
+ def computeTransform(str: => java.lang.Number, ns: NodeSeq): Seq[NodeSeq] = {
+ val num = str
+ List(if (null eq num) NodeSeq.Empty else Text(num.toString))
+ }
+ }
+
+
implicit def jsCmdTransform: ComputeTransformRules[ToJsCmd] = new ComputeTransformRules[ToJsCmd] {
def computeTransform(str: => ToJsCmd, ns: NodeSeq): Seq[NodeSeq] = List(Text(str.toJsCmd))
}
@@ -791,6 +800,12 @@ object ComputeTransformRules {
def computeTransform(info: => T[String], ns: NodeSeq): Seq[NodeSeq] = f(info).toSeq.map(a => Text(a))
}
+ implicit def iterableNumberTransform[T[_], N <: java.lang.Number](implicit f: T[N] => Iterable[N]): ComputeTransformRules[T[N]] =
+ new ComputeTransformRules[T[N]] {
+ def computeTransform(info: => T[N], ns: NodeSeq): Seq[NodeSeq] = f(info).toSeq.flatMap(a =>
+ if (a eq null) Nil else List(Text(a.toString)))
+ }
+
implicit def iterableBindableTransform[T[_]](implicit f: T[Bindable] => Iterable[Bindable]): ComputeTransformRules[T[Bindable]] =
new ComputeTransformRules[T[Bindable]] {
def computeTransform(info: => T[Bindable], ns: NodeSeq): Seq[NodeSeq] = Helpers.ensureUniqueId(f(info).toSeq.map(_.asHtml))
View
1  core/util/src/main/scala/net/liftweb/util/CssSelector.scala
@@ -156,6 +156,7 @@ object CssSelectorParser extends PackratParsers with ImplicitConversions {
private def fixAll(all: List[CssSelector], sn: Option[SubNode]): CssSelector = {
(all, sn) match {
+ // case (Nil, Some())
case (r :: Nil, None) => r
case (r :: Nil, Some(sn)) => r.withSubnode(sn)
case (lst, None) => lst.reduceRight((b, a) => EnclosedSelector(b, a))
View
30 core/util/src/test/scala/net/liftweb/util/BindHelpersSpec.scala
@@ -650,6 +650,36 @@ object CssBindHelpersSpec extends Specification {
}
+ "Java number support" in {
+ val f = "a *" #> Full(new java.lang.Long(12))
+ val xml = <a>Hello</a>
+
+ f(xml) must ==/ (<a>12</a>)
+ }
+
+
+ "Andreas's thing doesn't blow up" in {
+ def cachedMessageList: Box[Box[String]] = Empty
+
+ def messageListId = "Hello"
+
+ def collapseUnless[A](isEmptyCond: Boolean)(f: => A): Box[A] = {
+ if (!isEmptyCond) {
+ Empty
+ } else {
+ Full(f)
+ }
+ }
+
+ ".noMail" #> collapseUnless(cachedMessageList.map(_.isEmpty).openOr(true)) {
+ "tbody [id]" #> messageListId &
+ "*" #> PassThru
+ }
+
+ true must_== true
+ }
+
+
"option transform on *" in {
val opt: Box[String] = Empty
val res = ("* *" #> opt.map(ignore => "Dog")).apply(<top>cat</top>)
View
1  core/util/src/test/scala/net/liftweb/util/CssSelectorSpec.scala
@@ -50,6 +50,7 @@ object CssSelectorSpec extends Specification {
AttrSelector("type", "button", Empty)
}
+
":checkbox must parse" in {
CssSelectorParser.parse(":checkbox").open_! must_==
AttrSelector("type", "checkbox", Empty)
Please sign in to comment.
Something went wrong with that request. Please try again.