Permalink
Browse files

Support for setting a root for requires. Useful if you're doing many …

…requires in the same directory.
  • Loading branch information...
1 parent 060dcc9 commit 721357d572cfd02f135638c9c78a215077faeab2 @wagenet wagenet committed Nov 18, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/main.js
View
@@ -1,6 +1,7 @@
if (typeof document !== "undefined") {
(function() {
minispade = {
+ root: null,
modules: {},
loaded: {},
@@ -10,10 +11,14 @@ if (typeof document !== "undefined") {
if (!loaded) {
if (mod) {
- loaded = mod();
+ loaded = mod() || true;
minispade.loaded[name] = loaded;
} else {
- throw "The module '" + name + "' could not be found";
+ if (minispade.root && name.substr(0,minispade.root.length) !== minispade.root) {
+ return minispade.require(minispade.root+name);
+ } else {
+ throw "The module '" + name + "' could not be found";
+ }
}
}
@@ -35,4 +40,4 @@ if (typeof document !== "undefined") {
}
});
})();
-}
+}

0 comments on commit 721357d

Please sign in to comment.