Using Closure

Note-to-myself:

  1. Make the xyz.soy file. First line should contain {namespace  namespace_name} defining a name for your namespace.
  2. Define function calls inside the soy file using the format below, replacing abc with your HTML template and code:

    /**
    * function_name function description
    * @param? param1 description
    * @param param2 description
    */
    {template .function_name}
    <templating code>
    {/template}

  3. Compile the xyz.soy file into a .js file using the following command (You’ll need java runtime installed. I used Sun’s jre 6):

    java -jar [path_to_Closure_folder]/SoyToJsSrcCompiler.jar –outputPathFormat ‘[filename_format].js’ xyz.soy

    You can get more details about what can be used in outputPathFormat here.

  4. Import the generated javascript code file and the soyutils.js into your html file (before the main.js where templating functions will be called):


    <script type=”text/javascript” src=”script/[path_to_Closure_folder/]soyutils.js”></script>
    <script type=”text/javascript” src=”script/[generated_js_filename].js”></script>

  5. Call the templating functions as namespace_name.function_name(params) from anywhere in main.js or the HTML code.
  6. Done :)

Refer to:

Now, done.

P.S.: Finally finished moving the code through Closure templates. Now can begin normal development again.