Skip to content

Commit

Permalink
Working hello world output.
Browse files Browse the repository at this point in the history
  • Loading branch information
unconed committed Oct 10, 2010
1 parent 22bf83e commit f8e7acf
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 177 deletions.
2 changes: 1 addition & 1 deletion HTML/client/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tc.shell.prototype = {
// Hook into the given set of handlers.
hook: function (handlers) {
var self = this;
handlers = handlers || [];
handlers = handlers || {};
handlers['shell'] = function (m,a) { self.shellHandler(m, a); };
return handlers;
},
Expand Down
74 changes: 0 additions & 74 deletions HTML/commandview/commandlist.js

This file was deleted.

1 change: 1 addition & 0 deletions HTML/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<script type="text/javascript" charset="utf-8" src="outputview/outputview.js"></script>
<script type="text/javascript" charset="utf-8" src="outputview/outputnode.js"></script>
<script type="text/javascript" charset="utf-8" src="outputview/outputfactory.js"></script>

<script type="text/javascript" charset="utf-8" src="commandview/commandview.js"></script>
<script type="text/javascript" charset="utf-8" src="commandview/commandcontext.js"></script>
Expand Down
55 changes: 55 additions & 0 deletions HTML/outputview/outputfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(function ($) {

var ov = termkit.outputView;

/**
* Constructs node objects of the right class.
*/
ov.outputFactory = function () {

};

ov.outputFactory.prototype = {

construct: function (properties) {
var type = widgets[properties.type];
if (type) {
return new type(properties);
}
},

};

var widgets = ov.outputFactory.widgets = {};

///////////////////////////////////////////////////////////////////////////////

/**
* Raw output
*/
widgets.raw = function (properties) {

// Initialize node.
ov.outputNode.call(this, properties);

this.$contents = this.$element.find('> div.contents');
};

widgets.raw.prototype = $.extend(new ov.outputNode(), {

// Return active markup for this widget.
$markup: function () {
var $outputNode = $('<div class="termkitOutputNode widgetRaw"><div class="contents"></div></div>').data('controller', this);
var self = this;
return $outputNode;
},

// Update markup to match.
updateElement: function () {
this.$contents.text(this.contents);
this.$element.data('controller', this);
},

});

})(jQuery);
36 changes: 19 additions & 17 deletions HTML/outputview/outputnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ ov.outputNode = function (properties) {
for (i in properties) this[i] = properties[i];

this.$element = this.$markup();
this.$children = $([]);

this.children = [];
this.parent = null;
this.root = this;

this.contents = null;
this.index = {};

this.updateElement();
};

ov.outputNode.prototype = {
Expand All @@ -31,29 +29,33 @@ ov.outputNode.prototype = {
return $outputNode;
},

// Update markup to match.
updateElement: function () {
this.$element.data('controller', this);
},

// Pass-through length of array
get length() {
return this.children.length;
},

// Update children to match.
updateChildren: function () {
// Detach children.
var $e = this.$element;
$e.children().detach();
var self = this;

// Re-attach based on contents array.
// Detach children.
this.$children.detach();
this.$children = $([]);

// Re-attach based on children array.
$.each(this.children, function () {
$e.append(this.$element);
self.$children = self.$children.add(this.$element);
self.$element.append(this.$element);

this.updateElement();
});
},

// Update markup to match.
updateElement: function () {
this.$element.text(this.contents);
this.$element.data('controller', this);
},

// Adopt node index.
mergeIndex: function (node) {
for (id in node.index) {
Expand Down Expand Up @@ -114,14 +116,14 @@ ov.outputNode.prototype = {
}
var args = [ index, 0 ];

// Add elements.
[].splice.apply(this.children, args);

// Allow both single object and array.
$.each(oneOrMany(collection), function () {
self.adopt(this);
args.push(this);
});

// Add elements.
[].splice.apply(this.children, args);
},

// Remove node at index.
Expand Down
13 changes: 9 additions & 4 deletions HTML/outputview/outputview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var ov = termkit.outputView = function () {
var self = this;

this.$element = this.$markup();


this.factory = new ov.outputFactory();
};

ov.prototype = {
Expand All @@ -25,24 +26,27 @@ ov.prototype = {

// Update the element's markup in response to internal changes.
updateElement: function () {

this.root.updateChildren();
},

// Hook into the given set of handlers.
hook: function (handlers) {
var self = this;
handlers = handlers || [];
handlers = handlers || {};
handlers['view'] = function (m,a) { self.viewHandler(m, a); };
return handlers;
},

// Handler for view.* invocations.
viewHandler: function (method, args) {
var self = this;

switch (method) {
case 'view.add':
var target = this.root.getNode(args.target);
var nodes = oneOrMany(args.contents).map(function (node) { return new ov.outputNode(node); });
var nodes = oneOrMany(args.objects).map(function (node) { return self.factory.construct(node); });
target.add(nodes, args.offset);
this.updateElement();
break;

case 'view.remove':
Expand All @@ -53,6 +57,7 @@ ov.prototype = {
else if (target.parent) {
target.parent.remove(target);
}
this.updateElement();
break;

case 'view.replace':
Expand Down
2 changes: 1 addition & 1 deletion HTML/termkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ function bug(object, type) {
}

function oneOrMany(object) {
return (object.constructor == [].constructor) ? object : [ object ];
return (typeof object == 'object' && object.constructor == [].constructor) ? object : [ object ];
}
75 changes: 0 additions & 75 deletions HTML/tokenfield/tokenlist.js

This file was deleted.

4 changes: 2 additions & 2 deletions Node/shell/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports.shell = function (sequence, args, exit, router) {

exports.shell.prototype = {
run: function (sequence, args) {
this.send([sequence, 'run', args ]);
this.send([ sequence, 'run', args ]);
},

close: function () {
Expand All @@ -67,7 +67,7 @@ exports.shell.prototype = {
while (this.buffer.indexOf("\u0000") >= 0) {
var chunk = this.buffer.split("\u0000").shift();
var data = JSON.parse(chunk);
console.log('processing ', data);

this.router.send(this.id, data[0], data[1], data[2]);
this.buffer = this.buffer.substring(chunk.length + 1);
}
Expand Down
Loading

0 comments on commit f8e7acf

Please sign in to comment.