Permalink
Browse files

Support other loaders

  • Loading branch information...
1 parent 9b431aa commit 28486f82ec87d27beb6dfcda5b35226d8f59c62c Charles Jolley committed Apr 21, 2010
Showing with 41 additions and 3 deletions.
  1. +23 −1 lib/package.js
  2. +8 −2 lib/seed.js
  3. +5 −0 lib/source.js
  4. +5 −0 lib/special-packages.js
View
@@ -40,7 +40,7 @@ Package.sliceDummyext = sliceDummyext;
Package.prototype.init = function(id, path, source) {
TIKI.Package.prototype.init.call(this, id, {});
this.path = path;
- this.source = this;
+ this.source = source || this;
this.normalized = {};
this.packageConfig = {};
this.localConfig = {};
@@ -285,6 +285,15 @@ Package.prototype._findModulePath = function(moduleId, extensions) {
return null;
};
+Package.prototype.getLoader = function() {
+ var source = this.source, ret = this._loader;
+
+ if (!ret && source && (source !== this) && source.getLoader) {
+ ret = this._loader = source.getLoader();
+ }
+
+ return ret ;
+};
Package.prototype.getReaders = function() {
var ret = this._readers;
@@ -293,6 +302,19 @@ Package.prototype.getReaders = function() {
'.js': { id: 'seed:reader', pkg: null },
'.node': { id: 'seed:next/native-reader', pkg: null }
};
+
+ var loader = this.getLoader();
+ if (loader) {
+ var packages = loader.catalogPackages(this);
+ packages.forEach(function(pkg) {
+ var readers = pkg.get('seed:readers');
+ if (!readers) return;
+
+ var keys = Object.keys(readers),
+ loc = keys.length;
+ while(--loc>=0) ret[keys[loc]] = { id: readers[keys[loc]], pkg: pkg };
+ });
+ }
}
return ret ;
} ;
View
@@ -180,7 +180,7 @@ Seed.prototype.openPackage = function(path) {
var cache = this._directPackages;
if (!cache) cache = this._directPackages = {};
if (cache[path]) return cache[path];
- cache[path] = new Package('::seed'+path, path);
+ cache[path] = new Package('::seed'+path, path, this);
return cache[path];
} ;
@@ -205,6 +205,11 @@ Seed.prototype.packageFor = function(canonicalId, workingPackage) {
} else return TIKI.Loader.prototype.packageFor.apply(this, arguments);
};
+// Used by packages
+Seed.prototype.getLoader = function() {
+ return this;
+};
+
// ..........................................................
// REGISTERING SOURCES
//
@@ -234,10 +239,11 @@ Seed.prototype.register = function(packagePath, domain) {
packagePath = CORE.path.join.apply(CORE.path, arguments);
packagePath = CORE.path.normalize(packagePath);
- ret = new Package('::'+packagePath, packagePath, null);
+ ret = new Package('::'+packagePath, packagePath, this);
} else {
ret = packagePath;
+ ret.loader = this; // for sources...
}
if (this.sources.indexOf(ret)<0) this.sources.unshift(ret);
View
@@ -103,6 +103,11 @@ Source.prototype.close = function() {
// SOURCE SUPPORT
//
+// used by packages
+Source.prototype.getLoader = function() {
+ return this.loader;
+};
+
Source.prototype._packageForPath = function(path) {
var ret = this.packagesByPath[path];
if (!ret) {
View
@@ -127,3 +127,8 @@ AnonymousPackage.prototype._findModulePath = function(moduleId, extensions) {
return null;
};
+
+
+DefaultPackage.prototype.getLoader = AnonymousPackage.prototype.getLoader =
+ function() { return this.loader; };
+

0 comments on commit 28486f8

Please sign in to comment.