template.js 552 B

12345678910111213141516171819
  1. var template = require('lodash.template');
  2. var reInterpolate = require('lodash._reinterpolate');
  3. var forcedSettings = {
  4. escape: /<%-([\s\S]+?)%>/g,
  5. evaluate: /<%([\s\S]+?)%>/g,
  6. interpolate: reInterpolate
  7. };
  8. module.exports = function(tmpl, data){
  9. var fn = template(tmpl, null, forcedSettings);
  10. var wrapped = function(o) {
  11. if (typeof o === 'undefined' || typeof o.file === 'undefined') throw new Error('Failed to provide the current file as "file" to the template');
  12. return fn(o);
  13. };
  14. return (data ? wrapped(data) : wrapped);
  15. };