Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

incremental

  • Loading branch information...
commit 57ef10a68a4ed09562fb9cf71254b7fdd71ad265 1 parent 2f4a15c
@jeffsu authored
View
47 dist/browser/js2-full.js
@@ -1513,7 +1513,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1522,20 +1521,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1552,9 +1550,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1579,8 +1578,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1589,13 +1591,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1614,11 +1616,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1626,17 +1630,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1655,6 +1665,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 dist/gem/lib/js2/js2.js
@@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1610,11 +1612,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1622,17 +1626,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 dist/npm/lib/js2.js
@@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1610,11 +1612,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1622,17 +1626,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 flavors/browser-full.js
@@ -1513,7 +1513,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1522,20 +1521,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1552,9 +1550,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1579,8 +1578,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1589,13 +1591,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1614,11 +1616,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1626,17 +1630,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1655,6 +1665,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 flavors/node.js
@@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1610,11 +1612,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1622,17 +1626,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 flavors/ringo-full.js
@@ -1511,7 +1511,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1520,20 +1519,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1550,9 +1548,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1577,8 +1576,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1587,13 +1589,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1612,11 +1614,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1624,17 +1628,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1653,6 +1663,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 flavors/ruby.js
@@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
});
OO.addMember("flatten",function () {
- console.log(this.root);
return this.root.flatten();
});
@@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
});
@@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
- OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
- OO.addMember("SCOPE_OFFSET",2);
+ OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
+ OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
+ OO.addMember("SCOPE_OFFSET",1);
OO.addMember("initialize",function (line) {
this.children = [];
@@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, function(match, type, name){
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return '';
});
- line = line.replace(this.JS_REGEX, function(match, type, content){
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -1610,11 +1612,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -1622,17 +1626,23 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
});
+ OO.addMember("handleContent",function (out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ });
+
OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
});
@@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
});
});
View
47 src/Common/JSML.js2
@@ -22,7 +22,6 @@ class JSML {
}
function flatten() {
- console.log(this.root);
return this.root.flatten();
}
@@ -31,20 +30,19 @@ class JSML {
var scope = this.getScope();
if (ele.scope == scope) {
- console.log('same');
this.stack.pop();
this.getLast().push(ele);
+ this.stack.push(ele);
} else if (ele.scope > scope) {
- console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
- console.log('less');
- var diff = scope - ele.scope;
+ var diff = scope - ele.scope + 1;
while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
+ this.stack.push(ele);
}
}
@@ -61,9 +59,10 @@ class JSML {
class JSMLElement {
var SCOPE_REGEX = /^(\s*)(.*)$/;
- var TOKEN_REGEX = /^(\%|\#|\.)([\w-]+)/;
- var JS_REGEX = /^(-|=)(.*)$/;
- var SCOPE_OFFSET = 2;
+ var SPLIT_REGEX = /^([^=-\s]*)(=|-)?(?:\s*)(.*)$/;
+ var TOKEN_REGEX = /(\%|\#|\.)([\w-]+)/g;
+ var JS_REGEX = /^(-|=)(.*)$/g;
+ var SCOPE_OFFSET = 1;
function initialize(line) {
this.children = [];
@@ -88,8 +87,11 @@ class JSMLElement {
function parse(line) {
this.attributes = {};
+ this.line = line;
var self = this;
- line = line.replace(this.TOKEN_REGEX, #(match, type, name) {
+ var splitted = line.match(this.SPLIT_REGEX);
+
+ splitted[1].replace(this.TOKEN_REGEX, #(match, type, name) {
switch(type) {
case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break;
@@ -98,13 +100,13 @@ class JSMLElement {
return '';
});
- line = line.replace(this.JS_REGEX, #(match, type, content) {
- switch(type) {
- case '=': self.jsEQ = content; break;
- case '-': self.jsExec = content; break;
- }
- return '';
- });
+ if (splitted[2] == '=') {
+ this.jsEQ = splitted[3];
+ } else if (splitted[2] == '-') {
+ this.jsExec = splitted[3];
+ } else {
+ this.content = splitted[3];
+ }
if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div';
@@ -123,11 +125,13 @@ class JSMLElement {
if (this.nodeType) {
this.handleJsEQ(out);
+ this.handleContent(out);
out.unshift('out.push(' + JSON.stringify(%{<#{this.nodeType}#{this.getAttributes()}>}) + ');\n');
out.push('out.push(' + JSON.stringify(%{</#{this.nodeType}>}) + ');\n');
} else {
this.handleJsExec(out);
this.handleJsEQ(out);
+ this.handleContent(out);
}
return out;
@@ -135,17 +139,23 @@ class JSMLElement {
function handleJsEQ(out) {
if (this.jsEQ) {
+ this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n');
}
}
+ function handleContent(out) {
+ if (this.content != null && this.content.length > 0) {
+ out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
+ }
+ }
+
function handleJsExec(out) {
if (this.jsExec) {
out.unshift(this.jsExec);
-
if (this.jsExec.match(/\{\s*$/)) {
- out.push('}');
+ out.push("}\n");
}
}
}
@@ -164,6 +174,7 @@ class JSMLElement {
out.push(k + '=' + JSON.stringify(attrs[k]));
}
}
+
return (out.length ? ' ' : '') + out.join(' ');
}
}
View
8 tests/src/jsml.js2
@@ -1,11 +1,15 @@
console.log('hi');
var text = <<END:jsml
+ - for (var i=0; i<this.yo.length; i++) {
+ %div= this.yo[i];
- if (this.hello) {
- %div
+ %div.yo
.hello= this.bar
.world
+ .world
+ .world
%span Hello world
= this.hello
END
-console.log(text.result({ hello:"yo", bar:"foo" }));
+console.log(text.result({ hello:"yo", bar:"foo", yo:['hello', 'world'] }));
Please sign in to comment.
Something went wrong with that request. Please try again.