~tnurlygayanov/murano/reliase-0.1a

« back to all changes in this revision

Viewing changes to murano-dashboard/bin/lib/less/tree/call.js

  • Committer: Timur Nurlygayanov
  • Date: 2013-05-30 22:18:42 UTC
  • Revision ID: tnulrygayanov@mirantis.com-20130530221842-8e7xd8e89e99n3xz
murano-0.1a

Show diffs side-by-side

added added

removed removed

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