assets/distil.js in distil-0.14.1 vs assets/distil.js in distil-0.14.2.a
- old
+ new
@@ -230,10 +230,11 @@
}
resource = resource.parent;
}
+ window.__filename__ = null;
currentResource = resource ? resource : rootResource;
};
var fetchComplete = function(resource)
{
@@ -393,30 +394,46 @@
injectionComplete(currentResource);
}
distil.kick = distil.moduleDidLoad;
+ /**
+ pathToAssetInModule(asset, module) -> String
+ - asset (String): The name or path of the asset.
+ - module (Object): The module definition from which to pull the asset
+ */
+ var pathToAssetInModule = function(asset, module)
+ {
+ // If the asset is in the asset_map, it is presumed to be relative to the
+ // module rather than the currently running script.
+ if (module.asset_map && module.asset_map[asset])
+ return module.path + module.asset_map[asset];
+
+ var path, url;
+
+ if (distil.sync)
+ url = getRunningScriptSource();
+ else
+ url = window.__filename__;
+
+ if (url)
+ {
+ var lastSlash = url.lastIndexOf('/');
+ path = url.substring(0, lastSlash + 1);
+ }
+ else
+ path= module.path;
+
+ return path + asset;
+ };
+
distil.urlForAssetWithNameInModule = function(asset, moduleName)
{
var module = moduleName ? moduleIndex[moduleName] : distil.mainModule;
if (!module)
throw new Error(NO_MODULE_ERROR + moduleName);
-
- var path;
- if (distil.sync)
- {
- var url = getRunningScriptSource();
- var lastSlash = url.lastIndexOf('/');
- path = url.substring(0, lastSlash + 1);
- }
- else
- path = module.path;
-
- if (!module.asset_map)
- return path + asset;
-
- return path + (module.asset_map[asset] || asset);
+ return pathToAssetInModule(asset, module);
}
distil.dataForAssetWithNameInModule = function(asset, moduleName)
{
var module = moduleName ? moduleIndex[moduleName] : distil.mainModule;
@@ -431,26 +448,16 @@
return data;
if (!module.asset_map)
return null;
- var path;
- if (distil.sync)
- {
- var url = getRunningScriptSource();
- var lastSlash = url.lastIndexOf('/');
- path = url.substring(0, lastSlash + 1);
- }
- else
- path = module.path;
+ var path= pathToAssetInModule(asset, module);
- var assetUrl = path + (module.asset_map[asset] || asset);
-
function oncomplete(unused, xhr)
{
module.assets[asset] = data = xhr.responseText;
}
- fetchAsset(assetUrl, oncomplete, null, null, true);
+ fetchAsset(path, oncomplete, null, null, true);
return data;
}
distil.asset = distil.dataForAssetWithNameInModule;
distil.assetUrl = distil.urlForAssetWithNameInModule;