@zenweb/template 3.0.0 → 3.0.2

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## [3.0.2] - 2023-4-2
4
+ - 使用 ctx.template 方法无 engine 指定的情况下使用第一匹配的 engine
package/README.md CHANGED
@@ -21,13 +21,13 @@ npm install @types/nunjucks --save-dev
21
21
  npm install handlebars
22
22
  ```
23
23
 
24
- ## Config
24
+ ## App Config
25
25
 
26
26
  src/index.ts
27
27
  ```ts
28
28
  import { create } from 'zenweb';
29
29
  import modTemplate from '@zenweb/template';
30
- import nunjucks from '@zenweb/template/engine/nunjucks';
30
+ import nunjucks from '@zenweb/template/nunjucks';
31
31
  import handlebars from '@zenweb/template/handlebars';
32
32
 
33
33
  const app = create();
@@ -52,6 +52,13 @@ app.setup(modTemplate({
52
52
  app.start();
53
53
  ```
54
54
 
55
+ tsconfig.json
56
+ ```json
57
+ "compilerOptions": {
58
+ "moduleResolution": "node16",
59
+ }
60
+ ```
61
+
55
62
  ## Use
56
63
 
57
64
  src/controller/demo.ts
@@ -1,3 +1,4 @@
1
+ /// <reference types="handlebars" />
1
2
  import { TemplateEngine } from '../types';
2
3
  export interface HandlebarsOption extends CompileOptions {
3
4
  /**
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /// <reference types="handlebars" />
3
4
  const path = require("path");
4
5
  const fs = require("fs");
5
6
  const util_1 = require("util");
package/dist/render.js CHANGED
@@ -10,7 +10,8 @@ class TemplateRender {
10
10
  }
11
11
  match(ctx) {
12
12
  const opt = ctx[exports.TEMPLATE_OPTION];
13
- if (opt && opt.engine === this._option.engineName) {
13
+ // 匹配引擎, 如果不设置引擎则直接匹配
14
+ if (opt && (!opt.engine || opt.engine === this._option.engineName)) {
14
15
  (0, utils_1.debug)('matchEngine: %o', this._option.engineName);
15
16
  return true;
16
17
  }
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "@zenweb/template",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "zenweb template render module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
7
- "./engine": "./dist/engine"
7
+ "./handlebars": {
8
+ "require": "./dist/engine/handlebars.js",
9
+ "types": "./dist/engine/handlebars.d.ts"
10
+ },
11
+ "./nunjucks": {
12
+ "require": "./dist/engine/nunjucks.js",
13
+ "types": "./dist/engine/nunjucks.d.ts"
14
+ }
8
15
  },
9
16
  "types": "./dist/index.d.ts",
10
17
  "scripts": {