forked from hanachin/karma-handlebars-preprocessor
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
34 lines (27 loc) · 949 Bytes
/
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
var jade = require('jade');
var createJadePreprocessor = function(logger, basePath) {
var log = logger.create('preprocessor.jade');
return function(content, file, done) {
var processed = null;
log.debug('Processing "%s".', file.originalPath);
file.originalPath = file.originalPath.replace(/\.jade$/, '.html');
var templateName = file.originalPath.replace(/^.*\/([^\/]+)\.jade$/, '$1');
try {
var jadeOptions = {
filename: file.originalPath,
client: true,
pretty: true
};
processed = jade.render(content, jadeOptions);
} catch (e) {
log.error('%s\n at %s', e.message, file.originalPath);
}
log.debug('Processed content as:\n%s', processed);
done(processed);
};
};
createJadePreprocessor.$inject = ['logger', 'config.basePath'];
// PUBLISH DI MODULE
module.exports = {
'preprocessor:jade': ['factory', createJadePreprocessor]
};