https://github.com/morlay/br-processor
https://github.com/morlay/br-processor
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morlay/br-processor
- Owner: morlay
- Created: 2014-08-31T08:05:45.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2016-04-07T03:39:14.000Z (about 10 years ago)
- Last Synced: 2025-02-08T14:12:26.640Z (over 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## br processor
Use for [browserify transform](https://github.com/substack/node-browserify#btransformopts-tr)
and translate code of template engine or pre-proccessor to javascript string.
[](https://travis-ci.org/morlay/br-processor)
[](https://david-dm.org/morlay/br-processor)
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 \'');
}