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

7 Commits

Author SHA1 Message Date
s2
6d6def3374 v1.0.3 2019-05-18 15:30:59 +02:00
s2
326e760c78 resolve with the templateUrl on preload 2019-04-14 22:04:52 +02:00
s2
95a1708280 v1.0.2 2019-04-14 21:55:06 +02:00
s2
c4fc133475 outerHTML vs replaceWith 2019-04-14 21:54:34 +02:00
s2
c1f83b7468 add an example 2019-04-14 18:55:14 +02:00
s2
a2bd63ae60 some boilerplate stuff 2019-04-14 18:47:34 +02:00
s2
39238a44d6 typo 2019-04-14 18:38:32 +02:00
6 changed files with 63 additions and 11 deletions

14
.editorconfig Normal file
View File

@@ -0,0 +1,14 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
[*.md]
max_line_length = off
trim_trailing_whitespace = false

1
.eslintignore Normal file
View File

@@ -0,0 +1 @@
node_modules

33
.eslintrc.json Normal file
View File

@@ -0,0 +1,33 @@
{"parserOptions":
{"ecmaVersion": 6},
"rules": {
"quotes": [2, "single", {"allowTemplateLiterals": true}],
"curly": [2, "all"],
"keyword-spacing": [2, {"overrides": {"else": {"before": true}, "catch": {"before": true, "after": false}}}],
"space-before-blocks": [2, "always"],
"wrap-iife": [2, "inside"],
"space-before-function-paren": [2, "never"],
"one-var": [2, "never"],
"vars-on-top": 0, "no-empty": [2, {"allowEmptyCatch": true}],
"array-bracket-spacing": [2, "never"],
"space-in-parens": [2, "never"],
"no-underscore-dangle": 0,
"comma-style": [2, "last"],
"comma-spacing": [2, {"before": false, "after": true}],
"space-unary-ops": [2, {"words": false, "nonwords": false}],
"no-multi-spaces": 2,
"space-infix-ops": 2,
"no-with": 2,
"indent": [2, "tab", {"SwitchCase": 1, "FunctionExpression": {"body": 1, "parameters": 1}, "MemberExpression": 0}],
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"comma-dangle": [2, "never"],
"semi": [2, "always"],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"eol-last": 2,
"dot-notation": 0,
"no-multi-str": 2,
"key-spacing": [2, {"afterColon": true}],
"func-call-spacing": [2, "never"]
}
}

View File

@@ -2,6 +2,10 @@
[ejs](https://ejs.co/) remote client side includes.
```js
html = ejs.rr('sayhello.ejs', {name: 'Simon'});
```
## Quick start
0. Install with `npm i ejs-render-remote`
@@ -9,7 +13,7 @@
```html
<script src="node_modules/ejs-render-remote/ejs-render-remote.js"></script>
```
2. Creare a file with your template, for example `templates/hello-world.ejs` containing `hello <%= name %>!`
2. Create a file with your template, for example `templates/hello-world.ejs` containing `hello <%= name %>!`
3. Render the remote template:
```js
someDomelement.outerHTML = ejs.rr('templates/hello-world.ejs', {name: 'Simon'});
@@ -28,5 +32,5 @@ The resulting ejs template function is cached, so the second time this function
### ejs.preloadTemplate(templateUrl)
Since `ejs.rr` is async, you can call `ejs.preloadTemplate` before invoking `ejs.rr` to warm the template chace up for that `templateUrl`.
Since `ejs.rr` is async, you can call `ejs.preloadTemplate` before invoking `ejs.rr` to warm the template cache up for that `templateUrl`.
By doing so the call to `ejs.rr` will return the rendered template string right away.

View File

@@ -33,14 +33,14 @@
var r = uuidv4();
getTemplateFn.then(function(template) {
document.getElementById(r).outerHTML = ejs.render(
$('#' + r).replaceWith(ejs.render(
template,
data,
{
cache: true,
filename: templateUrl
}
);
));
});
return '<span class="ejs-templateplaceholder" style="display: none;" id="' + r + '"></span>';
@@ -64,10 +64,10 @@
ejs.cache.set(templateUrl, templateFn);
d.resolve();
d.resolve(templateUrl);
});
}
return d;
}
};
})(jQuery);

View File

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