mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
make env available to functions. Fix the path for the data-uri function in the browser. Fixes #997
This commit is contained in:
@@ -349,7 +349,7 @@ tree.functions = {
|
||||
"data-uri": function(mimetype, path) {
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
return new less.tree.URL(path || mimetype, '');
|
||||
return new less.tree.URL(path || mimetype, this.rootpath).eval(this.env);
|
||||
}
|
||||
|
||||
mimetype = mimetype.value;
|
||||
@@ -412,4 +412,11 @@ function clamp(val) {
|
||||
return Math.min(1, Math.max(0, val));
|
||||
}
|
||||
|
||||
tree.functionCall = function(env, rootpath) {
|
||||
this.env = env;
|
||||
this.rootpath = rootpath;
|
||||
};
|
||||
|
||||
tree.functionCall.prototype = tree.functions;
|
||||
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -622,7 +622,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
if (! $(')')) return;
|
||||
|
||||
if (name) { return new(tree.Call)(name, args, index, env.filename) }
|
||||
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath) }
|
||||
},
|
||||
arguments: function () {
|
||||
var args = [], arg;
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
//
|
||||
// A function call node.
|
||||
//
|
||||
tree.Call = function (name, args, index, filename) {
|
||||
tree.Call = function (name, args, index, filename, rootpath) {
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
this.index = index;
|
||||
this.filename = filename;
|
||||
this.rootpath = rootpath;
|
||||
};
|
||||
tree.Call.prototype = {
|
||||
//
|
||||
@@ -25,11 +26,12 @@ tree.Call.prototype = {
|
||||
//
|
||||
eval: function (env) {
|
||||
var args = this.args.map(function (a) { return a.eval(env) }),
|
||||
result;
|
||||
result, func;
|
||||
|
||||
if (this.name in tree.functions) { // 1.
|
||||
try {
|
||||
result = tree.functions[this.name].apply(tree.functions, args);
|
||||
func = new tree.functionCall(env, this.rootpath);
|
||||
result = func[this.name].apply(func, args);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
url: url('http://localhost:8081/browser/less/Trebuchet');
|
||||
}
|
||||
#data-uri {
|
||||
uri: url('test/data/image.jpg');
|
||||
uri: url('http://localhost:8081/browser/less/test/data/image.jpg');
|
||||
}
|
||||
#data-uri-guess {
|
||||
uri: url('test/data/image.jpg');
|
||||
uri: url('http://localhost:8081/browser/less/test/data/image.jpg');
|
||||
}
|
||||
#data-uri-ascii {
|
||||
uri-1: url('test/data/page.html');
|
||||
uri-2: url('test/data/page.html');
|
||||
uri-1: url('http://localhost:8081/browser/less/test/data/page.html');
|
||||
uri-2: url('http://localhost:8081/browser/less/test/data/page.html');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user