Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new version

  • Loading branch information...
commit cd7999af737eb4f51ea27e5df4b4a26c5f70d4d6 1 parent 3e2b444
Jeff Su authored
4 CHANGELOG
View
@@ -1,3 +1,7 @@
+0.3.15
+ * JSML: added "eval'd" attribute handling
+ * JSML: fixed browser js2 file
+
0.3.14
* JSML: added plain content children
2  VERSION
View
@@ -1 +1 @@
-0.3.14
+0.3.15
30 dist/browser/js2-full.js
View
@@ -18,7 +18,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1551,7 +1551,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1578,7 +1578,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1608,7 +1608,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1629,7 +1629,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1663,21 +1663,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
34 dist/browser/js2.js
View
@@ -19,7 +19,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -181,8 +181,6 @@ function mainFunction (arg) {
return JS2;
})(undefined, JS2);
- JS2.TEMPLATES = { jsml: JS2.JSML };
-
JS2.Array = function (arr) {
if (arr instanceof Array) {
this.append(arr);
@@ -334,7 +332,7 @@ JS2.Array.prototype.any = function() {
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -361,7 +359,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -391,7 +389,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -412,7 +410,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -446,26 +444,24 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
+ JS2.TEMPLATES = { jsml: JS2.JSML };
+
js2.ROOT = root;
4 dist/gem/CHANGELOG
View
@@ -1,3 +1,7 @@
+0.3.15
+ * JSML: added "eval'd" attribute handling
+ * JSML: fixed browser js2 file
+
0.3.14
* JSML: added plain content children
2  dist/gem/js2.gemspec
View
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = 'js2'
- s.version = '0.3.14'
+ s.version = '0.3.15'
s.summary = "Javascript Syntactic Sugar"
s.description = %{A superset of the Javascript language to make development easier.}
s.files = Dir['bin/*'] + Dir['lib/**/*.rb'] + Dir['lib/**/*.js'] + [ 'CHANGELOG' ]
30 dist/gem/lib/js2/js2.js
View
@@ -14,7 +14,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1547,7 +1547,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1574,7 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1604,7 +1604,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1625,7 +1625,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1659,21 +1659,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
4 dist/npm/CHANGELOG
View
@@ -1,3 +1,7 @@
+0.3.15
+ * JSML: added "eval'd" attribute handling
+ * JSML: fixed browser js2 file
+
0.3.14
* JSML: added plain content children
30 dist/npm/lib/js2.js
View
@@ -14,7 +14,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1547,7 +1547,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1574,7 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1604,7 +1604,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1625,7 +1625,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1659,21 +1659,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
2  dist/npm/package.json
View
@@ -1,6 +1,6 @@
{ "name" : "js2",
"description" : "Javascript Syntactic Sugar",
- "version" : "0.3.14",
+ "version" : "0.3.15",
"author" : "Jeff Su",
"repository" : { "type" : "git" , "url" : "git://github.com/jeffsu/js2.git" },
"bugs" : { "web" : "http://github.com/jeffsu/js2/issues" },
30 flavors/browser-full.js
View
@@ -18,7 +18,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1551,7 +1551,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1578,7 +1578,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1608,7 +1608,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1629,7 +1629,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1663,21 +1663,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
34 flavors/browser.js
View
@@ -19,7 +19,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -181,8 +181,6 @@ function mainFunction (arg) {
return JS2;
})(undefined, JS2);
- JS2.TEMPLATES = { jsml: JS2.JSML };
-
JS2.Array = function (arr) {
if (arr instanceof Array) {
this.append(arr);
@@ -334,7 +332,7 @@ JS2.Array.prototype.any = function() {
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -361,7 +359,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -391,7 +389,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -412,7 +410,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -446,26 +444,24 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
+ JS2.TEMPLATES = { jsml: JS2.JSML };
+
js2.ROOT = root;
2  flavors/browser.js.erb
View
@@ -13,9 +13,9 @@
JS2.ROOT = JS2;
<%= js 'core/js2-class.js' %>
- <%= js 'core/js2-end.js' %>
<%= js 'Common/Array.js2' %>
<%= js 'Common/JSML.js2' %>
+ <%= js 'core/js2-end.js' %>
js2.ROOT = root;
2  flavors/js2.gemspec
View
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = 'js2'
- s.version = '0.3.14'
+ s.version = '0.3.15'
s.summary = "Javascript Syntactic Sugar"
s.description = %{A superset of the Javascript language to make development easier.}
s.files = Dir['bin/*'] + Dir['lib/**/*.rb'] + Dir['lib/**/*.js'] + [ 'CHANGELOG' ]
30 flavors/node.js
View
@@ -14,7 +14,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1547,7 +1547,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1574,7 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1604,7 +1604,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1625,7 +1625,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1659,21 +1659,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
2  flavors/node.package.json
View
@@ -1,6 +1,6 @@
{ "name" : "js2",
"description" : "Javascript Syntactic Sugar",
- "version" : "0.3.14",
+ "version" : "0.3.15",
"author" : "Jeff Su",
"repository" : { "type" : "git" , "url" : "git://github.com/jeffsu/js2.git" },
"bugs" : { "web" : "http://github.com/jeffsu/js2/issues" },
30 flavors/ringo-full.js
View
@@ -16,7 +16,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1549,7 +1549,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1576,7 +1576,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1606,7 +1606,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1627,7 +1627,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1661,21 +1661,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
194 flavors/ringo.js
View
@@ -18,7 +18,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
js2.ROOT = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
// CLASS HELPERS
@@ -267,6 +267,198 @@ JS2.Array.prototype.any = function() {
};
+ JS2.Class.extend('JSML', function(KLASS, OO){
+ OO.addStaticMember("process",function (txt) {
+ return new KLASS(txt);
+ });
+
+ OO.addMember("initialize",function (txt) {
+ var lines = txt.split(/\n/);
+ this.root = new JS2.JSMLElement();
+ this.stack = [ this.root ];
+
+ for(var _i1=0,_c1=lines,_l1=_c1.length,l;(l=_c1[_i1])||(_i1<_l1);_i1++){
+ if (l.match(/^\s*$/)) continue;
+ this.processLine(l);
+ }
+
+ var toEval = 'function process() { var out = [];\n' + this.flatten().join('') + '\n return out.join("");\n}';
+ eval(toEval);
+
+ this.result = function(bound) {
+ bound = bound || {};
+ return process.call(bound);
+ };
+ });
+
+ OO.addMember("flatten",function () {
+ return this.root.flatten();
+ });
+
+ OO.addMember("processLine",function (line) {
+ var ele = new JS2.JSMLElement(line);
+ var scope = this.getScope();
+
+ if (ele.scope == scope) {
+ this.stack.pop();
+ this.getLast().push(ele);
+ this.stack.push(ele);
+ } else if (ele.scope > scope) {
+ this.getLast().push(ele);
+ this.stack.push(ele);
+ } else if (ele.scope < scope) {
+ var diff = scope - ele.scope + 1;
+ while(diff-- > 0) {
+ this.stack.pop();
+ }
+ this.getLast().push(ele);
+ this.stack.push(ele);
+ }
+ });
+
+
+ OO.addMember("getScope",function () {
+ return this.stack.length - 1;
+ });
+
+ OO.addMember("getLast",function () {
+ return this.stack[this.stack.length-1];
+ });
+
+});
+
+JS2.Class.extend('JSMLElement', function(KLASS, OO){
+ OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
+ 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 = [];
+
+ if (line == null) {
+ this.scope = this.SCOPE_OFFSET;
+ return;
+ }
+
+ var spaceMatch = line.match(this.SCOPE_REGEX);
+ this.scope = spaceMatch[1].length / 2 + this.SCOPE_OFFSET;
+
+ this.classes = [];
+ this.nodeID = null;
+
+ this.parse(spaceMatch[2]);
+ });
+
+ OO.addMember("push",function (child) {
+ this.children.push(child);
+ });
+
+ OO.addMember("parse",function (line) {
+ this.attributes;
+ this.line = line;
+ var self = this;
+
+ var splitted = line.match(this.SPLIT_REGEX);
+ var tokens = splitted[1];
+ var attrs = splitted[2];
+ var jsType = splitted[3];
+ var content = splitted[4];
+
+ if (tokens) {
+ tokens.replace(this.TOKEN_REGEX, function(match, type, name){
+ switch(type) {
+ case '%': self.nodeType = name; break;
+ case '.': self.classes.push(name); break;
+ case '#': self.nodeID = name; break;
+ }
+ return '';
+ });
+ }
+
+ if (jsType == '=') {
+ this.jsEQ = content;
+ } else if (jsType == '-') {
+ this.jsExec = content;
+ } else {
+ this.content = content;
+ }
+
+ if (attrs) {
+ this.attributes = attrs;
+ }
+
+ if (!this.nodeType && (this.classes.length || this.nodeID)) {
+ this.nodeType = 'div';
+ }
+ });
+
+ OO.addMember("flatten",function () {
+ var out = [];
+
+ for(var _i1=0,_c1=this.children,_l1=_c1.length,c;(c=_c1[_i1])||(_i1<_l1);_i1++){
+ var arr = c.flatten();
+ for(var _i2=0,_c2=arr,_l2=_c2.length,item;(item=_c2[_i2])||(_i2<_l2);_i2++){
+ out.push(item);
+ }
+ }
+
+ if (this.nodeType) {
+ this.handleJsEQ(out);
+ this.handleContent(out);
+ out.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
+ out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
+ } else {
+ this.handleJsExec(out);
+ this.handleJsEQ(out);
+ this.handleContent(out);
+ }
+
+ return out;
+ });
+
+ 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("}\n");
+ }
+ }
+ });
+
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
+ var out = [];
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
+
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
+ }
+ }
+ return (out.length ? ' ' : '') + out.join(' ');
+ });
+});
+
+
+ JS2.TEMPLATES = { jsml: JS2.JSML };
+
js2.ROOT = root;
return js2;
2  flavors/ringo.js.erb
View
@@ -11,6 +11,8 @@ exports.JS2 = (function (root) {
<%= js 'core/js2-class.js' %>
<%= js 'Common/Array.js2' %>
+ <%= js 'Common/JSML.js2' %>
+ <%= js 'core/js2-end.js' %>
js2.ROOT = root;
return js2;
2  flavors/ringo.package.json
View
@@ -1,6 +1,6 @@
{
"name": "js2-ringo",
- "version": "0.3.14",
+ "version": "0.3.15",
"description": "Javascript Syntactic Sugar",
"keywords": ["rhino", "ringo", "js2", "object oriented programming" ],
"author": "Jeff Su (http://jeffsu.com/) <me@jeffsu.com>",
30 flavors/ruby.js
View
@@ -14,7 +14,7 @@ function mainFunction (arg) {
var JS2 = root.JS2 = mainFunction;
var js2 = root.js2 = JS2;
- js2.VERSION = "0.3.14";
+ js2.VERSION = "0.3.15";
JS2.ROOT = JS2;
@@ -1547,7 +1547,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
- OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
+ OO.addMember("SPLIT_REGEX",/^((?:\.|\#|\%)[^=\-\s\{]*)?(\{.*\})?(=|-)?(?:\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);
@@ -1574,7 +1574,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
OO.addMember("parse",function (line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -1604,7 +1604,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -1625,7 +1625,7 @@ 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.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else {
this.handleJsExec(out);
@@ -1659,21 +1659,17 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
});
- OO.addMember("getAttributes",function () {
- if (!this.attributes) return '';
-
+ OO.addStaticMember("parseAttributes",function (hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
});
});
26 src/Common/JSML.js2
View
@@ -87,7 +87,7 @@ class JSMLElement {
}
function parse(line) {
- this.attributes = {};
+ this.attributes;
this.line = line;
var self = this;
@@ -117,7 +117,7 @@ class JSMLElement {
}
if (attrs) {
- eval('this.attributes = ' + attrs + ';');
+ this.attributes = attrs;
}
if (!this.nodeType && (this.classes.length || this.nodeID)) {
@@ -138,7 +138,7 @@ class JSMLElement {
if (this.nodeType) {
this.handleJsEQ(out);
this.handleContent(out);
- out.unshift('out.push(' + JSON.stringify(%{<#{this.nodeType}#{this.getAttributes()}>}) + ');\n');
+ out.unshift('out.push("<' + this.nodeType + '"+JS2.JSMLElement.parseAttributes(' + (this.attributes || "{}") + ', ' + JSON.stringify(this.classes || []) + ', ' + JSON.stringify(this.id || null) + ')+">");\n');
out.push('out.push(' + JSON.stringify(%{</#{this.nodeType}>}) + ');\n');
} else {
this.handleJsExec(out);
@@ -172,21 +172,17 @@ class JSMLElement {
}
}
- function getAttributes() {
- if (!this.attributes) return '';
-
+ static function parseAttributes(hash, classes, id) {
var out = [];
- var attrs = this.attributes;
-
- if (attrs['class']) this.classes.push(attrs['class']);
- if (this.classes.length) attrs['class'] = this.classes.join(' ');
+ classes = classes || [];
+ if (hash['class']) classes.push(hash['class']);
+ if (classes.length) hash['class'] = classes.join(" ");
- for (var k in attrs) {
- if (attrs.hasOwnProperty(k)) {
- out.push(k + '=' + JSON.stringify(attrs[k]));
+ for (var k in hash) {
+ if (hash.hasOwnProperty(k)) {
+ out.push(k + '=' + JSON.stringify(hash[k]));
}
- }
-
+ }
return (out.length ? ' ' : '') + out.join(' ');
}
}
4 tests/src/jsml.js2
View
@@ -5,7 +5,7 @@ var text = <<END:jsml
%div.yo
.hello= this.bar
.world
- %span{ class: 'hello', href: "/" } Hello world
+ %span{ class: this.hello, href: "/" } Hello world
= this.hello
END
@@ -18,7 +18,7 @@ END
js2.test(#(assert) {
var result = text.result({ hello:"yo", bar:"foo", yo:['hello', 'world'] });
- var expected = '<div>hello</div><div>world</div><div class="yo"><div class="hello">foo</div><div class="world"></div></div><span class="hello" href="/">Hello world</span>yo'
+ var expected = '<div>hello</div><div>world</div><div class="yo"><div class="hello">foo</div><div class="world"></div></div><span class="yo" href="/">Hello world</span>yo'
assert.eq(expected, result);
assert.eq('<div>helloworld</div>', text2.result());
});
Please sign in to comment.
Something went wrong with that request. Please try again.