Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (53 sloc) 1.74 KB
<% @identifier or= 'require' %>
(function(/*! Stitch !*/) {
if (!this.<%= @identifier %>) {
var modules = {}, cache = {}, require = function(name, root) {
var path = expand(root, name), indexPath = expand(path, './index'), fn;
var 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';
}
}, expand = function(root, name) {
var results = [], parts, part;
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('/');
}, dirname = function(path) {
return path.split('/').slice(0, -1).join('/');
};
this.<%= @identifier %> = {
modules: modules,
cache: cache,
require: function(name) {
return require(name, '');
},
define: function(bundle) {
for (var key in bundle)
modules[key] = bundle[key];
}
};
}
return this.<%= @identifier %>.define;
}).call(this)({
<%- (JSON.stringify(module.id) + ": function(exports, require, module) {#{module.compile()}}" for module in @modules).join(', ') %>
});
Jump to Line
Something went wrong with that request. Please try again.