1
0
mirror of https://github.com/S2-/ejs-render-remote synced 2025-08-03 13:00:04 +02:00

2 Commits

Author SHA1 Message Date
s2
9e36c0e82b v1.0.5 2019-05-18 15:30:59 +02:00
s2
6047c6b084 allow options to be passed in 2019-05-18 15:30:59 +02:00
2 changed files with 22 additions and 13 deletions

View File

@@ -9,7 +9,21 @@
}); });
}; };
ejs.rr = function(templateUrl, data) { var overwriteWithCacheOptions = function(options, cacheName) {
var cacheOptions = {
cache: true,
filename: cacheName
};
var templateOptions = options || {};
for (var attrname in cacheOptions) {
templateOptions[attrname] = cacheOptions[attrname];
}
return templateOptions;
};
ejs.rr = function(templateUrl, data, options) {
var templateFn = ejs.cache.get(templateUrl); var templateFn = ejs.cache.get(templateUrl);
//if the template is already cached, return it and we are done //if the template is already cached, return it and we are done
@@ -27,13 +41,12 @@
var r = uuidv4(); var r = uuidv4();
getTemplateFn.then(function(template) { getTemplateFn.then(function(template) {
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
$('#' + r).replaceWith(ejs.render( $('#' + r).replaceWith(ejs.render(
template, template,
data, data,
{ templateOptions
cache: true,
filename: templateUrl
}
)); ));
//clean up the getFnFor //clean up the getFnFor
@@ -46,7 +59,7 @@
} }
}; };
ejs.preloadTemplate = function(templateUrl) { ejs.preloadTemplate = function(templateUrl, options) {
var d = $.Deferred(); var d = $.Deferred();
//if the template is already cached, just return. //if the template is already cached, just return.
@@ -55,12 +68,8 @@
} else { } else {
$.get(templateUrl) $.get(templateUrl)
.then(function(template) { .then(function(template) {
var templateFn = ejs.compile(template, var templateOptions = overwriteWithCacheOptions(options, templateUrl);
{ var templateFn = ejs.compile(template, templateOptions);
cache: true,
filename: templateUrl
});
ejs.cache.set(templateUrl, templateFn); ejs.cache.set(templateUrl, templateFn);
d.resolve(templateUrl); d.resolve(templateUrl);

View File

@@ -1,6 +1,6 @@
{ {
"name": "ejs-render-remote", "name": "ejs-render-remote",
"version": "1.0.4", "version": "1.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"homepage": "https://github.com/S2-/ejs-render-remote", "homepage": "https://github.com/S2-/ejs-render-remote",