Permalink
Browse files

refactor

  • Loading branch information...
1 parent 5673c58 commit d73f3faf8a49d13cd9f1366a7c5344b527f23ef7 @maccman committed Apr 19, 2012
@@ -1,4 +1,64 @@
-module.exports = (function(){
+(function() {
+ 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;
+}).call(this);
+this.require.define({"app/parsers/color":function(exports, require, module){module.exports = (function(){
/*
* Generated by PEG.js 0.6.2.
*
@@ -798,3 +858,4 @@ module.exports = (function(){
return result;
})();
+;}});
Oops, something went wrong.

0 comments on commit d73f3fa

Please sign in to comment.