template.js 636 B

1234567891011121314151617181920212223
  1. var template = require('lodash.template');
  2. var reEscape = require('lodash._reescape');
  3. var reEvaluate = require('lodash._reevaluate');
  4. var reInterpolate = require('lodash._reinterpolate');
  5. var forcedSettings = {
  6. escape: reEscape,
  7. evaluate: reEvaluate,
  8. interpolate: reInterpolate
  9. };
  10. module.exports = function(tmpl, data) {
  11. var fn = template(tmpl, forcedSettings);
  12. var wrapped = function(o) {
  13. if (typeof o === 'undefined' || typeof o.file === 'undefined') {
  14. throw new Error('Failed to provide the current file as "file" to the template');
  15. }
  16. return fn(o);
  17. };
  18. return (data ? wrapped(data) : wrapped);
  19. };