3

I faced a problem while using Google Closure Soy templates. When I change a template I need to run a script from command line to compile Soy template to JS file. Is there a service or something else to rebuild these templates automatically?

Also, as far as I know, "plovr" service is able to rebuild JS sources with closure compiler automatically. Is there a way to rebuild soy templates and put them to specified folder by plovr automatically?

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
Just_Mad
  • 4,029
  • 3
  • 22
  • 30

1 Answers1

2

Plovr will automatically compile Closure Templates (soy files) along with JavaScript sources.

If your project had the following file structure, you could use the plovr config file shown below.

/home/my/project
         |-- build
         |-- js
             |-- myapp.js
         |-- soy
             |-- mytemplate.soy

plovr_config.json

{
  "id": "myapp",
  "inputs": [
    "/home/my/project/js/myapp.js"
  ],
  "paths": [
    "/home/my/project/soy"
  ],
  "mode": "ADVANCED",
  "level": "VERBOSE",
  "output-file": "/home/my/project/build/myapp.compiled.js"
}

During development, you would configure a <script> tag in your HTML file to automatically recompile your JavaScript and Closure Templates after launching the plovr server:

java -jar plovr.jar serve plovr_config.json 

index.html

<!doctype html>
<html>
<head>
  <title>My App</title>
</head>
<body>

<h1>My App</h1>

<script src="http://0.0.0.0:9810/compile?id=myapp"></script>

</body>
</html>
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • Ok, plovr compiles soy templates automatically if I specify a path to them, but how can I set a folder to put these compiled templates to? – Just_Mad Aug 30 '12 at 07:11
  • Plovr automatically compiles soy templates to JavaScript and places the compiled templates in the final output file. This even works using plovr's `raw` mode. Although plovr makes it very easy to integrate client-side Soy templates with your application, plovr does not offer the level of control provided by using `SoyToJsSrcCompiler.jar` directly. – Christopher Peisert Aug 30 '12 at 16:16