0.2.1 • Published 8 years ago

br-processor v0.2.1

Weekly downloads
2
License
WTFPL
Repository
github
Last release
8 years ago

br processor

Use for browserify transform and translate code of template engine or pre-proccessor to javascript string.

Build Status Dependencies

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    \'');
}
0.2.1

8 years ago

0.1.1

10 years ago

0.1.0

10 years ago