mirror of
https://github.com/S2-/ejs-render-remote
synced 2025-08-02 20:50:04 +02:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
2701eb3060 | |||
ad9d3b9be9 | |||
21d9319f97 | |||
371d16bc2e | |||
d53c239f90 | |||
6635965706 | |||
dfcf1a4b6f | |||
4b3df71c6b | |||
af63b77c9b | |||
9aba0176f4 | |||
75401b90dd | |||
47459bd322 | |||
6ed2b48d36 | |||
23d46035e8 | |||
1c720ce9f3 | |||
8c9f23ce3f | |||
94d5afe1a0 | |||
f5a44438d1 | |||
06b2289724 |
@@ -28,6 +28,7 @@
|
||||
"dot-notation": 0,
|
||||
"no-multi-str": 2,
|
||||
"key-spacing": [2, {"afterColon": true}],
|
||||
"func-call-spacing": [2, "never"]
|
||||
"func-call-spacing": [2, "never"],
|
||||
"no-console": "warn"
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
//this uses jQuery for now because ie11 support is needed (promises and fetch)
|
||||
//this uses jQuery for now because ie11 support is needed (promises, fetch, Object.assign)
|
||||
|
||||
(function($) {
|
||||
var uuidv4 = function() {
|
||||
@@ -16,11 +16,8 @@
|
||||
};
|
||||
|
||||
var templateOptions = options || {};
|
||||
for (var attrname in cacheOptions) {
|
||||
templateOptions[attrname] = cacheOptions[attrname];
|
||||
}
|
||||
|
||||
return templateOptions;
|
||||
return $.extend(templateOptions, cacheOptions);
|
||||
};
|
||||
|
||||
ejs.rr = function(templateUrl, data, options) {
|
||||
@@ -40,14 +37,18 @@
|
||||
}
|
||||
|
||||
var r = uuidv4();
|
||||
getTemplateFn.then(function(template) {
|
||||
getTemplateFn.done(function(template) {
|
||||
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
|
||||
|
||||
$('#' + r).replaceWith(ejs.render(
|
||||
template,
|
||||
data,
|
||||
templateOptions
|
||||
));
|
||||
try {
|
||||
$('#' + r).replaceWith(ejs.render(
|
||||
template,
|
||||
data,
|
||||
templateOptions
|
||||
));
|
||||
} catch(ex) {
|
||||
$.readyException(ex);
|
||||
}
|
||||
|
||||
//clean up the getFnFor
|
||||
if (ejs.cache.remove && ejs.cache.get('getFnFor' + templateUrl)) {
|
||||
@@ -64,15 +65,19 @@
|
||||
|
||||
//if the template is already cached, just return.
|
||||
if (ejs.cache.get(templateUrl)) {
|
||||
d.resolve();
|
||||
d.resolve(templateUrl);
|
||||
} else {
|
||||
$.get(templateUrl)
|
||||
.then(function(template) {
|
||||
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
|
||||
var templateFn = ejs.compile(template, templateOptions);
|
||||
ejs.cache.set(templateUrl, templateFn);
|
||||
|
||||
d.resolve(templateUrl);
|
||||
.done(function(template) {
|
||||
try {
|
||||
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
|
||||
var templateFn = ejs.compile(template, templateOptions);
|
||||
ejs.cache.set(templateUrl, templateFn);
|
||||
d.resolve(templateUrl);
|
||||
} catch(ex) {
|
||||
$.readyException(ex);
|
||||
d.reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
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 +1 @@
|
||||
Hello <%= name%>!
|
||||
Hello <%= name %>!
|
||||
|
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.5",
|
||||
"version": "1.0.13",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"homepage": "https://github.com/S2-/ejs-render-remote",
|
||||
@@ -9,5 +9,9 @@
|
||||
},
|
||||
"author": "s2 <s2@31337.it>",
|
||||
"license": "ISC",
|
||||
"keywords": ["ejs", "templating", "client-side"]
|
||||
"keywords": [
|
||||
"ejs",
|
||||
"templating",
|
||||
"client-side"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user