Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created September 9, 2011 21:18
Show Gist options
  • Save guillaumebort/1207364 to your computer and use it in GitHub Desktop.
Save guillaumebort/1207364 to your computer and use it in GitHub Desktop.
Compiling Play 2.0 type safe templates
val ScalaTemplates = (sourceDirectory:File, generatedDir:File, templateTypes:Function1[String,(String,String)], additionalImports:String) => {
import play.templates._
(generatedDir ** "*.template.scala").get.map(GeneratedSource(_)).foreach(_.sync())
try {
(sourceDirectory ** "*.scala.html").get.foreach { template =>
ScalaTemplateCompiler.compile(template, sourceDirectory, generatedDir, templateTypes("html")._1, templateTypes("html")._2, additionalImports)
}
} catch {
case TemplateCompilationError(source, message, line, column) => {
throw TemplateCompilationException(source, message, line, column-1)
}
case e => throw e
}
(generatedDir ** "*.scala").get.map(_.getAbsoluteFile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment