Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hello world for jsml

  • Loading branch information...
commit b34105f4a45c1a4d3841f00ea28bf0d4fb72d9db 1 parent 609e772
@jeffsu authored
View
42 dist/browser/js2-full.js
@@ -1128,6 +1128,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1237,6 +1238,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1282,6 +1284,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1353,6 +1356,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1439,6 +1443,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1483,6 +1488,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1497,11 +1503,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1599,10 +1608,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1610,11 +1634,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
(function (undefined, JS2) {
View
1  dist/browser/js2.js
@@ -270,6 +270,7 @@ JS2.Array.prototype.any = function() {
};
+
js2.ROOT = root;
return JS2;
View
42 dist/gem/lib/js2/js2.js
@@ -1124,6 +1124,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1234,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1280,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1352,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1439,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1484,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1493,11 +1499,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1595,10 +1604,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1606,11 +1630,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
43 dist/npm/lib/js2.js
@@ -1124,6 +1124,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1234,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1280,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1352,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1439,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1484,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1493,11 +1499,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1595,10 +1604,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1606,11 +1630,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1665,6 +1687,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new JS2.FileSystem(new JS2.NodeFileAdapter());
js2.DECORATOR = new JS2.NodeDecorator();
View
42 flavors/browser-full.js
@@ -1128,6 +1128,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1237,6 +1238,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1282,6 +1284,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1353,6 +1356,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1439,6 +1443,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1483,6 +1488,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1497,11 +1503,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1599,10 +1608,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1610,11 +1634,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
(function (undefined, JS2) {
View
1  flavors/browser.js
@@ -270,6 +270,7 @@ JS2.Array.prototype.any = function() {
};
+
js2.ROOT = root;
return JS2;
View
43 flavors/node.js
@@ -1124,6 +1124,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1234,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1280,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1352,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1439,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1484,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1493,11 +1499,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1595,10 +1604,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1606,11 +1630,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1665,6 +1687,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new JS2.FileSystem(new JS2.NodeFileAdapter());
js2.DECORATOR = new JS2.NodeDecorator();
View
43 flavors/ringo-full.js
@@ -1126,6 +1126,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1235,6 +1236,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1280,6 +1282,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1351,6 +1354,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1437,6 +1441,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1481,6 +1486,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1495,11 +1501,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1597,10 +1606,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1608,11 +1632,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1668,6 +1690,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new FileSystem(new RingoFileAdapter());
JS2.DECORATOR = new JS2.RingoDecorator();
View
1  flavors/ringo.js
@@ -267,6 +267,7 @@ JS2.Array.prototype.any = function() {
};
+
js2.ROOT = root;
return js2;
})(this);
View
42 flavors/ruby.js
@@ -1124,6 +1124,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1234,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1280,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1352,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1439,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1484,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1493,11 +1499,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- });
- OO.addMember("result",function () {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
});
OO.addMember("processLine",function (line) {
@@ -1595,10 +1604,25 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (this.nodeType) {
- out.unshift("<"+(this.nodeType)+">");
- out.push("</"+(this.nodeType)+">");
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+">") + ');\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+ return out;
+ });
+
+ OO.addMember("handleJsEQ",function (out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ });
+
+
+ OO.addMember("handleJsExec",function (out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -1606,11 +1630,9 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push('}');
}
}
-
-
- return out;
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
35 src/Common/JSML.js2
@@ -12,11 +12,14 @@ class JSML {
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
- console.log(this.root);
- }
- function result() {
- return this.root.flatten().join('');
+ var toEval = 'function process() { var out = [];\n' + this.root.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(hash) {
+ return process.call(hash);
+ };
+
}
function processLine(line) {
@@ -114,10 +117,25 @@ class JSMLElement {
}
if (this.nodeType) {
- out.unshift(%{<#{this.nodeType}>});
- out.push(%{</#{this.nodeType}>});
- }
+ this.handleJsEQ(out);
+ out.unshift('out.push(' + JSON.stringify(%{<#{this.nodeType}>}) + ');\n');
+ out.push('out.push(' + JSON.stringify(%{</#{this.nodeType}>}) + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ }
+
+ return out;
+ }
+ function handleJsEQ(out) {
+ if (this.jsEQ) {
+ out.unshift('out.push(' + this.jsEQ + ');\n');
+ }
+ }
+
+
+ function handleJsExec(out) {
if (this.jsExec) {
out.unshift(this.jsExec);
@@ -125,8 +143,5 @@ class JSMLElement {
out.push('}');
}
}
-
-
- return out;
}
}
View
4 tests/src/jsml.js2
@@ -2,10 +2,10 @@ console.log('hi');
var text = <<END:jsml
- if (this.hello) {
%div
- .hello
+ .hello= this.bar
.world
%span Hello world
= this.hello
END
-console.log(text.result({ hello:"yo" }));
+console.log(text.result({ hello:"yo", bar:"foo" }));
Please sign in to comment.
Something went wrong with that request. Please try again.