Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ref #884. There is some double-merging of class attributes. Added a t…

…est and fixed the double merge
  • Loading branch information...
commit 0f0c68843a3632e12db125709a3d31304a9a2446 1 parent 432cce5
@dpp dpp authored
View
23 core/util/src/main/scala/net/liftweb/util/BindHelpers.scala
@@ -1910,6 +1910,23 @@ private class SelectorMap(binds: List[CssBind]) extends Function1[NodeSeq, NodeS
final def applyRule(bind: CssBind, realE: Elem): NodeSeq = {
+ def uniqueClasses(cv: String*): String = {
+ import Helpers._
+
+ val ls: List[String] = cv.toList.flatMap(_.charSplit(' '))
+ import scala.collection.mutable._
+ val hs: HashSet[String] = new HashSet()
+ val ret: ListBuffer[String] = new ListBuffer()
+ ls.foreach {
+ v =>
+ if (!hs.contains(v)) {
+ hs += v
+ ret += v
+ }
+ }
+ ret.mkString(" ")
+ }
+
def mergeAll(other: MetaData, stripId: Boolean): MetaData = {
var oldAttrs = attrs - (if (stripId) "id" else "")
@@ -1926,8 +1943,10 @@ private class SelectorMap(binds: List[CssBind]) extends Function1[NodeSeq, NodeS
case Some(ca) => {
oldAttrs -= "class"
builtMeta = new UnprefixedAttribute("class",
- up.value.text + " "+
- ca, builtMeta)
+ uniqueClasses(up.value.
+ text,
+ ca),
+ builtMeta)
}
case _ => builtMeta = up.copy(builtMeta)
View
37 core/util/src/test/scala/net/liftweb/util/BindHelpersSpec.scala
@@ -354,6 +354,43 @@ object CssBindHelpersSpec extends Specification {
("#foo" #> "hello")(<b><span id="foo"/></b>) must ==/ (<b>hello</b>)
}
+
+ "not duplicate classes" in {
+
+ def anchor(quesType: String, value: String) = {
+ <a href="foo" class="selected">(value)</a>
+ }
+ var page = 1
+ var elements = List("1","2","3","4")
+
+ val xml = <div class="lift:Bug.attack bug">
+ <div id="question" class="question">
+ <a href="#" class="L">1</a>
+ <a href="#" class="U">1</a>
+ <a href="#" class="D">1</a>
+ </div>
+ <div class="navigation">
+ <button class="previous">Previous</button> <button class="next">Next</button>
+ </div>
+ </div>
+
+ val sel = ".question" #> elements.map(value => {
+ ".question [id]" #> ("question-" + value) &
+ ".question [class]" #> ("question-" + value) &
+ ".L" #> anchor("L", value) &
+ ".U" #> anchor("U", value) &
+ ".D" #> anchor("D", value)
+ })
+
+ val res = sel(xml)
+
+ println(res)
+
+ ((res \\ "a").head \ "@class").head.text must_== "selected L"
+
+ }
+
+
"Compound selector" in {
val res =
(".foo [href]" #> "http://dog.com" & ".bar [id]" #> "moo").apply(
Please sign in to comment.
Something went wrong with that request. Please try again.