|
|
|
@ -14,6 +14,8 @@ if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
|
|
|
|
|
tree.Import = function Import(path, imports) {
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
this._path = path;
|
|
|
|
|
|
|
|
|
|
// The '.less' extension is optional
|
|
|
|
|
if (path instanceof tree.Quoted) {
|
|
|
|
|
this.path = /\.(le?|c)ss$/.test(path.content) ? path.content : path.content + '.less';
|
|
|
|
@ -21,9 +23,14 @@ tree.Import = function Import(path, imports) {
|
|
|
|
|
this.path = path.value.content || path.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imports.push(this.path, function (root) {
|
|
|
|
|
that.root = root;
|
|
|
|
|
});
|
|
|
|
|
this.css = /css$/.test(this.path);
|
|
|
|
|
|
|
|
|
|
// Only pre-compile .less files
|
|
|
|
|
if (! this.css) {
|
|
|
|
|
imports.push(this.path, function (root) {
|
|
|
|
|
that.root = root;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -36,16 +43,26 @@ tree.Import = function Import(path, imports) {
|
|
|
|
|
// ruleset.
|
|
|
|
|
//
|
|
|
|
|
tree.Import.prototype = {
|
|
|
|
|
toCSS: function () { return "" },
|
|
|
|
|
toCSS: function () {
|
|
|
|
|
if (this.css) {
|
|
|
|
|
return "@import " + this._path.toCSS() + ';\n';
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
eval: function () {
|
|
|
|
|
for (var i = 0; i < this.root.rules.length; i++) {
|
|
|
|
|
if (this.root.rules[i] instanceof tree.Import) {
|
|
|
|
|
Array.prototype
|
|
|
|
|
.splice
|
|
|
|
|
.apply(this.root.rules,
|
|
|
|
|
[i, 1].concat(this.root.rules[i].eval()));
|
|
|
|
|
if (this.css) {
|
|
|
|
|
return this;
|
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0; i < this.root.rules.length; i++) {
|
|
|
|
|
if (this.root.rules[i] instanceof tree.Import) {
|
|
|
|
|
Array.prototype
|
|
|
|
|
.splice
|
|
|
|
|
.apply(this.root.rules,
|
|
|
|
|
[i, 1].concat(this.root.rules[i].eval()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this.root.rules;
|
|
|
|
|
}
|
|
|
|
|
return this.root.rules;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|