-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
50 lines (38 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var createHamlPreprocessor = function(args, config, logger, helper) {
config = config || {};
var log = logger.create('preprocessor.haml');
var defaultOptions = {
language: 'js'
};
var options = helper.merge(defaultOptions, args.options || {}, config.options || {});
//
var transpileJS = function(content, file, done) {
var haml = require('haml');
var compiled = haml.compile(content);
done(eval(compiled));
};
var transpileCoffee = function(content, file, done) {
var hamlc = require('haml-coffee');
var compiled = hamlc.compile(content)();
done(compiled);
};
//
return function(content, file, done) {
log.debug('Processing "%s".', file.originalPath);
switch(options.language) {
case 'js' :
transpileJS(content, file, done);
break;
case 'coffee' :
transpileCoffee(content, file, done);
break;
default :
log.error('Language "%s" is not a valid source language for the hamlPreprocessor. Available options are `js` and `coffee`.', options.language);
}
};
};
createHamlPreprocessor.$inject = ['args', 'config.hamlPreprocessor', 'logger', 'helper'];
// PUBLISH DI MODULE
module.exports = {
'preprocessor:haml': ['factory', createHamlPreprocessor]
};