Skip to content

Commit

Permalink
Add shim code
Browse files Browse the repository at this point in the history
  • Loading branch information
retro committed Sep 25, 2012
1 parent 28fa41e commit 2f7d799
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions steal.js
Expand Up @@ -716,8 +716,49 @@
})
}
})

return uri;
}

steal.config.shim = function(shims){

for(var id in shims){
var resource = Resource.make(id);
if(typeof shims[id] === "object"){
var needs = shims[id].deps || []
if(typeof shims[id].exports === "string"){
var exports = (function(_exports){
return function(){
return win[_exports];
}
})(shims[id].exports)
} else {
exports = shims[id].exports;
}
} else {
needs = shims[id];
}
(function(_resource, _needs){
_resource.options.needs = _needs;
})(resource, needs)

if(exports){
resource.exports = (function(_resource, _exports, _needs){
return function(){
var args = _needs.map(function(id){
return Resource.make(id).value;
})
_resource.value = _exports.apply(null, args)
return _resource.value
}
})(resource, exports, needs)
}
}

}



// for a given ID, where should I find this resource
/**
* `steal.idToUri( id, noJoin )` takes an id and returns a URI that
Expand Down Expand Up @@ -785,7 +826,6 @@
}
}
options.id = steal.id(options.id, curId);

// set the ext
options.ext = options.id.ext();

Expand Down Expand Up @@ -1087,7 +1127,6 @@
var uri = URI.cur,
self = this,
cur = steal.cur;

this.options = {
fn: function() {

Expand Down Expand Up @@ -1178,9 +1217,13 @@
// will load from it.
// rootSrc needs to be the translated path
// we need id vs rootSrc ...

if ( this.options.id ) {
URI.cur = URI(this.options.id);
}
if( this.exports ){
this.exports()
}
// set this as the current resource
steal.cur = this;

Expand Down

0 comments on commit 2f7d799

Please sign in to comment.