Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Jun 17, 2013
1 parent d58e706 commit e4c6eb7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
10 changes: 8 additions & 2 deletions packages/ui/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ _.extend(Component.prototype, {
},
addChild: function (name, childComponent) {
if (name instanceof Component) {
// omitted name, generate unique child ID
// omitted name arg
childComponent = name;
name = "__child#" + (this._uniqueIdCounter++) + "__";
name = null;
}
// omitted name, generate unique child ID
if (name === null || typeof name === 'undefined')
name = "__child#" + (this._uniqueIdCounter++) + "__";
name = String(name);

if (! (childComponent instanceof Component))
throw new Error("not a Component: " + childComponent);

this._requireAlive();
if (this.hasChild(name))
throw new Error("Already have a child named: " + name);
Expand Down
47 changes: 36 additions & 11 deletions packages/ui/html_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
HtmlBuilder = function () {
this.htmlBuf = [];

//this.rootComponent = null;
//this.currentComponent = null;
this.rootComponent = null;
this.currentComponent = null;
// parent chain of currentComponent, exclusive
//this.componentStack = [];
this.componentStack = [];

// this.builderId = Random.id();
// this.nextElementNum = 1;
Expand Down Expand Up @@ -89,8 +89,8 @@ _.extend(HtmlBuilder.prototype, {
throw new Error("Illegal HTML attribute name: " + attrName);

buf.push(' ', attrName, '="');
var initialValue = (typeof attrValue === 'string' ?
attrValue : attrValue());
var initialValue = (typeof attrValue === 'function' ?
attrValue() : attrValue);
buf.push(self._encodeEntities(initialValue, true));
buf.push('"');
});
Expand All @@ -105,23 +105,48 @@ _.extend(HtmlBuilder.prototype, {
this.htmlBuf.push('</', tagName, '>');
},
text: function (stringOrFunction) {
var text = (typeof stringOrFunction === 'string' ?
stringOrFunction : stringOrFunction());
var text = (typeof stringOrFunction === 'function' ?
stringOrFunction() : stringOrFunction);
this.htmlBuf.push(this.encodeEntities(text));
},
rawHtml: function (stringOrFunction) {
var html = (typeof stringOrFunction === 'string' ?
stringOrFunction : stringOrFunction());
var html = (typeof stringOrFunction === 'function' ?
stringOrFunction() : stringOrFunction);
this.htmlBuf.push(html);
},
component: function (componentOrFunction) {
// XXX
component: function (componentOrFunction, options) {
var self = this;
var comp = (typeof componentOrFunction === 'function' ?
componentOrFunction() : componentOrFunction);

var parentComponent = self.currentComponent; // may be null

if (self.currentComponent)
self.componentStack.push(self.currentComponent);
self.currentComponent = comp;

var childKey = (options && options.childKey || null);

try {
if (parentComponent)
parentComponent.addChild(childKey, comp);
comp.build(self);
// XXX
} finally {
self.currentComponent = self.componentStack.pop() || null;
}
},
finish: function () {
return this.htmlBuf.join('');
}
});

// CHANGES TO COMPONENT NEEDED:
//
// - childKey, elementKey -- call things "key"
// - no attach/detach -- need to wire things up from HTML...


// openChunk, closeChunk
//
// Drop comemnts at start and finish. Comments may have
Expand Down

0 comments on commit e4c6eb7

Please sign in to comment.