refactor compile

This commit is contained in:
Christopher Jeffrey 2013-02-16 15:11:05 -06:00
parent 214c10e547
commit 59cc5d73c3
1 changed files with 439 additions and 429 deletions

View File

@ -253,33 +253,48 @@ Tput.prototype.parseExtended = function(data) {
return info; return info;
}; };
Tput.prototype.invoke = function(key, prefix, params, suffix) { Tput.prototype.compile = function(key) {
var self = this; var self = this
if (!this.info.all) { , info = this.info;
this.info.all = {};
Object.keys(info.bools).forEach(function(key) {
self.info.all[key] = info.bools;
});
Object.keys(info.numbers).forEach(function(key) {
self.info.all[key] = info.numbers;
});
Object.keys(info.strings).forEach(function(key) {
self.info.all[key] = info.strings;
});
}
var val = this.info.all[key]; this.methods = {};
if (val == null) return; this.info.all = {};
Object.keys(info.bools).forEach(function(key) {
info.all[key] = info.bools;
});
Object.keys(info.numbers).forEach(function(key) {
info.all[key] = info.numbers;
});
Object.keys(info.strings).forEach(function(key) {
info.all[key] = info.strings;
});
Object.keys(info.all).forEach(function(key) {
self.methods[key] = self._compile(info.all[key]);
});
};
Tput.prototype._compile = function(val) {
var self = this;
switch (typeof val) { switch (typeof val) {
case 'boolean': case 'boolean':
val = val ? 'true' : 'false'; return function() {
break; return val ? 'true' : 'false';
};
case 'number': case 'number':
//val = val === -1 ? '' : val + ''; return function() {
val = val + ''; return val === -1 ? null : val;
break; };
case 'string': case 'string':
break;
default:
return function() {};
}
// e.g. // e.g.
// set_attributes: '%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m', // set_attributes: '%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m',
// cursor_address: '\u001b[%i%p1%d;%p2%dH', // cursor_address: '\u001b[%i%p1%d;%p2%dH',
@ -686,12 +701,7 @@ Tput.prototype.invoke = function(key, prefix, params, suffix) {
code += '"); return out.join("");'; code += '"); return out.join("");';
break; return new Function('params', code);
}
console.log(val);
return val;
}; };
// Return alias if one exists. // Return alias if one exists.