Skip to content

Instantly share code, notes, and snippets.

@stanch
Last active January 21, 2016 18:40
Show Gist options
  • Save stanch/a80b60db1a1b871efe8b to your computer and use it in GitHub Desktop.
Save stanch/a80b60db1a1b871efe8b to your computer and use it in GitHub Desktop.
Demo fragments for my talk “What can we learn from composable DSLs?”
object Utils {
val disableCache = respondWithHeaders(
`Cache-Control`(`no-cache`, `max-age`(0), `must-revalidate`, `no-store`),
`Expires`(DateTime.MinValue)
)
}
object BooksRoutes {
val routes = path("books" / Segment) { id =>
complete(id)
}
}
object AuthorRoutes {
val routes = path("authors" / "list") {
complete("Shakespear")
}
}
object Routes {
val routes = Utils.disableCache {
pathPrefix("v1" / "api") {
BookRoutes.routes ~ AuthorRoutes.routes
}
}
}
val large = TextTweaks.large + TextTweaks.italic
val adaptive = hdpi ? large | Tweaks.blank
val hello = widget[TextView] <~ text("Hello World!") <~ adaptive
val button = widget[Button] <~ text("Click me!")
layout[LinearLayout](
hello,
button
)
def nursery(teaser: String) = li(
em(teaser), " ", button("Show")
)
val lamb = nursery("Mary had a little lamb")
val star = nursery("Twinkle, twinkle, little star")
val rhymes = ul(lamb, star)
println(rhymes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment