Skip to content
Browse files

adding support for compile and adding bootstrap file to root

  • Loading branch information...
1 parent fd8e035 commit 9a8774542bec8b2465c48ee8ad67c03fc5761993 @jeffsu committed May 30, 2012
View
2 Rakefile
@@ -30,6 +30,7 @@ namespace :test do
puts e.to_s
end
end
+
end
desc "run all tests on node platform"
@@ -68,6 +69,7 @@ task :compile do
puts "Compiling #{target}\n --> #{destination}"
File.open(destination, "w") { |t| t << ERB.new(File.read(target)).result(binding) }
end
+ system("cp ./platforms/www/mochiscript.js .")
end
desc "copy over bootstrap"
View
2 VERSION
@@ -1 +1 @@
-0.5.3
+0.5.5
View
399 mochiscript.js
@@ -0,0 +1,399 @@
+(function (window) {
+var log = window.console ? window.console.log : function () { };
+
+var $m = {
+ ROOT: window,
+ ADAPTER: {
+ out: log,
+ outs: log
+ },
+ PLATFORM: 'browser'
+};
+
+window.$m = $m;
+
+// CLASS HELPERS
+(function (undefined, $m) {
+
+ var OO = function (klass, par) {
+ this.klass = klass;
+ this.par = par;
+
+ this.members = {};
+ this.staticMembers = {};
+ this.children = [];
+ this.included = [];
+
+ if (this.par) this.par.OO.children.push(klass);
+ };
+
+ $m.PUSH_ROOT = function (r) {
+ this.ROOTS = this.ROOTS || [];
+ this.ROOTS.push(r);
+ this.ROOT = r;
+ };
+
+ $m.POP_ROOT = function () {
+ this.ROOTS = this.ROOTS || [];
+ if (this.ROOTS.length) {
+ this.ROOTS.pop();
+ this.ROOT = this.ROOTS[this.ROOTS.length-1];
+ }
+
+ };
+
+ OO.prototype = {
+ forbiddenMembers: {
+ 'prototype': undefined,
+ 'OO': undefined
+ },
+
+ include: function(module) {
+ this.included.push(module);
+ var members = module.OO.members;
+ for (var name in members) {
+ if (members.hasOwnProperty(name)) {
+ this.addMember(name, members[name]);
+ }
+ }
+
+ var staticMembers = module.OO.staticMembers;
+ for (var name in staticMembers) {
+ if (staticMembers.hasOwnProperty(name)) {
+ this.addStaticMember(name, staticMembers[name]);
+ }
+ }
+
+ if (typeof staticMembers['included'] == 'function') {
+ staticMembers['included'](this.klass);
+ }
+ },
+
+ createNamespace: function(name) {
+ var splitted = name.split('.');
+ var klassName = splitted.pop();
+ var root = $m.ROOT;
+
+ while (splitted.length > 0) {
+ var name = splitted.shift();
+ if (!root[name]) root[name] = $m.Class.extend({});
+ root = root[name];
+ }
+
+ return [ root, klassName ];
+ },
+
+ makeSuper: function(newMethod, oldMethod) {
+ if (!oldMethod) return newMethod;
+
+ return function() {
+ this.$super = oldMethod;
+ return newMethod.apply(this, arguments);
+ };
+ },
+
+ addMember: function(name, member) {
+ if (this.forbiddenMembers.hasOwnProperty(name)) return;
+
+ var proto = this.klass.prototype;
+ if (typeof proto[name] == 'function' && !(proto[name] instanceof RegExp)) {
+ member = this.makeSuper(member, proto[name]);
+ }
+
+ proto[name] = member;
+ this.members[name] = member;
+ },
+
+ addStaticMember: function(name, member) {
+ if (this.forbiddenMembers.hasOwnProperty(name)) return;
+
+ if (typeof this.klass[name] == 'function') {
+ if (!this.klass.hasOwnProperty(name)) {
+ member = this.makeSuper(member, this.klass[name]);
+ }
+ }
+
+ this.klass[name] = member;
+ this.staticMembers[name] = member;
+ }
+ };
+
+ $m.Class = function() { this.initialize.apply(this, arguments); };
+ $m.Class.OO = new OO($m.Class);
+ $m.Class.prototype = {
+ initialize: function () {},
+ oo: $m.Class.OO
+ };
+
+ var namedClasses = {};
+ $m.getClass = function(name) {
+ return namedClasses[name];
+ };
+
+ var noInit = false;
+ $m.Class.extend = function(name, klassDef) {
+ var klass = function() { if (!noInit) this.initialize.apply(this, arguments); };
+ klass.OO = new OO(klass, this);
+
+ if (typeof name != 'string') {
+ klassDef = name;
+ } else {
+ namedClasses[name] = klass;
+ var namespace = this.OO.createNamespace(name);
+ namespace[0][namespace[1]] = klass;
+ }
+
+ // create instance of this as prototype for new this
+ noInit = true;
+ var proto = new this();
+ noInit = false;
+
+ klass.prototype = proto;
+ var oo = klass.OO;
+ proto.OO = oo;
+
+ for (var name in this) {
+ oo.addStaticMember(name, this[name]);
+ }
+
+ if (typeof klassDef == 'function') {
+ klassDef(klass, oo);
+ } else {
+ for (var name in klassDef) {
+ oo.addMember(name, klassDef[name]);
+ }
+ }
+
+ return klass;
+ };
+
+ $m.Module = $m.Class;
+
+ var assert = {
+ 'eq': function(expected, actual) { if (expected != actual) $m.outs("Expected "+expected+", but got "+actual+".") },
+ 'isFalse': function(val) { if (val) $m.outs("Expected false, but got "+JSON.stringify(val)+".") },
+ 'isTrue': function(val) { if (!val) $m.outs("Expected true, but got " +val+".") }
+ };
+
+ $m.test = function(message, callback) {
+ if (!callback) callback = message;
+ callback(assert);
+ };
+
+ function addListener(type, listener) {
+ var events = this.__$events || (this.__$events = {});
+ this.emit('newListener', type, listener);
+ if (!events[type]) events[type] = [];
+ events[type].push(listener);
+ }
+
+ $m.out = function () {
+ for (var i=0,arg=null,_list_0=arguments,_len_0=_list_0.length;(arg=_list_0[i])||i<_len_0;i++){
+ $m.ADAPTER.out(arg);
+ if (i < arguments.length-1) {
+ $m.ADAPTER.out(',');
+ }
+ }
+ };
+
+ $m.outs = function () {
+ for (var _i_0=0,arg=null,_list_0=arguments,_len_0=_list_0.length;(arg=_list_0[_i_0])||_i_0<_len_0;_i_0++){
+ $m.ADAPTER.outs(arg);
+ }
+ };
+
+ return $m;
+})(undefined, $m);
+
+
+$m.Module.extend("EventEmitter", function(KLASS, OO){
+
+ var MAX_LISTENERS = 10;
+ var isArray = Array.isArray;
+
+
+ OO.addMember("emit", function(){var self=this;
+ var type = arguments[0];
+ // If there is no 'error' event listener then throw.
+ if (type === 'error') {
+ if (!this._events || !this._events.error ||
+ (isArray(this._events.error) && !this._events.error.length))
+ {
+ if (arguments[1] instanceof Error) {
+ throw arguments[1]; // Unhandled 'error' event
+ } else {
+ throw new Error("Uncaught, unspecified 'error' event.");
+ }
+ return false;
+ }
+ }
+
+ if (!this._events) return false;
+ var handler = this._events[type];
+ if (!handler) return false;
+
+ if (typeof handler == 'function') {
+ switch (arguments.length) {
+ // fast cases
+ case 1:
+ handler.call(this);
+ break;
+ case 2:
+ handler.call(this, arguments[1]);
+ break;
+ case 3:
+ handler.call(this, arguments[1], arguments[2]);
+ break;
+ // slower
+ default:
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+ handler.apply(this, args);
+ }
+ return true;
+
+ } else if (isArray(handler)) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+
+ var listeners = handler.slice();
+ for (var i = 0, l = listeners.length; i < l; i++) {
+ listeners[i].apply(this, args);
+ }
+ return true;
+
+ } else {
+ return false;
+ }
+
+ });
+
+ OO.addMember("addListener", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('addListener only takes instances of Function');
+ }
+
+ if (!this._events) this._events = {};
+
+ // To avoid recursion in the case that type == "newListeners"! Before
+ // adding it to the listeners, first emit "newListeners".
+ this.emit('newListener', type, typeof listener.listener === 'function' ?
+ listener.listener : listener);
+
+ if (!this._events[type]) {
+ // Optimize the case of one listener. Don't need the extra array object.
+ this._events[type] = listener;
+ } else if (isArray(this._events[type])) {
+
+ // If we've already got an array, just append.
+ this._events[type].push(listener);
+
+ } else {
+ // Adding the second element, need to change to array.
+ this._events[type] = [this._events[type], listener];
+
+ }
+
+ // Check for listener leak
+ if (isArray(this._events[type]) && !this._events[type].warned) {
+ var m;
+ if (MAX_LISTENERS !== undefined) {
+ m = MAX_LISTENERS;
+ } else {
+ m = defaultMaxListeners;
+ }
+
+ if (m && m > 0 && this._events[type].length > m) {
+ this._events[type].warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ this._events[type].length);
+ console.trace();
+ }
+ }
+
+ return this;
+ });
+
+ OO.addMember("on", function(type, listener){var self=this;
+ this.addListener(type, listener);
+ });
+
+ OO.addMember("once", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('.once only takes instances of Function');
+ }
+
+ function g() {
+ self.removeListener(type, g);
+ listener.apply(this, arguments);
+ };
+
+ g.listener = listener;
+ this.on(type, g);
+
+ return this;
+ });
+
+ OO.addMember("removeListener", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('removeListener only takes instances of Function');
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (!this._events || !this._events[type]) return this;
+
+ var list = this._events[type];
+
+ if (isArray(list)) {
+ var position = -1;
+ for (var i = 0, length = list.length; i < length; i++) {
+ if (list[i] === listener ||
+ (list[i].listener && list[i].listener === listener))
+ {
+ position = i;
+ break;
+ }
+ }
+
+ if (position < 0) return this;
+ list.splice(position, 1);
+ if (list.length == 0)
+ delete this._events[type];
+ } else if (list === listener ||
+ (list.listener && list.listener === listener))
+ {
+ delete this._events[type];
+ }
+
+ return this;
+ });
+
+ OO.addMember("removeAllListeners", function(type){var self=this;
+ if (arguments.length === 0) {
+ this._events = {};
+ return this;
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (type && this._events && this._events[type]) this._events[type] = null;
+ return this;
+ });
+
+ OO.addMember("listeners", function(type){var self=this;
+ if (!this._events) this._events = {};
+ if (!this._events[type]) this._events[type] = [];
+ if (!isArray(this._events[type])) {
+ this._events[type] = [this._events[type]];
+ }
+ return this._events[type];
+ });
+});
+
+$m.EventEmitter = $m.ROOT.EventEmitter;
+
+
+})(window);
View
2 platforms/gem/lib/mochiscript/version.rb
@@ -1,3 +1,3 @@
module Mochiscript
- VERSION = "0.5.3"
+ VERSION = "0.5.5"
end
View
2 platforms/npm/package.json
@@ -3,7 +3,7 @@
"description": "Javascript Dessert",
"keywords": [ "javascript", "language", "mochiscript", "compiler" ],
"author": "Jeff Su",
- "version": "0.5.3",
+ "version": "0.5.5",
"licenses": [ { "type": "MIT" }],
"engines": { "node": ">=0.4.0" },
"directories": { "lib": "./lib/mochiscript" },
View
399 platforms/www/mochiscript.js
@@ -0,0 +1,399 @@
+(function (window) {
+var log = window.console ? window.console.log : function () { };
+
+var $m = {
+ ROOT: window,
+ ADAPTER: {
+ out: log,
+ outs: log
+ },
+ PLATFORM: 'browser'
+};
+
+window.$m = $m;
+
+// CLASS HELPERS
+(function (undefined, $m) {
+
+ var OO = function (klass, par) {
+ this.klass = klass;
+ this.par = par;
+
+ this.members = {};
+ this.staticMembers = {};
+ this.children = [];
+ this.included = [];
+
+ if (this.par) this.par.OO.children.push(klass);
+ };
+
+ $m.PUSH_ROOT = function (r) {
+ this.ROOTS = this.ROOTS || [];
+ this.ROOTS.push(r);
+ this.ROOT = r;
+ };
+
+ $m.POP_ROOT = function () {
+ this.ROOTS = this.ROOTS || [];
+ if (this.ROOTS.length) {
+ this.ROOTS.pop();
+ this.ROOT = this.ROOTS[this.ROOTS.length-1];
+ }
+
+ };
+
+ OO.prototype = {
+ forbiddenMembers: {
+ 'prototype': undefined,
+ 'OO': undefined
+ },
+
+ include: function(module) {
+ this.included.push(module);
+ var members = module.OO.members;
+ for (var name in members) {
+ if (members.hasOwnProperty(name)) {
+ this.addMember(name, members[name]);
+ }
+ }
+
+ var staticMembers = module.OO.staticMembers;
+ for (var name in staticMembers) {
+ if (staticMembers.hasOwnProperty(name)) {
+ this.addStaticMember(name, staticMembers[name]);
+ }
+ }
+
+ if (typeof staticMembers['included'] == 'function') {
+ staticMembers['included'](this.klass);
+ }
+ },
+
+ createNamespace: function(name) {
+ var splitted = name.split('.');
+ var klassName = splitted.pop();
+ var root = $m.ROOT;
+
+ while (splitted.length > 0) {
+ var name = splitted.shift();
+ if (!root[name]) root[name] = $m.Class.extend({});
+ root = root[name];
+ }
+
+ return [ root, klassName ];
+ },
+
+ makeSuper: function(newMethod, oldMethod) {
+ if (!oldMethod) return newMethod;
+
+ return function() {
+ this.$super = oldMethod;
+ return newMethod.apply(this, arguments);
+ };
+ },
+
+ addMember: function(name, member) {
+ if (this.forbiddenMembers.hasOwnProperty(name)) return;
+
+ var proto = this.klass.prototype;
+ if (typeof proto[name] == 'function' && !(proto[name] instanceof RegExp)) {
+ member = this.makeSuper(member, proto[name]);
+ }
+
+ proto[name] = member;
+ this.members[name] = member;
+ },
+
+ addStaticMember: function(name, member) {
+ if (this.forbiddenMembers.hasOwnProperty(name)) return;
+
+ if (typeof this.klass[name] == 'function') {
+ if (!this.klass.hasOwnProperty(name)) {
+ member = this.makeSuper(member, this.klass[name]);
+ }
+ }
+
+ this.klass[name] = member;
+ this.staticMembers[name] = member;
+ }
+ };
+
+ $m.Class = function() { this.initialize.apply(this, arguments); };
+ $m.Class.OO = new OO($m.Class);
+ $m.Class.prototype = {
+ initialize: function () {},
+ oo: $m.Class.OO
+ };
+
+ var namedClasses = {};
+ $m.getClass = function(name) {
+ return namedClasses[name];
+ };
+
+ var noInit = false;
+ $m.Class.extend = function(name, klassDef) {
+ var klass = function() { if (!noInit) this.initialize.apply(this, arguments); };
+ klass.OO = new OO(klass, this);
+
+ if (typeof name != 'string') {
+ klassDef = name;
+ } else {
+ namedClasses[name] = klass;
+ var namespace = this.OO.createNamespace(name);
+ namespace[0][namespace[1]] = klass;
+ }
+
+ // create instance of this as prototype for new this
+ noInit = true;
+ var proto = new this();
+ noInit = false;
+
+ klass.prototype = proto;
+ var oo = klass.OO;
+ proto.OO = oo;
+
+ for (var name in this) {
+ oo.addStaticMember(name, this[name]);
+ }
+
+ if (typeof klassDef == 'function') {
+ klassDef(klass, oo);
+ } else {
+ for (var name in klassDef) {
+ oo.addMember(name, klassDef[name]);
+ }
+ }
+
+ return klass;
+ };
+
+ $m.Module = $m.Class;
+
+ var assert = {
+ 'eq': function(expected, actual) { if (expected != actual) $m.outs("Expected "+expected+", but got "+actual+".") },
+ 'isFalse': function(val) { if (val) $m.outs("Expected false, but got "+JSON.stringify(val)+".") },
+ 'isTrue': function(val) { if (!val) $m.outs("Expected true, but got " +val+".") }
+ };
+
+ $m.test = function(message, callback) {
+ if (!callback) callback = message;
+ callback(assert);
+ };
+
+ function addListener(type, listener) {
+ var events = this.__$events || (this.__$events = {});
+ this.emit('newListener', type, listener);
+ if (!events[type]) events[type] = [];
+ events[type].push(listener);
+ }
+
+ $m.out = function () {
+ for (var i=0,arg=null,_list_0=arguments,_len_0=_list_0.length;(arg=_list_0[i])||i<_len_0;i++){
+ $m.ADAPTER.out(arg);
+ if (i < arguments.length-1) {
+ $m.ADAPTER.out(',');
+ }
+ }
+ };
+
+ $m.outs = function () {
+ for (var _i_0=0,arg=null,_list_0=arguments,_len_0=_list_0.length;(arg=_list_0[_i_0])||_i_0<_len_0;_i_0++){
+ $m.ADAPTER.outs(arg);
+ }
+ };
+
+ return $m;
+})(undefined, $m);
+
+
+$m.Module.extend("EventEmitter", function(KLASS, OO){
+
+ var MAX_LISTENERS = 10;
+ var isArray = Array.isArray;
+
+
+ OO.addMember("emit", function(){var self=this;
+ var type = arguments[0];
+ // If there is no 'error' event listener then throw.
+ if (type === 'error') {
+ if (!this._events || !this._events.error ||
+ (isArray(this._events.error) && !this._events.error.length))
+ {
+ if (arguments[1] instanceof Error) {
+ throw arguments[1]; // Unhandled 'error' event
+ } else {
+ throw new Error("Uncaught, unspecified 'error' event.");
+ }
+ return false;
+ }
+ }
+
+ if (!this._events) return false;
+ var handler = this._events[type];
+ if (!handler) return false;
+
+ if (typeof handler == 'function') {
+ switch (arguments.length) {
+ // fast cases
+ case 1:
+ handler.call(this);
+ break;
+ case 2:
+ handler.call(this, arguments[1]);
+ break;
+ case 3:
+ handler.call(this, arguments[1], arguments[2]);
+ break;
+ // slower
+ default:
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+ handler.apply(this, args);
+ }
+ return true;
+
+ } else if (isArray(handler)) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+
+ var listeners = handler.slice();
+ for (var i = 0, l = listeners.length; i < l; i++) {
+ listeners[i].apply(this, args);
+ }
+ return true;
+
+ } else {
+ return false;
+ }
+
+ });
+
+ OO.addMember("addListener", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('addListener only takes instances of Function');
+ }
+
+ if (!this._events) this._events = {};
+
+ // To avoid recursion in the case that type == "newListeners"! Before
+ // adding it to the listeners, first emit "newListeners".
+ this.emit('newListener', type, typeof listener.listener === 'function' ?
+ listener.listener : listener);
+
+ if (!this._events[type]) {
+ // Optimize the case of one listener. Don't need the extra array object.
+ this._events[type] = listener;
+ } else if (isArray(this._events[type])) {
+
+ // If we've already got an array, just append.
+ this._events[type].push(listener);
+
+ } else {
+ // Adding the second element, need to change to array.
+ this._events[type] = [this._events[type], listener];
+
+ }
+
+ // Check for listener leak
+ if (isArray(this._events[type]) && !this._events[type].warned) {
+ var m;
+ if (MAX_LISTENERS !== undefined) {
+ m = MAX_LISTENERS;
+ } else {
+ m = defaultMaxListeners;
+ }
+
+ if (m && m > 0 && this._events[type].length > m) {
+ this._events[type].warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ this._events[type].length);
+ console.trace();
+ }
+ }
+
+ return this;
+ });
+
+ OO.addMember("on", function(type, listener){var self=this;
+ this.addListener(type, listener);
+ });
+
+ OO.addMember("once", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('.once only takes instances of Function');
+ }
+
+ function g() {
+ self.removeListener(type, g);
+ listener.apply(this, arguments);
+ };
+
+ g.listener = listener;
+ this.on(type, g);
+
+ return this;
+ });
+
+ OO.addMember("removeListener", function(type, listener){var self=this;
+ if ('function' !== typeof listener) {
+ throw new Error('removeListener only takes instances of Function');
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (!this._events || !this._events[type]) return this;
+
+ var list = this._events[type];
+
+ if (isArray(list)) {
+ var position = -1;
+ for (var i = 0, length = list.length; i < length; i++) {
+ if (list[i] === listener ||
+ (list[i].listener && list[i].listener === listener))
+ {
+ position = i;
+ break;
+ }
+ }
+
+ if (position < 0) return this;
+ list.splice(position, 1);
+ if (list.length == 0)
+ delete this._events[type];
+ } else if (list === listener ||
+ (list.listener && list.listener === listener))
+ {
+ delete this._events[type];
+ }
+
+ return this;
+ });
+
+ OO.addMember("removeAllListeners", function(type){var self=this;
+ if (arguments.length === 0) {
+ this._events = {};
+ return this;
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (type && this._events && this._events[type]) this._events[type] = null;
+ return this;
+ });
+
+ OO.addMember("listeners", function(type){var self=this;
+ if (!this._events) this._events = {};
+ if (!this._events[type]) this._events[type] = [];
+ if (!isArray(this._events[type])) {
+ this._events[type] = [this._events[type]];
+ }
+ return this._events[type];
+ });
+});
+
+$m.EventEmitter = $m.ROOT.EventEmitter;
+
+
+})(window);
View
16 src/platforms/gem/vendor/assets/javascripts/mochiscript.js.erb
@@ -1,16 +0,0 @@
-(function (window) {
-var log = window.console ? window.console.log : function () { };
-
-var $m = {
- ROOT: window,
- ADAPTER: {
- out: log,
- outs: log
- },
- PLATFORM: 'browser'
-};
-
-window.$m = $m;
-
-<%= @boot %>
-})(window);
View
1 src/platforms/gem/vendor/assets/javascripts/mochiscript.js.erb
View
16 src/platforms/www/mochiscript.js.erb
@@ -0,0 +1,16 @@
+(function (window) {
+var log = window.console ? window.console.log : function () { };
+
+var $m = {
+ ROOT: window,
+ ADAPTER: {
+ out: log,
+ outs: log
+ },
+ PLATFORM: 'browser'
+};
+
+window.$m = $m;
+
+<%= @boot %>
+})(window);

0 comments on commit 9a87745

Please sign in to comment.
Something went wrong with that request. Please try again.