Created
February 26, 2013 15:10
-
-
Save chrhicks/5039126 to your computer and use it in GitHub Desktop.
Traversing a handlebars.scala Program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ProgramHelper { | |
def filter(node: Node)(implicit filterFn: Node => Boolean): List[Node] = { | |
(if (filterFn(node)) List(node) else List()) ++ (node match { | |
case n:Path => n.value.flatMap(filter(_)) | |
case n:Partial => filter(n.value) | |
case n:Mustache => filter(n.value) ++ n.parameters.flatMap(filter(_)) | |
case n:Section => filter(n.name) ++ filter(n.value) | |
case n:Program => n.value.flatMap(filter(_)) ++ n.inverse.map(filter(_)).getOrElse(List()) | |
case _ => List() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment