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

6 Commits

Author SHA1 Message Date
s2
6635965706 1.0.11 2020-02-08 18:22:48 +01:00
s2
dfcf1a4b6f use $.readyException 2020-02-08 18:22:16 +01:00
s2
4b3df71c6b 1.0.10 2020-02-08 17:57:16 +01:00
s2
af63b77c9b add more logs 2020-02-08 17:57:05 +01:00
s2
9aba0176f4 add an example 2020-02-08 17:05:22 +01:00
s2
75401b90dd update ejs 2020-02-08 16:58:53 +01:00
5 changed files with 22 additions and 10 deletions

View File

@@ -25,7 +25,11 @@
//if the template is already cached, return it and we are done
if (templateFn) {
return templateFn(data);
try {
return templateFn(data);
} catch(ex) {
$.readyException(ex);
}
} 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
@@ -47,7 +51,7 @@
templateOptions
));
} catch(ex) {
console.error(templateUrl, ex);
$.readyException(ex);
}
//clean up the getFnFor
@@ -69,17 +73,15 @@
} else {
$.get(templateUrl)
.then(function(template) {
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
try {
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
var templateFn = ejs.compile(template, templateOptions);
ejs.cache.set(templateUrl, templateFn);
d.resolve(templateUrl);
} catch(ex) {
console.error(templateUrl, ex);
$.readyException(ex);
d.reject(ex);
throw ex;
}
ejs.cache.set(templateUrl, templateFn);
d.resolve(templateUrl);
});
}

2
examples/ejs.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,7 @@
<body>
<h1>ejs-render-remote example</h1>
<p class="hello"></p>
<div class="sometext"></div>
<script src="jquery.min.js"></script>
<script src="ejs.min.js"></script>
@@ -18,6 +19,14 @@
<script>
//render the template
$('.hello').html(ejs.rr('templates/hello.ejs', {name: 'Simon'}));
//a more elaborate example: preload the template to be sure the dom is
//ready when manipulated
ejs.preloadTemplate('templates/somestuff.ejs')
.then(function(t) {
$('.sometext').html(ejs.rr(t)); //this is sync now
$('.stuff').html('hi!');
});
</script>
</body>
</html>

View File

@@ -0,0 +1 @@
<p class="stuff"></p>

View File

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