@midwayjs/view 3.19.2 → 4.0.0-alpha.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.
@@ -58,11 +58,12 @@ let ViewConfiguration = class ViewConfiguration {
58
58
  await container.getAsync(viewManager_1.ViewManager);
59
59
  }
60
60
  };
61
+ exports.ViewConfiguration = ViewConfiguration;
61
62
  __decorate([
62
63
  (0, core_1.Inject)(),
63
64
  __metadata("design:type", core_1.MidwayApplicationManager)
64
65
  ], ViewConfiguration.prototype, "applicationManager", void 0);
65
- ViewConfiguration = __decorate([
66
+ exports.ViewConfiguration = ViewConfiguration = __decorate([
66
67
  (0, core_1.Configuration)({
67
68
  namespace: 'view',
68
69
  importConfigs: [
@@ -73,5 +74,4 @@ ViewConfiguration = __decorate([
73
74
  ],
74
75
  })
75
76
  ], ViewConfiguration);
76
- exports.ViewConfiguration = ViewConfiguration;
77
77
  //# sourceMappingURL=configuration.js.map
@@ -24,7 +24,7 @@ let ContextView = class ContextView {
24
24
  async render(name, locals, options) {
25
25
  // retrieve fullpath matching name from `config.root`
26
26
  const filename = await this.viewManager.resolve(name);
27
- options = options !== null && options !== void 0 ? options : {};
27
+ options = options ?? {};
28
28
  options.name = name;
29
29
  options.root = filename.replace((0, path_1.normalize)(name), '').replace(/[/\\]$/, '');
30
30
  options.locals = locals;
@@ -39,16 +39,15 @@ let ContextView = class ContextView {
39
39
  if (!viewEngineName) {
40
40
  viewEngineName = this.viewConfig.defaultViewEngine;
41
41
  }
42
- assert(viewEngineName, `Can't find viewEngine for ${filename}`);
42
+ assert.ok(viewEngineName, `Can't find viewEngine for ${filename}`);
43
43
  // get view engine and render
44
44
  const view = await this.getViewEngine(viewEngineName);
45
45
  return await view.render(filename, this.setLocals(locals), options);
46
46
  }
47
47
  async renderString(tpl, locals, options) {
48
- var _a;
49
- options = options !== null && options !== void 0 ? options : {};
50
- const viewEngineName = (_a = options.viewEngine) !== null && _a !== void 0 ? _a : this.viewConfig.defaultViewEngine;
51
- assert(viewEngineName, "Can't find viewEngine");
48
+ options = options ?? {};
49
+ const viewEngineName = options.viewEngine ?? this.viewConfig.defaultViewEngine;
50
+ assert.ok(viewEngineName, "Can't find viewEngine");
52
51
  // get view engine and render
53
52
  const view = await this.getViewEngine(viewEngineName);
54
53
  return await view.renderString(tpl, this.setLocals(locals), options);
@@ -56,7 +55,7 @@ let ContextView = class ContextView {
56
55
  async getViewEngine(name) {
57
56
  // get view engine
58
57
  const ViewEngine = this.viewManager.get(name);
59
- assert(ViewEngine, `Can't find ViewEngine "${name}"`);
58
+ assert.ok(ViewEngine, `Can't find ViewEngine "${name}"`);
60
59
  // use view engine to render
61
60
  const engine = await this.ctx.requestContext.getAsync(ViewEngine);
62
61
  // wrap render and renderString to support both async function and generator function
@@ -75,6 +74,7 @@ let ContextView = class ContextView {
75
74
  }, this.ctx.locals, locals);
76
75
  }
77
76
  };
77
+ exports.ContextView = ContextView;
78
78
  __decorate([
79
79
  (0, core_1.Inject)(),
80
80
  __metadata("design:type", viewManager_1.ViewManager)
@@ -87,8 +87,7 @@ __decorate([
87
87
  (0, core_1.Inject)(),
88
88
  __metadata("design:type", Object)
89
89
  ], ContextView.prototype, "ctx", void 0);
90
- ContextView = __decorate([
90
+ exports.ContextView = ContextView = __decorate([
91
91
  (0, core_1.Provide)()
92
92
  ], ContextView);
93
- exports.ContextView = ContextView;
94
93
  //# sourceMappingURL=contextView.js.map
@@ -53,11 +53,11 @@ let ViewManager = class ViewManager extends Map {
53
53
  * @param {Object} viewEngine - the class of view engine
54
54
  */
55
55
  use(name, viewEngine) {
56
- assert(name, 'name is required');
57
- assert(!this.has(name), `${name} has been registered`);
58
- assert(viewEngine, 'viewEngine is required');
59
- assert(viewEngine.prototype.render, 'viewEngine should implement `render` method');
60
- assert(viewEngine.prototype.renderString, 'viewEngine should implement `renderString` method');
56
+ assert.ok(name, 'name is required');
57
+ assert.ok(!this.has(name), `${name} has been registered`);
58
+ assert.ok(viewEngine, 'viewEngine is required');
59
+ assert.ok(viewEngine.prototype.render, 'viewEngine should implement `render` method');
60
+ assert.ok(viewEngine.prototype.renderString, 'viewEngine should implement `renderString` method');
61
61
  this.set(name, viewEngine);
62
62
  }
63
63
  /**
@@ -75,7 +75,7 @@ let ViewManager = class ViewManager extends Map {
75
75
  return filename;
76
76
  // try find it with default extension
77
77
  filename = await resolvePath([name, name + config.defaultExtension], config.root);
78
- assert(filename, `Can't find ${name} from ${config.root.join(',')}`);
78
+ assert.ok(filename, `Can't find ${name} from ${config.root.join(',')}`);
79
79
  // set cache
80
80
  this.fileMap.set(name, filename);
81
81
  return filename;
@@ -98,8 +98,9 @@ let ViewManager = class ViewManager extends Map {
98
98
  return this.extMap.get(ext);
99
99
  }
100
100
  };
101
+ exports.ViewManager = ViewManager;
101
102
  __decorate([
102
- (0, core_1.App)(),
103
+ (0, core_1.MainApp)(),
103
104
  __metadata("design:type", Object)
104
105
  ], ViewManager.prototype, "app", void 0);
105
106
  __decorate([
@@ -112,11 +113,10 @@ __decorate([
112
113
  __metadata("design:paramtypes", []),
113
114
  __metadata("design:returntype", void 0)
114
115
  ], ViewManager.prototype, "init", null);
115
- ViewManager = __decorate([
116
+ exports.ViewManager = ViewManager = __decorate([
116
117
  (0, core_1.Provide)(),
117
118
  (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
118
119
  ], ViewManager);
119
- exports.ViewManager = ViewManager;
120
120
  async function resolvePath(names, root) {
121
121
  for (const name of names) {
122
122
  for (const dir of root) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/view",
3
- "version": "3.19.2",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Midway Component for render view",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
9
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
10
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
11
11
  "ci": "npm run test"
12
12
  },
13
13
  "keywords": [
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/core": "^3.19.0",
31
- "@midwayjs/koa": "^3.19.2",
32
- "@midwayjs/mock": "^3.19.2"
30
+ "@midwayjs/core": "^4.0.0-alpha.1",
31
+ "@midwayjs/koa": "^4.0.0-alpha.1",
32
+ "@midwayjs/mock": "^4.0.0-alpha.1"
33
33
  },
34
- "gitHead": "57fd034be94897fb819b0d9ef776de0b9923ab0f"
34
+ "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
35
35
  }