UNPKG

797 BJavaScriptView Raw
1var _ = require("underscore"),
2structr = require("structr");
3
4exports = module.exports = structr({
5
6 /**
7 */
8
9 "__construct": function(plugins, loaders) {
10 this._plugins = plugins;
11 this._loaders = loaders;
12 this._sortLoaders();
13 },
14
15 /**
16 */
17
18 "addLoaderClass": function(loaderClass) {
19 this._loaders.push(loaderClass);
20 },
21
22 /**
23 */
24
25 "getLoader": function(source) {
26 var self = this;
27 var clazz = _.find(this._loaders, function(loader) {
28 return loader.test(source, self._plugins.loader);
29 });
30
31 if(!clazz) {
32 throw new Error("unable to find plugin loader for \"" + source + "\".");
33 }
34
35 return new clazz(source, this, this._plugins);
36 },
37
38 /**
39 */
40
41 "_sortLoaders": function() {
42 this._loaders.sort(function(a, b) {
43 return a.priority > b.priority ? -1 : 1;
44 });
45 }
46});