1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var Crixalis = require('../controller'),
|
12 | Parser = require('less').Parser,
|
13 | cache = {};
|
14 |
|
15 | module.exports = function (options) {
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Crixalis.plugin('processor', {
|
24 | method : 'less',
|
25 | extension : 'css',
|
26 | compile : function (filename, data, options) {
|
27 | options.filename = filename;
|
28 | options.async = true;
|
29 |
|
30 | var parser = new Parser(options),
|
31 | that = this;
|
32 |
|
33 | parser.parse(data, function (error, result) {
|
34 | if (!error && result) {
|
35 | try {
|
36 | result = result.toCSS({ compress: true });
|
37 | } catch (exception) {
|
38 | error = exception;
|
39 | }
|
40 | }
|
41 |
|
42 |
|
43 | if (error && !(error instanceof Error)) {
|
44 | error = new Error([error.message, error.filename].join(' '));
|
45 | }
|
46 |
|
47 | that.forward(error, result);
|
48 | });
|
49 | }
|
50 | });
|
51 | };
|