Skip to content

Instantly share code, notes, and snippets.

@dcbriccetti
Last active December 27, 2015 04:49
Show Gist options
  • Save dcbriccetti/7269649 to your computer and use it in GitHub Desktop.
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
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