Move parsing into loadStylesheet from loadFile

This commit is contained in:
Luke Page
2013-03-19 11:14:28 +00:00
parent 806ddb64e6
commit d907cccf6f
2 changed files with 23 additions and 17 deletions

View File

@@ -248,11 +248,23 @@ function extractUrlParts(url, baseUrl) {
}
function loadStyleSheet(sheet, callback, reload, remaining) {
loadFile(sheet, function(e, root, data, sheet, webInfo, path) {
loadFile(sheet, function(e, root, data, sheet, webInfo, path, env) {
if (webInfo) {
webInfo.remaining = remaining;
}
callback(e, root, data, sheet, webInfo, path);
if (data) {
new(less.Parser)(env).parse(data, function (e, root) {
if (e) { return callback(e, null, null, sheet); }
try {
callback(e, root, data, sheet, webInfo, path);
} catch (e) {
callback(e, null, null, sheet);
}
});
} else {
callback(e, root, data, sheet, webInfo, path);
}
}, reload);
}
@@ -312,20 +324,14 @@ function loadFile(sheet, callback, reload) {
env.paths = [hrefParts.path];
env.currentFileInfo = newFileInfo;
new(less.Parser)(env).parse(data, function (e, root) {
if (e) { return callback(e, null, null, sheet); }
try {
callback(e, root, data, sheet, { local: false, lastModified: lastModified }, href);
//TODO - there must be a better way? A generic less-to-css function that can both call error
//and removeNode where appropriate
//should also add tests
if (env.currentFileInfo.rootFilename === href) {
removeNode(document.getElementById('less-error-message:' + extractId(href)));
}
} catch (e) {
callback(e, null, null, sheet);
}
});
//TODO - there must be a better way? A generic less-to-css function that can both call error
//and removeNode where appropriate
//should also add tests
if (newFileInfo.rootFilename === href) {
removeNode(document.getElementById('less-error-message:' + extractId(href)));
}
callback(null, null, data, sheet, { local: false, lastModified: lastModified }, href, env)
} catch (e) {
callback(e, null, null, sheet);
}