Permalink
Browse files

Added a test for star and also did the surround kids

  • Loading branch information...
1 parent 2674d4a commit c13b8f4dd398b9652107b1dce843ea2fb5680dcc @dpp dpp committed Aug 27, 2012
@@ -19,7 +19,7 @@ package util
import scala.util.parsing.combinator.{PackratParsers, Parsers, ImplicitConversions}
-import scala.xml.NodeSeq
+import xml.{Elem, NodeSeq}
import net.liftweb.common._
sealed trait CssSelector {
@@ -84,7 +84,20 @@ final case object DontMergeAttributes extends SubNode {
}
final case class SurroundKids() extends SubNode with WithKids {
- def transform(original: NodeSeq, newNs: NodeSeq): NodeSeq = newNs ++ original // FIXME
+ def transform(original: NodeSeq, newNs: NodeSeq): NodeSeq = {
+ var changed = false
+
+ val res: NodeSeq = newNs.flatMap{
+ case e: Elem if !changed =>
+ changed = true
+ new Elem(e.prefix,
+ e.label, e.attributes,
+ e.scope, e.child ++ original :_*)
+ case x => x
+ }
+
+ if (changed) res else newNs ++ original
+ }
}
final case class AppendKidsSubNode() extends SubNode with WithKids {
@@ -167,6 +180,7 @@ object CssSelectorParser extends PackratParsers with ImplicitConversions {
private lazy val topParser: Parser[CssSelector] =
phrase(rep1((_idMatch | _nameMatch | _classMatch | _attrMatch | _elemMatch |
_colonMatch | _starMatch) <~ (rep1(' ') | 26.toChar)) ~ opt(subNode)) ^^ {
+ case (one :: Nil) ~ sn => fixAll(List(one), sn)
case all ~ None if all.takeRight(1).head == StarSelector(Empty) =>
fixAll(all.dropRight(1), Some(KidsSubNode()))
case all ~ sn => fixAll(all, sn)
@@ -658,6 +658,13 @@ object CssBindHelpersSpec extends Specification {
}
+ "Surround kids" in {
+ val f = "a <*>" #> <div></div>
+ val xml = <b>Meow <a href="dog">Cat</a> woof</b>
+
+ f(xml) must ==/ (<b>Meow <a href="dog"><div>Cat</div></a> woof</b>)
+ }
+
"Andreas's thing doesn't blow up" in {
def cachedMessageList: Box[Box[String]] = Empty
@@ -679,6 +686,27 @@ object CssBindHelpersSpec extends Specification {
true must_== true
}
+ "other Andreas test" in {
+ def renderBlogEntrySummary = {
+ ".blogEntry" #> ((ns: NodeSeq) => {
+ ("*" #> "Horse").apply(ns)
+ })
+ }
+
+
+
+ def render = {
+
+ "*" #> ((ns: NodeSeq) =>
+ renderBlogEntrySummary.apply(ns) ++ <a>hi</a>
+ )
+ }
+
+ render
+
+ true must_== true
+ }
+
"option transform on *" in {
val opt: Box[String] = Empty

0 comments on commit c13b8f4

Please sign in to comment.