mirror of
https://github.com/S2-/ejs-render-remote
synced 2025-08-02 20:50:04 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
23d46035e8 | |||
1c720ce9f3 | |||
8c9f23ce3f | |||
94d5afe1a0 | |||
f5a44438d1 | |||
06b2289724 | |||
9e36c0e82b | |||
6047c6b084 |
@@ -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() {
|
||||
@@ -9,7 +9,18 @@
|
||||
});
|
||||
};
|
||||
|
||||
ejs.rr = function(templateUrl, data) {
|
||||
var overwriteWithCacheOptions = function(options, cacheName) {
|
||||
var cacheOptions = {
|
||||
cache: true,
|
||||
filename: cacheName
|
||||
};
|
||||
|
||||
var templateOptions = options || {};
|
||||
|
||||
return $.extend(templateOptions, cacheOptions);
|
||||
};
|
||||
|
||||
ejs.rr = function(templateUrl, data, options) {
|
||||
var templateFn = ejs.cache.get(templateUrl);
|
||||
|
||||
//if the template is already cached, return it and we are done
|
||||
@@ -27,13 +38,12 @@
|
||||
|
||||
var r = uuidv4();
|
||||
getTemplateFn.then(function(template) {
|
||||
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
|
||||
|
||||
$('#' + r).replaceWith(ejs.render(
|
||||
template,
|
||||
data,
|
||||
{
|
||||
cache: true,
|
||||
filename: templateUrl
|
||||
}
|
||||
templateOptions
|
||||
));
|
||||
|
||||
//clean up the getFnFor
|
||||
@@ -46,21 +56,23 @@
|
||||
}
|
||||
};
|
||||
|
||||
ejs.preloadTemplate = function(templateUrl) {
|
||||
ejs.preloadTemplate = function(templateUrl, options) {
|
||||
var d = $.Deferred();
|
||||
|
||||
//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 templateFn = ejs.compile(template,
|
||||
{
|
||||
cache: true,
|
||||
filename: templateUrl
|
||||
});
|
||||
|
||||
var templateOptions = overwriteWithCacheOptions(options, templateUrl);
|
||||
try {
|
||||
var templateFn = ejs.compile(template, templateOptions);
|
||||
} catch(ex) {
|
||||
console.error(templateUrl, ex);
|
||||
d.reject(ex);
|
||||
throw ex;
|
||||
}
|
||||
ejs.cache.set(templateUrl, templateFn);
|
||||
|
||||
d.resolve(templateUrl);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ejs-render-remote",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.8",
|
||||
"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