2016-10-10 03:43:44 +02:00
|
|
|
var template = require('lodash.template');
|
|
|
|
var reInterpolate = require('lodash._reinterpolate');
|
|
|
|
|
|
|
|
var forcedSettings = {
|
2016-11-03 01:33:53 +01:00
|
|
|
escape: /<%-([\s\S]+?)%>/g,
|
|
|
|
evaluate: /<%([\s\S]+?)%>/g,
|
2016-10-10 03:43:44 +02:00
|
|
|
interpolate: reInterpolate
|
|
|
|
};
|
|
|
|
|
2016-11-03 01:33:53 +01:00
|
|
|
module.exports = function(tmpl, data){
|
|
|
|
var fn = template(tmpl, null, forcedSettings);
|
2016-10-10 03:43:44 +02:00
|
|
|
|
|
|
|
var wrapped = function(o) {
|
2016-11-03 01:33:53 +01:00
|
|
|
if (typeof o === 'undefined' || typeof o.file === 'undefined') throw new Error('Failed to provide the current file as "file" to the template');
|
2016-10-10 03:43:44 +02:00
|
|
|
return fn(o);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (data ? wrapped(data) : wrapped);
|
|
|
|
};
|