Skip to content

Commit

Permalink
feat(plugins): track plugin id for relative resource loading without …
Browse files Browse the repository at this point in the history
…system hack
  • Loading branch information
EisenbergEffect committed Jan 16, 2015
1 parent 0275251 commit 3465e84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/aurelia.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import * as LogManager from 'aurelia-logging';
import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {
BindingLanguage,
ResourceCoordinator,
ViewSlot,
ResourceRegistry,
CompositionEngine
} from 'aurelia-templating';
import {BindingLanguage, ResourceCoordinator, ViewSlot, ResourceRegistry, CompositionEngine} from 'aurelia-templating';
import {Plugins} from './plugins';

var logger = LogManager.getLogger('aurelia'),
Expand All @@ -19,7 +13,7 @@ function loadResources(container, resourcesToLoad, appResources){

function next(){
if(current = resourcesToLoad.shift()){
return resourceCoordinator.importResources(current).then(resources => {
return resourceCoordinator.importResources(current, current.resourceManifestUrl).then(resources => {
resources.forEach(x => x.register(appResources));
return next();
});
Expand Down Expand Up @@ -48,6 +42,10 @@ export class Aurelia {
this.resourcesToLoad = [];
this.plugins = new Plugins(this);

if(!this.resources.baseResourcePath){
this.resources.baseResourcePath = System.baseUrl || '';
}

this.withInstance(Aurelia, this);
this.withInstance(Loader, this.loader);
this.withInstance(ResourceRegistry, this.resources);
Expand Down Expand Up @@ -87,12 +85,9 @@ export class Aurelia {
* @return {Aurelia} Returns the current Aurelia instance.
*/
withResources(resources){
if (Array.isArray(resources)) {
this.resourcesToLoad.push(resources);
} else {
this.resourcesToLoad.push(slice.call(arguments));
}

var toAdd = Array.isArray(resources) ? resources : slice.call(arguments);
toAdd.resourceManifestUrl = this.currentPluginId;
this.resourcesToLoad.push(toAdd);
return this;
}

Expand Down
5 changes: 5 additions & 0 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ var logger = LogManager.getLogger('aurelia');
function loadPlugin(aurelia, loader, info){
logger.debug(`Loading plugin ${info.moduleId}.`);

aurelia.currentPluginId = info.moduleId;

return loader.loadModule(info.moduleId, '').then(exportedValue => {
if('install' in exportedValue){
var result = exportedValue.install(aurelia, info.config || {});

if(result){
return result.then(() =>{
aurelia.currentPluginId = null;
logger.debug(`Installed plugin ${info.moduleId}.`);
});
}else{
Expand All @@ -19,6 +22,8 @@ function loadPlugin(aurelia, loader, info){
}else{
logger.debug(`Loaded plugin ${info.moduleId}.`);
}

aurelia.currentPluginId = null;
});
}

Expand Down

0 comments on commit 3465e84

Please sign in to comment.