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.

Yes Yes Yes Yes Yes Yes Yessssssss! Ahh.. the joy of a overcoming a tiny, but hugely irritating hurdle. Like that piece of chicken stuck between teeth.

Just got the Closure template working to do a listAll, after a day and half of struggling :)

A night of suffering

The refactoring continues.

After moving all xhr calls from JSON to html, backed by django templating on the server, realised that in order to implement offline, localStorage based system, I still need to generate html at the browser. I could have taken the old, working version with html generating via js strings but it will need another load of work when the design of page starts changing. So, spent the night researching browser-based templating systems. Have shortlisted three – mustache, Closure and Pure. All seem to be taking strange approaches. So far Closure seems to be the one I’ll go with, but the final call will happen tomorrow after some more research.

Meanwhile, the pen drive finally seems to have filled up, so can’t work off it anymore. Have saved all that I wanted to in dropbox and in bookmark syncs. Gonna reformat and recreate the live USB now so I can start working again tomorrow. The new laptop still isn’t featured on dell website though people have started talking about it on twitter. Seems like it’ll be another week or so before I finally get my hands on it and can create a full development environment. The new liveUSB should last till then, I hope.

Time to sleep now. Ciao.