tildeio/htmlbars — pull request #176 by mmun (2014-11-30 20:11:24+00:00)
Title: Rewrite templates as objects

What's in your hand? Back at me. The templates are now objects.

Example:

```hbs
{{#each items as |item|}}
{{item.id}}: {{item.name}}
{{/each}}
```

now compiles to

```js
(function() {
var child0 = (function() {
return {
isHTMLBars: true,
cachedFragment: null,
build: function build(dom) {
var el0 = dom.createDocumentFragment();
var el1 = dom.createTextNode(" ");
dom.appendChild(el0, el1);
var el1 = dom.createTextNode(": ");
dom.appendChild(el0, el1);
var el1 = dom.createTextNode("\n");
dom.appendChild(el0, el1);
return el0;
},
render: function render(context, env, contextualElement, blockArguments) {
var dom = env.dom;
var hooks = env.hooks, set = hooks.set, content = hooks.content;
dom.detectNamespace(contextualElement);
if (this.cachedFragment === null) {
this.cachedFragment = this.build(dom);
}
var fragment = dom.cloneNode(this.cachedFragment, true);
var morph0 = dom.createMorphAt(fragment,0,1,contextualElement);
var morph1 = dom.createMorphAt(fragment,1,2,contextualElement);
set(context, "item", blockArguments[0]);
content(morph0, "item.id", context, [], {}, {morph:morph0}, env);
content(morph1, "item.name", context, [], {}, {morph:morph1}, env);
return fragment;
}
};
}());
return {
isHTMLBars: true,
cachedFragment: null,
build: function build(dom) {
var el0 = dom.createDocumentFragment();
var el1 = dom.createTextNode("");
dom.appendChild(el0, el1);
var el1 = dom.createTextNode("");
dom.appendChild(el0, el1);
return el0;
},
render: function render(context, env, contextualElement) {
var dom = env.dom;
var hooks = env.hooks, get = hooks.get, content = hooks.content;
dom.detectNamespace(contextualElement);
if (this.cachedFragment === null) {
this.cachedFragment = this.build(dom);
}
var fragment = dom.cloneNode(this.cachedFragment, true);
dom.repairClonedNode(fragment,[0,1]);
var morph0 = dom.createMorphAt(fragment,0,1,contextualElement);
content(morph0, "each", context, [get(context, "items", env)], {}, {template:child0,morph:morph0,blockParams:1}, env);
return fragment;
}
};
}())
```