gulp-ejs-template
Version:
Precompile EJS templates to a JS file.
50 lines (41 loc) • 1.12 kB
JavaScript
// **Github:** https://github.com/teambition/gulp-ejs-template
//
// **License:** MIT
/* global module, define, setImmediate, window */
;(function(root, factory) {
'use strict';
if (typeof module === 'object' && module.exports) module.exports = factory();
else if (typeof define === 'function' && define.amd) define([], factory);
else root.moduleName = factory();
}(typeof window === 'object' ? window : this, function() {
'use strict';
var templates = {};
/*PLACEHOLDER*/
var ejs = {
locals: {},
get: getTpl,
render: render
};
return ejs;
function render(tplName, data) {
var it = copy({}, ejs.locals);
return getTpl(tplName)(copy(it, data));
}
function getTpl(tplName) {
return templates[tplName];
}
function escape(markup) {
if (!markup) return '';
return String(markup)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/'/g, ''')
.replace(/"/g, '"');
}
function copy(to, from) {
from = from || {};
for (var key in from) to[key] = from[key];
return to;
}
}));