make env available to functions. Fix the path for the data-uri function in the browser. Fixes #997

This commit is contained in:
Luke Page
2013-01-04 20:26:52 +00:00
parent aa9c47b5da
commit 4c2d01a316
4 changed files with 18 additions and 9 deletions

View File

@@ -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'));

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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');
}