Skip to content

Commit

Permalink
feat(resource-coordinator): enable load resources relative to a manif…
Browse files Browse the repository at this point in the history
…est file
  • Loading branch information
EisenbergEffect committed Jan 16, 2015
1 parent e507251 commit 98a5f01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/resource-coordinator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {Loader} from 'aurelia-loader';
import {relativeToFile, join} from 'aurelia-path';
import {Container} from 'aurelia-dependency-injection';
import {getAnnotation, addAnnotation, ResourceType, Origin} from 'aurelia-metadata';
import {ValueConverter} from 'aurelia-binding';
import {CustomElement} from './custom-element';
import {AttachedBehavior} from './attached-behavior';
import {TemplateController} from './template-controller';
import {ViewEngine} from './view-engine';
import {ResourceRegistry} from './resource-registry';

var id = 0;

Expand All @@ -14,13 +16,14 @@ function nextId(){
}

export class ResourceCoordinator {
static inject(){ return [Loader, Container, ViewEngine]; }
constructor(loader, container, viewEngine){
static inject(){ return [Loader, Container, ViewEngine, ResourceRegistry]; }
constructor(loader, container, viewEngine, appResources){
this.loader = loader;
this.container = container;
this.viewEngine = viewEngine;
this.importedModules = {};
this.importedAnonymous = {};
this.appResources = appResources;
viewEngine.resourceCoordinator = this;
}

Expand Down Expand Up @@ -79,15 +82,29 @@ export class ResourceCoordinator {
});
}

importResources(imports){
importResources(imports, resourceManifestUrl){
var i, ii, current, annotation, existing,
lookup = {},
finalModules = [],
importIds = [];
importIds = [], analysis, type;

for(i = 0, ii = imports.length; i < ii; ++i){
current = imports[i];
annotation = Origin.get(current);

if(!annotation){
analysis = analyzeModule({'default':current});
type = (analysis.element || analysis.resources[0]).type;

if(resourceManifestUrl){
annotation = new Origin(relativeToFile("./" + type.name, resourceManifestUrl));
}else{
annotation = new Origin(join(this.appResources.baseResourceUrl, type.name));
}

Origin.set(current, annotation);
}

existing = lookup[annotation.moduleId];

if(!existing){
Expand Down Expand Up @@ -172,16 +189,20 @@ export class ResourceCoordinator {

class ResourceModule {
constructor(source, element, resources){
var i, ii;
var i, ii, org;

this.source = source;
this.element = element;
this.resources = resources;

if(element){
this.id = Origin.get(element.value).moduleId;
org = Origin.get(element.value);
}else if(resources.length){
this.id = Origin.get(resources[0].value).moduleId;
org = Origin.get(resources[0].value);
}

if(org){
this.id = org.id;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/resource-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class ResourceRegistry {
this.elements = {};
this.valueConverters = {};
this.attributeMap = {};
this.baseResourceUrl = '';
}

registerElement(tagName, behavior){
Expand Down

0 comments on commit 98a5f01

Please sign in to comment.