Last active
December 27, 2015 04:49
-
-
Save dcbriccetti/7269649 to your computer and use it in GitHub Desktop.
Simple example of rendering a tree with Lift, without using templates (not that this is a good thing). Yields: - Root 1 A 1 A1 2 A2 2 B
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
package org.example.snippet | |
import scala.xml.NodeSeq | |
class Tree { | |
def render = { | |
case class N(label: String, children: Seq[N]) | |
def renderTree(node: N): NodeSeq = { | |
<li> | |
{node.label} | |
<ol> | |
{node.children.flatMap(renderTree)} | |
</ol> | |
</li> | |
} | |
val tree = | |
N("Root", Seq( | |
N("A", Seq( | |
N("A1", Nil), | |
N("A2", Nil))), | |
N("B", Nil))) | |
<ul>{renderTree(tree)}</ul> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment