Question

A feature of the Play 2.0 framework I appreciate is statically compiled views. If a controller renders a view without supplying the correct number of well-typed arguments, a compile error is thrown. This greatly increases maintainability as controller<>view discrepancies don't have to be tested by running the application but appear at compile time instead.

However, the standard Play 2.0 view templates use plain HTML combined with Scala as a language. I want to use Scalate so I can combine Scala with the much less verbose Scaml or Jade templating languages. But I don't want to use Scalate to compile my views on runtime, because I'll lose the advantage of statically compiled views I've mentioned above.

Therefore, I've tried implementing static compilation of my Jade views using the xsbt-scalate-generator as described elsewhere. This only gets me halfway though - the plugin when configured correctly manages to produce corresponding .class files, but it names and packages them differently than normal Play 2.0 views. A default Play 2.0 view named index.scala.html gets compiled to a file index.class in the package views.html. However, a Jade view named index.jade creates a file $_scalate_$default_jade.class in the default (blank) package. This class is not importable and not usable in a Java Play 2.0 controller.

How can I generate the class files of my Scalate views in such a way that I could just write return ok(views.html.index.render(args)); in my controllers?

(It does appear the generated classes provide a method named render() at least)

Was it helpful?

Solution

I started out a plugin to do just that. Checkout my work on: https://github.com/kryptt/play2-scalate-plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top