source: Dev/branches/rest-dojo-ui/client/util/less/tree/call.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1(function (tree) {
2
3//
4// A function call node.
5//
6tree.Call = function (name, args, index) {
7    this.name = name;
8    this.args = args;
9    this.index = index;
10};
11tree.Call.prototype = {
12    //
13    // When evaluating a function call,
14    // we either find the function in `tree.functions` [1],
15    // in which case we call it, passing the  evaluated arguments,
16    // or we simply print it out as it appeared originally [2].
17    //
18    // The *functions.js* file contains the built-in functions.
19    //
20    // The reason why we evaluate the arguments, is in the case where
21    // we try to pass a variable to a function, like: `saturate(@color)`.
22    // The function should receive the value, not the variable.
23    //
24    eval: function (env) {
25        var args = this.args.map(function (a) { return a.eval(env) });
26
27        if (this.name in tree.functions) { // 1.
28            try {
29                return tree.functions[this.name].apply(tree.functions, args);
30            } catch (e) {
31                throw { message: "error evaluating function `" + this.name + "`",
32                        index: this.index };
33            }
34        } else { // 2.
35            return new(tree.Anonymous)(this.name +
36                   "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
37        }
38    },
39
40    toCSS: function (env) {
41        return this.eval(env).toCSS();
42    }
43};
44
45})(require('less/tree'));
Note: See TracBrowser for help on using the repository browser.