Small hack to help keep me productive when using Google Closure Templates. This'll set an external filter for .soy files so that they can be compiled and returned as executable javascript. I've done this by modifying SoyToJsSrcCompiler to accept a new cmdline arg: --mattHack. If you pass --mattHack, then --outputPathFormat and passed-in soy filepaths will be ignored. If --mattHack is defined then SoyToJsSrcCompiler will spit stdin to a temporary file and pass that to SoyCompiler, business-as-usual. SoyCompiler will compile the template to a temporary file which SoyToJsSrcCompiler will then write to stdout. To get a compiled template, you can run this:
java -jar SoyToJsSrcCompiler.jar --mattHack<CoolSoyTemplate.soy
To get the above working w/ apache we'll setup an external filter to call node (which'll do all the heavy lifting). A filter, as defined by: ExtFilterDefine, will pipe what would've been apache's response to a subprocess AND THEN take the output from the subprocess and send that back to the browser (slash original requestor). So our filter will catch all requests to a .soy file and apply the CompileSoyTemplate filter. The CompileSoyTemplate filter will pass the contents of the .soy file to node which will pass that to SoyToJsSrcCompiler.jar with the --mattHack argument. Node then takes the response from SoyToJsSrcCompiler.jar and sends that back to apache, who then sends it to the browser (or wherever).
You can then reference that template directly from a script tag:
<script src="CoolSoyTemplate.soy"></script>
Or from a goog.require statement (assuming your deps.js is up to date :):
goog.require('Cool.Soy.Template');
Oh ya, to apply the SoyToJsSrcCompiler.java diff and build a new custom version SoyToJsSrcCompiler.jar, do the following:
svn checkout http://closure-templates.googlecode.com/svn/trunk/ closure-templates-src
patch -p0 -i SoyToJsSrcCompiler.java.diff
ant -f closure-templates-src/build.xml SoyToJsSrcCompiler
file closure-templates-src/build/SoyToJsSrcCompiler.jar
Also, sorry for the shitty java code. I'll update that. One day. Maybe. But probably not :/
Doh, 10 revisions just to get my markdown right