angular-app/angular-app — pull request #6 by petebacondarwin (2012-09-18 09:26:48+00:00)
Title: Partials

Hi Pawel,
I have done a bit of a rewrite on the partial compiling/loading. Can you take a look? I have implemented the same strategy that Vojta uses but with a bit of tweaking. This method has the aesthetic benefit of not polluting our index.html with processing instructions and loads of html. It also has performance benefits: the script directive does not have to parse and compile the html itself and the generated template js can be minified and compressed for download.

All the basic tasks still work: default, build, release, watch, watch-test, etc.

The concatPartials and the processing instructions inside the index.html are now gone. There is a new task called html2js, which gets its config from the html2js config section in grunt.js.

All the templates are compiled into a javascript call to directly add the the html to the template cache.

Each compiled template is inside its own module. This means that you can load them up (i.e. concat them) in any order. But that also means that you have to include the template as a dependency of your app for them to be executed. I managed this by having a module called "templates", which is generated by the html2js task. This module simply depends upon all the generated template modules. Now we simply get the "app" module to depend upon the "templates" module.

Finally, the "id" of the template is take from its file path. I have made it a little more palatable by having a "base" config value that lets us strip off the "src/modules" bit of the path, but I was reluctant to start hard coding in removal of the "partial" folder from the path. This means that that id of the templates is along the lines of "admin/partials/project-edit.tpl.html" rather than "admin/project-edit.tpl.html". I have changed all references to partials in the code to deal with this. If it really is a problem then we can either hard code in a removal of the partials bit of the path or we can move the partials up a level out of the partials folder.