ibm-js/delite — pull request #191 by wkeese (2014-06-18 02:37:47+00:00)
Title: Create Templated base class as simpler interface than handlebars! plugin.

@sbrunot suggested that widgets (or at least, his ListItem widget) have an easier
way for users to redefine a widget's template.

The current approach is:

define([..., "delite/handlebars!./templates/MyTemplate.html"], function(..., renderFunc){
...
buildRendering: renderFunc,
...
}

If your template contains other widgets that need to be loaded, then you use handlebars as a plain AMD module, via the `compile()` method:

define([..., "delite/handlebars"], function(..., handlebars){
...
buildRendering: handlebars.compile(
'{{label}}'
),
...
}

(Of course, the string could be loaded via `requirejs-text/text!` rather than inlined.)

The new approach would be:

```
define([...,
"delite/Templated",
"requirejs-text/text!myTemplate.html"
], function (Templated, template) {
return register("my-widget", [Templated], {
template: template
});
);
```

The new approach is simpler, in particular for when you have widgets in templates, and also hides some of the machinery of how templates work. The only downsides I see are that:

1. It gives the *impression* that we only support delite/handlebars as a way to do templates. In actuality though, nothing has changed; an app can still plug in its own engine. CC @cjolif, @pruzand since I remember @cjolif kept talking about plug-and-play of template engines. Perhaps the base class should be called `HandlebarsTemplated` or something more specific, rather than just `Templated`?
2. Builds - This makes it harder for the build to precompile templates. Currently the build tool only inlines strings, but ideally, eventually, it should precompile templates in order to speed up initial page render, and to avoid downloading handlebars.js and template.js to the browser. I don't know how important those goals are in practice though so maybe we should forget about them. CC @clmath.

TODO: Remove support for using handlebars! as a plugin. No reason to have two ways to do the same thing.