tildeio/htmlbars — pull request #52 by mixonic (2014-06-22 16:53:51+00:00)
Title: Refactor DOMHelper, introduce contextualElement

Template execution now requires both hooks and the dom to be passed in. For example:

```JavaScript
template(context, {hooks: hooks, dom: new DOMHelper()});
```

DOMHelper can be instantiated a few arguments:

```JavaScript
// no contextual element (uses fallback div), global document, no namespace
new DOMHelper();

// contextual element, ownerDocument of element, namespace of element
new DOMHelper(document.createElement('table'));

// contextual element, ownerDocument of element, namespace provided
new DOMHelper(document.createElementNS(svgNamespace, 'foreignObject'), null, xhtmlNamespace);

// no contextual element (uses fallback div), document provided
new DOMHelper(null, document);
```

Optionally, you can provide a contextualElement to the DOMHelper. This will allow it to resolve un-escaped HTML rendering issues:

```JavaScript
var template = compile('{{{html}}}');
var tableElement = document.createElement('table');
template({html: '
Yo
', {
hooks: hooks,
dom: new DOMHelper(tableElement)
});
```

When block or component hooks are called in hydration, they are passed a DOMHelper instance with the current contextual element. This allows templates like:

```JavaScript
var template = compile('

{{#test}}{{{html}}}{{/if}}');
template({html: '
Yo
', {
hooks: hooks,
dom: new DOMHelper()
});
```

To run properly. The `test` helper just needs to pass the env (which contains the proper contextual element) through to the inner render.

This code also prepares htmlbars for changing namespaces based on the AST.