Permalink
Browse files

Closes #971. Added a test to insure that attributes are set even if t…

…he transform is transforming the Elem
  • Loading branch information...
1 parent f7da1d3 commit 6c58e20cf0d86b2e763ccd0c28794931f26088d5 @dpp dpp committed May 14, 2011
@@ -2011,7 +2011,7 @@ private class SelectorMap(binds: List[CssBind]) extends Function1[NodeSeq, NodeS
}
-
+ // This is where the rules are applied -- DPP HERE
final def applyRule(bind: CssBind, realE: Elem): NodeSeq = {
def uniqueClasses(cv: String*): String = {
import Helpers._
@@ -2120,62 +2120,6 @@ private class SelectorMap(binds: List[CssBind]) extends Function1[NodeSeq, NodeS
}
}
}
-
- /*
- case Full(AttrSubNode(attr)) => {
- val calced = bind.calculate(realE)
- val filtered = realE.attributes.filter{
- case up: UnprefixedAttribute => up.key != attr
- case _ => true
- }
-
- val newAttr = if (calced.isEmpty) {
- filtered
- } else {
- val flat: NodeSeq = calced.flatMap(a => a)
- new UnprefixedAttribute(attr, flat, filtered)
- }
-
- new Elem(realE.prefix,
- realE.label, newAttr,
- realE.scope, SelectorMap.this.apply(realE.child) :_*)
- }
-
- case Full(AttrAppendSubNode(attr)) => {
- val org: NodeSeq = realE.attribute(attr).getOrElse(NodeSeq.Empty)
- val calced = bind.calculate(realE).toList
-
-
- if (calced.isEmpty) {
- realE
- } else {
- val filtered = realE.attributes.filter{
- case up: UnprefixedAttribute => up.key != attr
- case _ => true
- }
-
- val flat: NodeSeq = if (attr == "class") {
- if (org.isEmpty) {
- calced.dropRight(1).flatMap(a => a ++ Text(" ")) ++
- calced.takeRight(1).head
- } else {
- org ++ Text(" ") ++
- calced.dropRight(1).flatMap(a => a ++ Text(" ")) ++
- calced.takeRight(1).head
- }
- } else {
- org ++ (calced.flatMap(a => a): NodeSeq)
- }
-
- val newAttr = new UnprefixedAttribute(attr, flat, filtered)
-
- new Elem(realE.prefix,
- realE.label, newAttr,
- realE.scope, SelectorMap.this.apply(realE.child) :_*)
-
- }
- }
- */
case x: EmptyBox => {
val calced = bind.calculate(realE)
@@ -421,6 +421,14 @@ object CssBindHelpersSpec extends Specification {
xf(<div/>)
}
+ "support modifying attributes along with body" in {
+ val org = <a>foo</a>
+ val func = "a [href]" #> "dog" & "a *" #> "bar"
+ val res = func(org)
+
+ res.toString must_== "<a href=\"dog\">bar</a>"
+ }
+
"substitute a String by id" in {
("#foo" replaceWith "hello")(<b><span id="foo"/></b>) must ==/ (<b>hello</b>)
}

0 comments on commit 6c58e20

Please sign in to comment.