Permalink
Browse files

util: CanBind: apply changes from master

  • Loading branch information...
1 parent 5befd59 commit 1ae95c1df87bc610fa7f24363f962e78e71d104a @nafg nafg committed Oct 3, 2011
Showing with 23 additions and 13 deletions.
  1. +23 −13 core/util/src/main/scala/net/liftweb/util/CssBinding.scala
@@ -111,7 +111,12 @@ object CanBind {
* calling the StringPromotable's toString method and replacing content with it wrapped in a Text node.
* StringPromotable includes Int, Long, Boolean, and Symbol
*/
- implicit def stringPromotable[T](implicit view: T=>StringPromotable) = new CanBind[T](strPromo => _ => Text(view(strPromo).toString))
+ implicit def stringPromotable[T](implicit view: T=>StringPromotable) = new CanBind[T]({strPromo => _ =>
+ view(strPromo).toString match {
+ case null => NodeSeq.Empty
+ cases s => Text(s)
+ }
+ })
}
@@ -787,19 +792,24 @@ private class SelectorMap(binds: List[CssBind]) extends Function1[NodeSeq, NodeS
}
case n => {
- calced.toList.zipWithIndex.flatMap {
- case (Group(g), _) => g
- case (e: Elem, 0) =>
- new Elem(e.prefix,
- e.label, mergeAll(e.attributes, false),
- e.scope, e.child :_*)
- case (e: Elem, _) =>
- new Elem(e.prefix,
- e.label, mergeAll(e.attributes, true),
- e.scope, e.child :_*)
- case (x, _) =>
- x
+ val calcedList = calced.toList
+ val availableIds = (attrs.get("id").toList ++
+ calcedList.collect({ case e:Elem => e.attribute("id") }).flatten.map(_.toString)).toSet
+ val merged = calcedList.foldLeft((availableIds, Nil: List[Seq[xml.Node]])) { (idsAndResult, a) =>
+ val (ids, result) = idsAndResult
+ a match {
+ case Group(g) => (ids, g :: result)
+ case e:Elem => {
+ val targetId = e.attribute("id").map(_.toString) orElse (attrs.get("id"))
+ val keepId = targetId map { id => ids.contains(id) } getOrElse (false)
+ val newIds = targetId filter (_ => keepId) map (i => ids - i) getOrElse (ids)
+ val newElem = new Elem(e.prefix, e.label, mergeAll(e.attributes, ! keepId), e.scope, e.child: _*)
+ (newIds, newElem :: result)
+ }
+ case x => (ids, x :: result)
+ }
}
+ merged._2.reverse.flatten
}
}
}

0 comments on commit 1ae95c1

Please sign in to comment.