Skip to content

Commit

Permalink
Bring back the render hook with a pushable buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed May 3, 2015
1 parent c762400 commit 888492e
Show file tree
Hide file tree
Showing 6 changed files with 720 additions and 37 deletions.
15 changes: 15 additions & 0 deletions packages/ember-htmlbars/lib/system/component-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import setProperties from "ember-metal/set_properties";
import View from "ember-views/views/view";
import { MUTABLE_CELL } from "ember-views/compat/attrs-proxy";
import getCellOrValue from "ember-htmlbars/hooks/get-cell-or-value";
import SafeString from "htmlbars-util/safe-string";

// In theory this should come through the env, but it should
// be safe to import this until we make the hook system public
Expand Down Expand Up @@ -105,6 +106,20 @@ ComponentNode.prototype.render = function(env, attrs, visitor) {

if (component) {
var element = this.expectElement && this.renderNode.firstNode;
if (component.render) {
var content, node, lastChildIndex;
var buffer = [];
component.render(buffer);
content = buffer.join('');
if (element) {
lastChildIndex = this.renderNode.childNodes.length - 1;
node = this.renderNode.childNodes[lastChildIndex];
} else {
node = this.renderNode;
}
node.setContent(new SafeString(content));
}

env.renderer.didCreateElement(component, element); // 2.0TODO: Remove legacy hooks.
env.renderer.willInsertElement(component, element);
env.lifecycleHooks.push({ type: 'didInsertElement', view: component });
Expand Down
34 changes: 1 addition & 33 deletions packages/ember-htmlbars/lib/system/render-view.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import Ember from "ember-metal/core";
import defaultEnv from "ember-htmlbars/env";
import { get } from "ember-metal/property_get";
import ComponentNode, { createOrUpdateComponent } from "ember-htmlbars/system/component-node";

export default function renderView(view, buffer, template) {
if (!template) {
return;
}

var output;

Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function');
output = renderLegacyTemplate(view, buffer, template);

if (output !== undefined) {
buffer.push(output);
}
}

// This function only gets called once per render of a "root view" (`appendTo`). Otherwise,
// HTMLBars propagates the existing env and renders templates for a given render node.
export function renderHTMLBarsBlock(view, block, renderNode) {
Expand All @@ -36,22 +19,7 @@ export function renderHTMLBarsBlock(view, block, renderNode) {

view.env = env;
createOrUpdateComponent(view, {}, renderNode, env);
var componentNode = new ComponentNode(view, null, renderNode, block, true);
var componentNode = new ComponentNode(view, null, renderNode, block, view.tagName !== '');

componentNode.render(env, {});
}

function renderLegacyTemplate(view, buffer, template) {
// FIXME: This should likely be removed. Adds support for bespoke kind-of-handlebars
// templates. They are used in tests, but nobody should be using them in the
// wild.
var context = get(view, 'context');
var options = {
data: {
view: view,
buffer: buffer
}
};

return template(context, options);
}
Loading

0 comments on commit 888492e

Please sign in to comment.