@zenweb/template 3.0.2 → 3.1.0

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 CHANGED
@@ -1,4 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.1.0] - 2023-4-2
4
+ - 完成 failTemplate 功能
5
+
6
+ ## [3.0.3] - 2023-4-2
7
+ - 清除遗留的 console.log
8
+
3
9
  ## [3.0.2] - 2023-4-2
4
10
  - 使用 ctx.template 方法无 engine 指定的情况下使用第一匹配的 engine
package/dist/render.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TemplateRender = exports.TEMPLATE_OPTION = void 0;
4
+ const result_1 = require("@zenweb/result");
4
5
  const utils_1 = require("./utils");
5
6
  exports.TEMPLATE_OPTION = Symbol('template@option');
6
7
  class TemplateRender {
@@ -35,9 +36,14 @@ class TemplateRender {
35
36
  return false;
36
37
  }
37
38
  render(ctx, data) {
38
- console.log(this);
39
- const opt = ctx[exports.TEMPLATE_OPTION];
40
- let template = opt === null || opt === void 0 ? void 0 : opt.template;
39
+ const opt = ctx[exports.TEMPLATE_OPTION] || {};
40
+ let template = opt.template;
41
+ if (data instanceof result_1.ResultFail) {
42
+ data = { fail: data };
43
+ if (opt.failTemplate !== false) {
44
+ template = opt.failTemplate || this._option.failTemplate;
45
+ }
46
+ }
41
47
  if (!template) {
42
48
  template = ctx.path.slice(1);
43
49
  if (this._option.templateAffix) {
package/dist/types.d.ts CHANGED
@@ -24,7 +24,10 @@ export interface TemplateSetupOption {
24
24
  */
25
25
  templateAffix?: string;
26
26
  /**
27
- * 失败使用模版
27
+ * 使用 `ctx.fail` 操作所使用的模版 - 全局
28
+ * - 不指定则使用 `TemplateOption.template` 值
29
+ * - 指定后可以在控制器中设置 `TemplateOption.failTemplate = false` 关闭全局 `failTemplate`
30
+ * @default undefined
28
31
  */
29
32
  failTemplate?: string;
30
33
  /**
@@ -42,6 +45,12 @@ export interface TemplateOption {
42
45
  * 指定模版名,不指定取 `ctx.path`
43
46
  */
44
47
  template?: string;
48
+ /**
49
+ * 使用 `ctx.fail` 操作所使用的模版
50
+ * - 默认使用全局配置的 `failTemplate`
51
+ * - 如果设置为 `false` 则强制使用 `template`
52
+ */
53
+ failTemplate?: string | false;
45
54
  /**
46
55
  * 使用的渲染引擎
47
56
  * - 对应的是 `TemplateSetupOption.engineName`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenweb/template",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "zenweb template render module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",