mirror of
https://github.com/S2-/ejs-render-remote
synced 2025-08-04 13:20:06 +02:00
Compare commits
6 Commits
c1f83b7468
...
v1.0.4
Author | SHA1 | Date | |
---|---|---|---|
4dd2bfb8a9 | |||
b6e19487b7 | |||
6d6def3374 | |||
326e760c78 | |||
95a1708280 | |||
c4fc133475 |
@@ -14,12 +14,6 @@
|
|||||||
|
|
||||||
//if the template is already cached, return it and we are done
|
//if the template is already cached, return it and we are done
|
||||||
if (templateFn) {
|
if (templateFn) {
|
||||||
//but first check if there is still a getter function for this template in the cache
|
|
||||||
//if yes, remove it so we clean up a bit
|
|
||||||
if (ejs.cache.remove && ejs.cache.get('getFnFor' + templateUrl)) {
|
|
||||||
ejs.cache.remove('getFnFor' + templateUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return templateFn(data);
|
return templateFn(data);
|
||||||
|
|
||||||
} else { //if the template is not cached, we need to get it and render it later once we have it. remember: this happens only if the template is not already cached
|
} else { //if the template is not cached, we need to get it and render it later once we have it. remember: this happens only if the template is not already cached
|
||||||
@@ -33,14 +27,19 @@
|
|||||||
|
|
||||||
var r = uuidv4();
|
var r = uuidv4();
|
||||||
getTemplateFn.then(function(template) {
|
getTemplateFn.then(function(template) {
|
||||||
document.getElementById(r).outerHTML = ejs.render(
|
$('#' + r).replaceWith(ejs.render(
|
||||||
template,
|
template,
|
||||||
data,
|
data,
|
||||||
{
|
{
|
||||||
cache: true,
|
cache: true,
|
||||||
filename: templateUrl
|
filename: templateUrl
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
|
|
||||||
|
//clean up the getFnFor
|
||||||
|
if (ejs.cache.remove && ejs.cache.get('getFnFor' + templateUrl)) {
|
||||||
|
ejs.cache.remove('getFnFor' + templateUrl);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return '<span class="ejs-templateplaceholder" style="display: none;" id="' + r + '"></span>';
|
return '<span class="ejs-templateplaceholder" style="display: none;" id="' + r + '"></span>';
|
||||||
@@ -57,17 +56,17 @@
|
|||||||
$.get(templateUrl)
|
$.get(templateUrl)
|
||||||
.then(function(template) {
|
.then(function(template) {
|
||||||
var templateFn = ejs.compile(template,
|
var templateFn = ejs.compile(template,
|
||||||
{
|
{
|
||||||
cache: true,
|
cache: true,
|
||||||
filename: templateUrl
|
filename: templateUrl
|
||||||
});
|
});
|
||||||
|
|
||||||
ejs.cache.set(templateUrl, templateFn);
|
ejs.cache.set(templateUrl, templateFn);
|
||||||
|
|
||||||
d.resolve();
|
d.resolve(templateUrl);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
};
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ejs-render-remote",
|
"name": "ejs-render-remote",
|
||||||
"version": "1.0.1",
|
"version": "1.0.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"homepage": "https://github.com/S2-/ejs-render-remote",
|
"homepage": "https://github.com/S2-/ejs-render-remote",
|
||||||
|
Reference in New Issue
Block a user