SBT Scalate Template Compiler
Generates scala from scalate templates and compiles them to class files. This is useful to deploy templates to a restrictive environment like Google App Engine.
Because sbt 0.7.4 is scala 2.7.7 based it can't directly use scalate which is based in scala 2.8.0; so the project is based in two parts: a 2.8.0 based generator and the plugin proper which invokes the generator as an external process.
The artifacts do not live in any repo yet so you must build them yourself.
Clone the repo and do
sbt update && sbt publish-local first in the compiler subdirectory and then in the plugin subdirectory.
Then look at the test subdirectory which contains a test project for an example configuration.
The plugin assumes the templates live in
src/main/templates if you prefer otherwise, in the project definition override
templateRoots like this
override def templateRoots = mainSourcePath / "resources"
The plugin redefines the compile action to depend on two more actions:
precompileScalate which generates scala code from the templates and
compileScalate which compiles that code to class files with the same compiler sbt compiles the rest of the sources.
If you run
~ compile or
~ prepare-webapp sbt recompiles the templates when you save them.
Google App Engine
If you deploy to google app engine you must set this properties in your app.yaml
system_properties: scalate.allowReload: false scalate.workdir: WEB-INF
If you are an xml lover and use appengine-web.xml :
<system-properties> <property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" /> <property name="scalate.allowReload" value="false"/> <property name="scalate.workdir" value="WEB-INF"/> </system-properties>
I think this can be set programatically, too.
For a sample servlet look at Yasushi Abe's hello-scalate-appengine's template servlet. I will upload a sample project soon.
- I have not fully tested this yet so use with caution: it may eat your soul and burn your house.
While it generates code, compiles it and the class files end in WEB-INF/classes, GAE still complains:
java.security.AccessControlException: access denied (java.io.FilePermission /index.ssp read). I need to check with the people in Scalate's ML because I thought it would load the class and not the file.
- Make a GAE/J sample app.
- Replace separators with correct platform independent separators.
- Make a clean action.
- Write tests.
- Automate the full building thing ( Apparently sbt does not like to build projects with mixed scala versions ).
Stop using MainCompilerConfig. BUG Generates code into mainSources triggering compilation twice when using
~ compileor similar. This was my original problem ( original code entered into a loop ).