Skip to content
mustache implementation for scala
Scala Java
Pull request Compare This branch is 10 commits behind mariusae:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


mustache.scala is an implementation of mustache for Scala. It does not at present support custom delimiters.

To render a template, a Mustache object must first be instantiated. This takes a, which has many convenience methods for reading files, strings, etc.

import org.monkey.mustache._
val mustache = new Mustache(io.Source.fromString(
  "{{helloworld}} {{#truefalse}}yes?{{/truefalse}}" + 
  "{{#falsetrue}}grr{{/falsetrue}}" +

Once the template is instantiated, it is rendered with a Dictionary. Dictionary provides a builder to create dictionaries:

val d = Dictionary()
  .data("helloworld", "hello, world!")
  .bool("truefalse", true)
      .data("v2", "iter0"))
      .data("v2", "iter1"))

The string is then rendered with Mustache.apply

scala> mustache(d)
res4: String = hello, world! yes?iter0iter1


mustache.scala uses ANTLR for parsing. This requires source files to be generated. Thus, the slightly modified sbt routine is necessary:

$ sbt update
$ sbt compile-antlr

This only needs to be run initially, and whenever the grammar has changed (src/main/antlr/Mustache.g).

maven / sbt

mustache.scala is published to the maven repo at To use with sbt, add the following lines:

val monkeyRepo = "" at ""
val mustache = "org.monkey" % "mustache" % "1.0"
Something went wrong with that request. Please try again.