-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Less parsing as a top level feature of the less package
Converting a Less stylesheet into an AST is a valuable piece of functionality, and worthy of being easily accessible to consumers of less.js.
- Loading branch information
jackwanders
committed
Dec 2, 2014
1 parent
94a6501
commit cf54e01
Showing
3 changed files
with
70 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise, | ||
contexts = require("./contexts"), | ||
Parser = require('./parser/parser'), | ||
PluginManager = require('./plugin-manager'); | ||
|
||
module.exports = function(environment, ParseTree, ImportManager) { | ||
var parse = function (input, options, callback) { | ||
options = options || {}; | ||
|
||
if (typeof(options) === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
if (!callback) { | ||
var self = this; | ||
return new PromiseConstructor(function (resolve, reject) { | ||
parse.call(self, input, options, function(err, output) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(output); | ||
} | ||
}); | ||
}); | ||
} else { | ||
var context, | ||
rootFileInfo, | ||
pluginManager = new PluginManager(this); | ||
|
||
pluginManager.addPlugins(options.plugins); | ||
options.pluginManager = pluginManager; | ||
|
||
context = new contexts.Parse(options); | ||
|
||
if (options.rootFileInfo) { | ||
rootFileInfo = options.rootFileInfo; | ||
} else { | ||
var filename = options.filename || "input"; | ||
var entryPath = filename.replace(/[^\/\\]*$/, ""); | ||
rootFileInfo = { | ||
filename: filename, | ||
relativeUrls: context.relativeUrls, | ||
rootpath: context.rootpath || "", | ||
currentDirectory: entryPath, | ||
entryPath: entryPath, | ||
rootFilename: filename | ||
}; | ||
} | ||
|
||
var imports = new ImportManager(context, rootFileInfo); | ||
|
||
new Parser(context, imports, rootFileInfo) | ||
.parse(input, function (e, root) { | ||
if (e) { return callback(e); } | ||
callback(null, root, imports, options); | ||
}, options); | ||
} | ||
}; | ||
return parse; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters