forked from ojdx/karma-jade-preprocessor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (44 loc) · 1.38 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
51
52
var pug = require('pug');
var createPugPreprocessor = function(logger, basePath, args, config) {
var log = logger.create('preprocessor.pug');
return function(content, file, done) {
var processed = null;
log.debug('Processing "%s".', file.originalPath);
file.path = file.originalPath.replace(/\.pug$/, '.html');
var templateName = file.originalPath.replace(/^.*\/([^\/]+)\.pug$/, '$1');
try {
var pugOptions = _objectAssign({
filename: file.originalPath,
client: true,
pretty: true
}, args, config);
processed = pug.render(content, pugOptions);
} catch (e) {
log.error('%s\n at %s', e.message, file.originalPath);
}
log.debug('Processed content as:\n%s', processed);
done(processed);
};
};
function _objectAssign(target) {
var output = Object(target);
var idx = 1;
var length = arguments.length;
while (idx < length) {
var source = arguments[idx];
if (source != null) {
for (var nextKey in source) {
if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
idx += 1;
}
return output;
};
createPugPreprocessor.$inject = ['logger', 'config.basePath', 'args', 'config.pugPreprocessor'];
// PUBLISH DI MODULE
module.exports = {
'preprocessor:pug': ['factory', createPugPreprocessor]
};