Fix data-uri relative url to be relative in the same way as normal url's

This commit is contained in:
Luke Page
2013-02-17 12:44:31 +00:00
parent f68337e450
commit e7cbc4c190
5 changed files with 19 additions and 10 deletions

View File

@@ -12,8 +12,9 @@
'dumpLineNumbers', // option - whether to dump line numbers
'compress', // option - whether to compress
'mime', // browser only - mime type for sheet import
'entryPath', // browser only, path of entry less file
'rootFilename' // browser only, href of the entry less file
'entryPath', // browser only - path of entry less file
'rootFilename', // browser only - href of the entry less file
'currentDirectory' // node only - the current directory
];
tree.parseEnv = function(options) {

View File

@@ -390,8 +390,8 @@ tree.functions = {
filePath = mimetype;
}
if (this.relativePath && this.env.isPathRelative(filePath)) {
filePath = path.join(this.relativePath, filePath);
if (this.currentDirectory && this.env.isPathRelative(filePath)) {
filePath = path.join(this.currentDirectory, filePath);
}
// detect the mimetype if not given
@@ -497,10 +497,10 @@ function clamp(val) {
return Math.min(1, Math.max(0, val));
}
tree.functionCall = function(env, rootpath, relativePath) {
tree.functionCall = function(env, rootpath, currentDirectory) {
this.env = env;
this.rootpath = rootpath;
this.relativePath = relativePath;
this.currentDirectory = currentDirectory;
};
tree.functionCall.prototype = tree.functions;

View File

@@ -124,6 +124,9 @@ less.Parser.importer = function (file, paths, callback, env) {
if(env.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
env.rootpath = env.rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
}
if (env.relativeUrls) {
env.currentDirectory = pathname.replace(/[^\\\/]*$/, "");
}
env.contents[pathname] = data; // Updating top importing parser content cache.
env.paths = [dirname].concat(paths);

View File

@@ -71,6 +71,11 @@ less.Parser = function Parser(env) {
env = new tree.parseEnv(env);
}
if (!env.currentDirectory && env.filename) {
// only works for node, only used for node
env.currentDirectory = env.filename.replace(/[^\/\\]*$/, "");
}
// This function is called after all files
// have been imported through `@import`.
var finish = function () {};
@@ -630,7 +635,7 @@ less.Parser = function Parser(env) {
return;
}
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath, env.rootpath || env.paths[0]); }
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath, env.currentDirectory); }
},
arguments: function () {
var args = [], arg;

View File

@@ -3,13 +3,13 @@
//
// A function call node.
//
tree.Call = function (name, args, index, filename, rootpath, relativePath) {
tree.Call = function (name, args, index, filename, rootpath, currentDirectory) {
this.name = name;
this.args = args;
this.index = index;
this.filename = filename;
this.rootpath = rootpath;
this.relativePath = relativePath;
this.currentDirectory = currentDirectory;
};
tree.Call.prototype = {
//
@@ -32,7 +32,7 @@ tree.Call.prototype = {
if (nameLC in tree.functions) { // 1.
try {
func = new tree.functionCall(env, this.rootpath, this.relativePath);
func = new tree.functionCall(env, this.rootpath, this.currentDirectory);
result = func[nameLC].apply(func, args);
if (result != null) {
return result;