Allow adding plugins via @import (plugin)

This commit is contained in:
rjgotten
2015-02-25 17:36:00 +01:00
parent 51ead08691
commit 83db6e8d90
3 changed files with 19 additions and 5 deletions

View File

@@ -64,7 +64,7 @@ module.exports = function(environment) {
return;
}
if (tryAppendLessExtension) {
if (tryAppendLessExtension && !importOptions.plugin) {
path = fileManager.tryAppendLessExtension(path);
}
@@ -101,7 +101,19 @@ module.exports = function(environment) {
newFileInfo.reference = true;
}
if (importOptions.inline) {
if (importOptions.plugin) {
try {
var plugin = require(resolvedFilename);
if ( -1 === newEnv.pluginManager.installedPlugins.indexOf( plugin )) {
newEnv.pluginManager.addPlugin(plugin);
}
fileParsedFunc(null, "", resolvedFilename);
} catch(e) {
fileParsedFunc(e, "", resolvedFilename);
}
} else if (importOptions.inline) {
fileParsedFunc(null, contents, resolvedFilename);
} else {
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {

View File

@@ -1212,7 +1212,7 @@ var Parser = function Parser(context, imports, fileInfo) {
},
importOption: function() {
var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/);
var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional|plugin)/);
if (opt) {
return opt[1];
}

View File

@@ -50,7 +50,7 @@ Import.prototype.accept = function (visitor) {
this.features = visitor.visit(this.features);
}
this.path = visitor.visit(this.path);
if (!this.options.inline && this.root) {
if (!this.options.plugin && !this.options.inline && this.root) {
this.root = visitor.visit(this.root);
}
};
@@ -120,7 +120,9 @@ Import.prototype.eval = function (context) {
}
}
if (this.options.inline) {
if (this.options.plugin) {
return [];
} else if (this.options.inline) {
var contents = new Anonymous(this.root, 0, {filename: this.importedFilename}, true, true);
return this.features ? new Media([contents], this.features.value) : [contents];
} else if (this.css) {