| 2 | |
| 3 | export default function(environment, ParseTree) { |
| 4 | const render = function (input, options, callback) { |
| 5 | if (typeof options === 'function') { |
| 6 | callback = options; |
| 7 | options = utils.copyOptions(this.options, {}); |
| 8 | } |
| 9 | else { |
| 10 | options = utils.copyOptions(this.options, options || {}); |
| 11 | } |
| 12 | |
| 13 | if (!callback) { |
| 14 | const self = this; |
| 15 | return new Promise(function (resolve, reject) { |
| 16 | render.call(self, input, options, function(err, output) { |
| 17 | if (err) { |
| 18 | reject(err); |
| 19 | } else { |
| 20 | resolve(output); |
| 21 | } |
| 22 | }); |
| 23 | }); |
| 24 | } else { |
| 25 | this.parse(input, options, function(err, root, imports, options) { |
| 26 | if (err) { return callback(err); } |
| 27 | |
| 28 | let result; |
| 29 | try { |
| 30 | const parseTree = new ParseTree(root, imports); |
| 31 | result = parseTree.toCSS(options); |
| 32 | } |
| 33 | catch (err) { return callback(err); } |
| 34 | |
| 35 | callback(null, result); |
| 36 | }); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | return render; |
| 41 | } |