Permalink
Browse files

jsml

  • Loading branch information...
1 parent b34105f commit 2f4a15c3c588fd70b35ee78701f8377116793ea6 @jeffsu committed Apr 1, 2011
Showing with 192 additions and 16 deletions.
  1. +24 −2 dist/browser/js2-full.js
  2. +24 −2 dist/gem/lib/js2/js2.js
  3. +24 −2 dist/npm/lib/js2.js
  4. +24 −2 flavors/browser-full.js
  5. +24 −2 flavors/node.js
  6. +24 −2 flavors/ringo-full.js
  7. +24 −2 flavors/ruby.js
  8. +24 −2 src/Common/JSML.js2
View
@@ -1504,13 +1504,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1574,6 +1578,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1609,7 +1614,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1635,6 +1640,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
View
@@ -1500,13 +1500,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1570,6 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1605,7 +1610,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1631,6 +1636,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
View
@@ -1500,13 +1500,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1570,6 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1605,7 +1610,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1631,6 +1636,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
View
@@ -1504,13 +1504,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1574,6 +1578,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1609,7 +1614,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1635,6 +1640,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
View
@@ -1500,13 +1500,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1570,6 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1605,7 +1610,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1631,6 +1636,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
View
@@ -1502,13 +1502,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
this.processLine(l);
}
- var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
eval(toEval);
this.result = function(hash) {
return process.call(hash);
};
+ });
+ OO.addMember("flatten",function () {
+ console.log(this.root);
+ return this.root.flatten();
});
OO.addMember("processLine",function (line) {
@@ -1572,6 +1576,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
+ this.attributes = {};
var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
@@ -1607,7 +1612,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
- out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1633,6 +1638,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
}
});
+
+ OO.addMember("getAttributes",function () {
+ if (!this.attributes) return '';
+
+ var out = [];
+ var attrs = this.attributes;
+
+ if (attrs['class']) this.classes.push(attrs['class']);
+ if (this.classes.length) attrs['class'] = this.classes.join(' ');
+
+ for (var k in attrs) {
+ if (attrs.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(attrs[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
});
JS2.TEMPLATES = { jsml: JS2.JSML };
Oops, something went wrong.

0 comments on commit 2f4a15c

Please sign in to comment.