mirror of
https://github.com/less/less.js.git
synced 2026-02-12 16:05:03 -05:00
Fix data-uri relative url to be relative in the same way as normal url's
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user