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

3 Commits

Author SHA1 Message Date
s2
4dd2bfb8a9 v1.0.4 2019-05-18 15:30:59 +02:00
s2
b6e19487b7 clean up cache right after render 2019-05-18 15:30:59 +02:00
s2
6d6def3374 v1.0.3 2019-05-18 15:30:59 +02:00
2 changed files with 14 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
//this uses jQuery for now because ie11 support is needed (promises, fetch, Object.assign)
//this uses jQuery for now because ie11 support is needed (promises and fetch)
(function($) {
var uuidv4 = function() {
@@ -9,18 +9,7 @@
});
};
var overwriteWithCacheOptions = function(options, cacheName) {
var cacheOptions = {
cache: true,
filename: cacheName
};
var templateOptions = options || {};
return $.extend(templateOptions, cacheOptions);
};
ejs.rr = function(templateUrl, data, options) {
ejs.rr = function(templateUrl, data) {
var templateFn = ejs.cache.get(templateUrl);
//if the template is already cached, return it and we are done
@@ -38,12 +27,13 @@
var r = uuidv4();
getTemplateFn.then(function(template) {
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
$('#' + r).replaceWith(ejs.render(
template,
data,
templateOptions
{
cache: true,
filename: templateUrl
}
));
//clean up the getFnFor
@@ -56,7 +46,7 @@
}
};
ejs.preloadTemplate = function(templateUrl, options) {
ejs.preloadTemplate = function(templateUrl) {
var d = $.Deferred();
//if the template is already cached, just return.
@@ -65,8 +55,12 @@
} else {
$.get(templateUrl)
.then(function(template) {
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
var templateFn = ejs.compile(template, templateOptions);
var templateFn = ejs.compile(template,
{
cache: true,
filename: templateUrl
});
ejs.cache.set(templateUrl, templateFn);
d.resolve(templateUrl);

View File

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