mirror of
https://github.com/S2-/ejs-render-remote
synced 2025-08-02 20:50:04 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6635965706 | |||
dfcf1a4b6f | |||
4b3df71c6b | |||
af63b77c9b | |||
9aba0176f4 | |||
75401b90dd |
@@ -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
2
examples/ejs.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -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>
|
||||
|
1
examples/templates/somestuff.ejs
Normal file
1
examples/templates/somestuff.ejs
Normal file
@@ -0,0 +1 @@
|
||||
<p class="stuff"></p>
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user