ibm-js/delite — pull request #207 by wkeese (2014-06-28 02:05:54+00:00)
Title: Handlebars simplifications (second try)

Opening this PR in preference to #191.

---
This first change is to support a `data-requires="..."` attribute in templates to load specified AMD modules:

```xml

```

This means that `delite/handlebars!` used as a plugin can compile any template, even if it contains widgets, without those widgets already being loaded. It will help with builds and is probably a good idea in general. The syntax is up for debate though.

Inadvertently fixes #159.

---

The second change, from @sbrunot's suggestion, is to create
`delite/Templated`, a mixin used by widgets with templates, in conjunction with `delite/handlebars!`.

Extending `delite/Templated` rather than `delite/Widget` has two effects:

(1) You specify the template via the `template` property rather than `buildRendering()` method:

```js
define(["delite/register", "delite/Templated", "delite/handlebars!./template/MyTemplate.html"],
function (register, Templated, template){

register("my-widget", [HTMLElement, Templated], {
template: template
});
});
```

instead of:

```js
define(["delite/register", "delite/Widget", "delite/handlebars!./template/MyTemplate.html"],
function (register, Widget, template){

register("my-widget", [HTMLElement, Widget], {
buildRendering: template
});
});
```

(2) It allows subclasses of a Templated widget to more easily inline a template definition:

```js
define(["delite/register", "delite/SuperClass"],
function (register, SuperClass){

register("my-sub-widget", [SuperClass], {
template: ""
});
});
```

rather than:

```js
define(["delite/register", "delite/SuperClass", "delite/handlebars"],
function (register, SuperClass, handlebars){

register("my-sub-widget", [SuperClass], {
template: handlebars.compile("")
});
});
```

However, this usage will likely require downloading handlebars to the client, even after a build, so it's not recommended except for RAD.