MCPcopy
hub / github.com/CodeboxIDE/codebox / loadFile

Function loadFile

core/cb.addons/require-tools/less/lessc.js:6692–6753  ·  view source on GitHub ↗
(originalHref, currentFileInfo, callback, env, newVars)

Source from the content-addressed store, hash-verified

6690}
6691
6692function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
6693
6694 if (currentFileInfo && currentFileInfo.currentDirectory && !/^([a-z-]+:)?\//.test(originalHref)) {
6695 originalHref = currentFileInfo.currentDirectory + originalHref;
6696 }
6697
6698 // sheet may be set to the stylesheet for the initial load or a collection of properties including
6699 // some env variables for imports
6700 var hrefParts = extractUrlParts(originalHref, window.location.href);
6701 var href = hrefParts.url;
6702 var newFileInfo = {
6703 currentDirectory: hrefParts.path,
6704 filename: href
6705 };
6706
6707 if (currentFileInfo) {
6708 newFileInfo.entryPath = currentFileInfo.entryPath;
6709 newFileInfo.rootpath = currentFileInfo.rootpath;
6710 newFileInfo.rootFilename = currentFileInfo.rootFilename;
6711 newFileInfo.relativeUrls = currentFileInfo.relativeUrls;
6712 } else {
6713 newFileInfo.entryPath = hrefParts.path;
6714 newFileInfo.rootpath = less.rootpath || hrefParts.path;
6715 newFileInfo.rootFilename = href;
6716 newFileInfo.relativeUrls = env.relativeUrls;
6717 }
6718
6719 if (newFileInfo.relativeUrls) {
6720 if (env.rootpath) {
6721 newFileInfo.rootpath = extractUrlParts(env.rootpath + pathDiff(hrefParts.path, newFileInfo.entryPath)).path;
6722 } else {
6723 newFileInfo.rootpath = hrefParts.path;
6724 }
6725 }
6726
6727 if (env.useFileCache && fileCache[href]) {
6728 try {
6729 var lessText = fileCache[href];
6730 if (newVars) {
6731 lessText += "\n" + newVars;
6732 }
6733 callback(null, lessText, href, newFileInfo, { lastModified: new Date() });
6734 } catch (e) {
6735 callback(e, null, href);
6736 }
6737 return;
6738 }
6739
6740 doXHR(href, env.mime, function (data, lastModified) {
6741 // per file cache
6742 fileCache[href] = data;
6743
6744 // Use remote copy (re-parse)
6745 try {
6746 callback(null, data, href, newFileInfo, { lastModified: lastModified });
6747 } catch (e) {
6748 callback(e, null, href);
6749 }

Callers 1

loadStyleSheetFunction · 0.70

Calls 4

extractUrlPartsFunction · 0.85
pathDiffFunction · 0.85
doXHRFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected