nci/transforms/jade.js

35 lines
638 B
JavaScript
Raw Normal View History

2015-12-11 06:53:57 +00:00
'use strict';
var through = require('through'),
jade = require('react-jade');
module.exports = function(fileName, options) {
if (!/\.jade$/i.test(fileName)) {
return through();
}
var template = '';
return through(
function(chunk) {
template += chunk.toString();
},
function() {
options.filename = fileName;
options.globalReact = true;
try {
template = jade.compileClient(template, options);
} catch (e) {
this.emit('error', e);
return;
}
var moduleBody = 'var React = require("react");\n' +
'module.exports = ' + template;
this.queue(moduleBody);
this.queue(null);
}
);
};