br-processor
v0.2.1
Published
Use for browserify transform and translate code of template engine or pre-proccessor to javascript string
Downloads
2
Maintainers
Readme
br processor
Use for browserify transform and translate code of template engine or pre-proccessor to javascript string.
Support most pre-precessor which has sync api;
Options
processorList
matchTest
to test file's ext and return boolean to tell browserfiy transform;process
a process translate input string to browserify js code;
Demo
Then use for b.transform(transformOpts,brProcessor)
var jade = require('jade');
var transformOpts = {
processorList: [{
matchTest: function(file) {
return /\.jade$/.exec(file);
},
process: function(inputString) {
return html2jsWraper(jade.render(inputString, jadeOpts));
}
}]
}
function html2jsWraper(string) {
return [
'module.exports=',
escapeContent(string),
';'
].join('\'')
}
function escapeContent(content) {
return content.replace(/\\/g, '\\\\').replace(/'/g, '\\\'').replace(/\r?\n/g,
'\\n\' +\n \'');
}