@ololoepepe/template-renderer 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +10 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ololoepepe/template-renderer",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "eta-based template renderer",
5
5
  "main": "src/index.js",
6
6
  "imports": {
package/src/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import {Eta} from 'eta';
2
2
 
3
+ function getTemplateName(name) {
4
+ return name.startsWith('@') ? name : `./${name}`;
5
+ }
6
+
3
7
  export class TemplateRenderer {
4
8
  #eta = null;
5
9
 
@@ -13,12 +17,16 @@ export class TemplateRenderer {
13
17
  });
14
18
  }
15
19
 
20
+ loadTemplateSync(name, text) {
21
+ this.#eta.loadTemplate(`@${name}`, text);
22
+ }
23
+
16
24
  async renderTemplate(templateName, variables) {
17
- return await this.#eta.renderAsync(`./${templateName}`, variables);
25
+ return await this.#eta.renderAsync(getTemplateName(templateName), variables);
18
26
  }
19
27
 
20
28
  renderTemplateSync(templateName, variables) {
21
- return this.#eta.render(`./${templateName}`, variables);
29
+ return this.#eta.render(getTemplateName(templateName), variables);
22
30
  }
23
31
  }
24
32