4e251ee498e1cd3551ac4e232c778d27e0167536
[platform/framework/web/web-ui-fw.git] / build-tools / lib / less / tree / element.js
1 (function (tree) {
2
3 tree.Element = function (combinator, value, index) {
4     this.combinator = combinator instanceof tree.Combinator ?
5                       combinator : new(tree.Combinator)(combinator);
6
7     if (typeof(value) === 'string') {
8         this.value = value.trim();
9     } else if (value) {
10         this.value = value;
11     } else {
12         this.value = "";
13     }
14     this.index = index;
15 };
16 tree.Element.prototype.eval = function (env) {
17     return new(tree.Element)(this.combinator,
18                              this.value.eval ? this.value.eval(env) : this.value,
19                              this.index);
20 };
21 tree.Element.prototype.toCSS = function (env) {
22         var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);
23         if (value == '' && this.combinator.value.charAt(0) == '&') {
24                 return '';
25         } else {
26                 return this.combinator.toCSS(env || {}) + value;
27         }
28 };
29
30 tree.Combinator = function (value) {
31     if (value === ' ') {
32         this.value = ' ';
33     } else {
34         this.value = value ? value.trim() : "";
35     }
36 };
37 tree.Combinator.prototype.toCSS = function (env) {
38     return {
39         ''  : '',
40         ' ' : ' ',
41         ':' : ' :',
42         '+' : env.compress ? '+' : ' + ',
43         '~' : env.compress ? '~' : ' ~ ',
44         '>' : env.compress ? '>' : ' > ',
45         '|' : env.compress ? '|' : ' | '
46     }[this.value];
47 };
48
49 })(require('../tree'));