~george-edison55/less/trunk

« back to all changes in this revision

Viewing changes to lib/less/tree/rule.js

  • Committer: Nathan Osman
  • Date: 2013-04-16 22:43:51 UTC
  • Revision ID: admin@quickmediasolutions.com-20130416224351-5juqujuu4itkwpat
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function (tree) {
 
2
 
 
3
tree.Rule = function (name, value, important, index, currentFileInfo, inline) {
 
4
    this.name = name;
 
5
    this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
 
6
    this.important = important ? ' ' + important.trim() : '';
 
7
    this.index = index;
 
8
    this.currentFileInfo = currentFileInfo;
 
9
    this.inline = inline || false;
 
10
 
 
11
    if (name.charAt(0) === '@') {
 
12
        this.variable = true;
 
13
    } else { this.variable = false }
 
14
};
 
15
 
 
16
tree.Rule.prototype = {
 
17
    type: "Rule",
 
18
    accept: function (visitor) {
 
19
        this.value = visitor.visit(this.value);
 
20
    },
 
21
    toCSS: function (env) {
 
22
        if (this.variable) { return "" }
 
23
        else {
 
24
            try {
 
25
                return this.name + (env.compress ? ':' : ': ') +
 
26
                   this.value.toCSS(env) +
 
27
                   this.important + (this.inline ? "" : ";");
 
28
            }
 
29
            catch(e) {
 
30
                e.index = this.index;
 
31
                e.filename = this.currentFileInfo.filename;
 
32
                throw e;
 
33
            }
 
34
        }
 
35
    },
 
36
    eval: function (env) {
 
37
        var strictMathsBypass = false;
 
38
        if (this.name === "font" && env.strictMaths === false) {
 
39
            strictMathsBypass = true;
 
40
            env.strictMaths = true;
 
41
        }
 
42
        try {
 
43
            return new(tree.Rule)(this.name,
 
44
                              this.value.eval(env),
 
45
                              this.important,
 
46
                              this.index, this.currentFileInfo, this.inline);
 
47
        }
 
48
        finally {
 
49
            if (strictMathsBypass) {
 
50
                env.strictMaths = false;
 
51
            }
 
52
        }
 
53
    },
 
54
    makeImportant: function () {
 
55
        return new(tree.Rule)(this.name,
 
56
                              this.value,
 
57
                              "!important",
 
58
                              this.index, this.currentFileInfo, this.inline);
 
59
    }
 
60
};
 
61
 
 
62
})(require('../tree'));