-
-
Save gilligan/00206343c41331ac9ce6 to your computer and use it in GitHub Desktop.
stitch output example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(/*! Stitch !*/) { | |
if (!this.require) { | |
var modules = {}, cache = {}; | |
var require = function(name, root) { | |
var path = expand(root, name), indexPath = expand(path, './index'), module, fn; | |
module = cache[path] || cache[indexPath]; | |
if (module) { | |
return module; | |
} else if (fn = modules[path] || modules[path = indexPath]) { | |
module = {id: path, exports: {}}; | |
cache[path] = module.exports; | |
fn(module.exports, function(name) { | |
return require(name, dirname(path)); | |
}, module); | |
return cache[path] = module.exports; | |
} else { | |
throw 'module ' + name + ' not found'; | |
} | |
}; | |
var expand = function(root, name) { | |
var results = [], parts, part; | |
// If path is relative | |
if (/^\.\.?(\/|$)/.test(name)) { | |
parts = [root, name].join('/').split('/'); | |
} else { | |
parts = name.split('/'); | |
} | |
for (var i = 0, length = parts.length; i < length; i++) { | |
part = parts[i]; | |
if (part == '..') { | |
results.pop(); | |
} else if (part != '.' && part != '') { | |
results.push(part); | |
} | |
} | |
return results.join('/'); | |
}; | |
var dirname = function(path) { | |
return path.split('/').slice(0, -1).join('/'); | |
}; | |
this.require = function(name) { | |
return require(name, ''); | |
}; | |
this.require.define = function(bundle) { | |
for (var key in bundle) { | |
modules[key] = bundle[key]; | |
} | |
}; | |
this.require.modules = modules; | |
this.require.cache = cache; | |
} | |
return this.require.define; | |
}).call(this)({ | |
"models/orm": function(exports, require, module) { | |
module.exports = "A ORM"; | |
}, "models/user": function(exports, require, module) { | |
var ORM = require('models/orm'); | |
var User = Dove.Class.sub(); | |
User.extend(ORM); | |
}, "index": function(exports, require, module) { | |
require('models/user'); | |
// Do some stuff | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment