Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref ticket #2 - Added browser support #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions Jakefile
@@ -0,0 +1,41 @@
var browserify = require('browserify');
var uglifyjs = require('uglify-js');
var fs = require('fs');
desc('Builds Ctor for the browser');
task('build', function () {
jake.Task['ascii'].invoke();
console.log('Building ctor.js');
// First we generate an unminified, browser version of ctor
browserify('./index.js').bundle({standalone: 'ctor'}, function (err, src) {
if (err) {
console.log(err);
return;
}
// Stupid umd bug makes everything lowercase, so force fix it
src = src.replace(/\.ctor/g, ".Ctor");
// If there were no errors write to the file and then...
fs.writeFile('browser/ctor.js', src, function (err) {
if (err) {
console.log(err);
return;
}
console.log('Minifying ctor.js');
// ...if there were no errors, minify and write ctor.min.js
var minifiedCode = uglifyjs.minify('browser/ctor.js').code;
fs.writeFile('browser/ctor.min.js', minifiedCode, function(err) {
err ? console.log(err) : console.log('Build complete');
});
});
});
});

desc('Kick out the ascii');
task('ascii', function() {
var ascii = ''+
' ______ ______ ______ ______ \ \n'+
'/\\ ___\\ /\\__ _\\/\\ __ \\ /\\ == \\ \ \n'+
'\\ \\ \\____\\/_/\\ \\/\\ \\ \\/\\ \\\\ \\ __< \ \n'+
' \\ \\_____\\ \\ \\_\\ \\ \\_____\\\\ \\_\\ \\_\\ \ \n'+
' \\/_____/ \\/_/ \\/_____/ \\/_/ /_/ \ \n'
console.log(ascii);
});
147 changes: 147 additions & 0 deletions browser/ctor.js
@@ -0,0 +1,147 @@
(function(e){if("function"==typeof bootstrap)bootstrap("ctor",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeCtor=e}else"undefined"!=typeof window?window.Ctor=e():global.Ctor=e()})(function(){var define,ses,bootstrap,module,exports;
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0](function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
var inherits = require('inherits')
, mixin = require('otools').mixin;

var slice = Array.prototype.slice;

function Ctor() {
if(!(this instanceof Ctor)) {
return Object.create(Ctor.prototype);
}
}

function createObj(ctor, args) {
var obj
, tmp;

obj = Object.create(ctor.prototype);

tmp = ctor.apply(obj, args);

// Always allow the constructor return value to override
if(tmp !== undefined) { obj = tmp; }

return obj;
}

function create() {
if(typeof this !== 'function') { throw new Error('create expects "this" to be a function'); }

var args = arguments.length ? slice.call(arguments) : undefined;
return createObj(this, args);
}

function extend(proto) {
if(typeof this !== 'function') { throw new Error('extend expects "this" to be a function'); }

var parent = this
, ctor
, base;

if(proto && typeof proto.constructor === 'function') {
base = proto.constructor;
delete proto.constructor;
}

ctor = function() {
var obj = this
, tmp;

if(!(obj instanceof ctor)) {
obj = Object.create(ctor);
}

parent.apply(obj, arguments);

if(base) {
tmp = base.apply(obj, arguments);
if(tmp) { obj = tmp; }
}

return obj;
}

inherits(ctor, parent, proto)

mixin(ctor, Ctor);

return ctor;
}

Ctor.extend = extend;
Ctor.create = create;

module.exports = Ctor;

},{"inherits":2,"otools":3}],2:[function(require,module,exports){
module.exports = inherits

function inherits (c, p, proto) {
proto = proto || {}
var e = {}
;[c.prototype, proto].forEach(function (s) {
Object.getOwnPropertyNames(s).forEach(function (k) {
e[k] = Object.getOwnPropertyDescriptor(s, k)
})
})
c.prototype = Object.create(p.prototype, e)
c.super = p
}

//function Child () {
// Child.super.call(this)
// console.error([this
// ,this.constructor
// ,this.constructor === Child
// ,this.constructor.super === Parent
// ,Object.getPrototypeOf(this) === Child.prototype
// ,Object.getPrototypeOf(Object.getPrototypeOf(this))
// === Parent.prototype
// ,this instanceof Child
// ,this instanceof Parent])
//}
//function Parent () {}
//inherits(Child, Parent)
//new Child

},{}],3:[function(require,module,exports){
var slice = Array.prototype.slice;

var each = function(o, fn) {
for(var k in o) {
fn.call(o, o[k], k);
}
}

var eachOwn = function(o, fn) {
var keys = Object.keys(o);

for(var i = 0, k; i < keys.length; i++) {
k = keys[i];
fn.call(o, o[k], k);
}
}

var mixin = function(target, source) {
var args = arguments.length > 2 ? slice.call(arguments,1) : [source];

for(var i = 0; i < args.length; i++) {
source = args[i];
if(!source) { continue; }

for(var k in source) {
target[k] = source[k];
}
}

return target;
}

exports.each = each;
exports.eachOwn = eachOwn;
exports.mixin = mixin;

},{}]},{},[1])(1)
});
;
1 change: 1 addition & 0 deletions browser/ctor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -23,6 +23,8 @@
"otools": "*"
},
"devDependencies": {
"tape": "*"
"tape": "*",
"uglify-js": "2.2.x",
"browserify": "2.11.x"
}
}