@midwayjs/view 3.4.12 → 3.5.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.
@@ -33,7 +33,7 @@ let ContextView = class ContextView {
33
33
  let viewEngineName = options.viewEngine;
34
34
  if (!viewEngineName) {
35
35
  const ext = (0, path_1.extname)(filename);
36
- viewEngineName = this.viewManager.extMap.get(ext);
36
+ viewEngineName = this.viewManager.findEngine(ext);
37
37
  }
38
38
  // use the default view engine that is configured if no matching above
39
39
  if (!viewEngineName) {
@@ -69,7 +69,7 @@ let ContextView = class ContextView {
69
69
  return engine;
70
70
  }
71
71
  setLocals(locals) {
72
- return Object.assign({
72
+ return Object.assign(this.viewManager.getLocals(), {
73
73
  ctx: this.ctx,
74
74
  request: this.ctx.request,
75
75
  }, this.ctx.locals, locals);
@@ -1,11 +1,12 @@
1
1
  import { IViewEngine } from './interface';
2
2
  export declare class ViewManager extends Map {
3
- app: any;
4
- viewConfig: any;
5
- config: any;
6
- extMap: Map<any, any>;
7
- fileMap: Map<any, any>;
8
- init(): void;
3
+ protected app: any;
4
+ protected viewConfig: any;
5
+ protected config: any;
6
+ protected extMap: Map<any, any>;
7
+ protected fileMap: Map<any, any>;
8
+ protected localsMap: {};
9
+ protected init(): void;
9
10
  /**
10
11
  * This method can register view engine.
11
12
  *
@@ -29,5 +30,16 @@ export declare class ViewManager extends Map {
29
30
  * @return {String} filename - the full path
30
31
  */
31
32
  resolve(name: string): Promise<string>;
33
+ /**
34
+ * add a global data for all views
35
+ * @param key
36
+ * @param localValue
37
+ */
38
+ addLocals(key: any, localValue: any): void;
39
+ /**
40
+ * get global locals data
41
+ */
42
+ getLocals(): {};
43
+ findEngine(ext: string): string;
32
44
  }
33
45
  //# sourceMappingURL=viewManager.d.ts.map
@@ -19,6 +19,7 @@ let ViewManager = class ViewManager extends Map {
19
19
  super(...arguments);
20
20
  this.extMap = new Map();
21
21
  this.fileMap = new Map();
22
+ this.localsMap = {};
22
23
  }
23
24
  init() {
24
25
  this.config = this.viewConfig;
@@ -79,6 +80,23 @@ let ViewManager = class ViewManager extends Map {
79
80
  this.fileMap.set(name, filename);
80
81
  return filename;
81
82
  }
83
+ /**
84
+ * add a global data for all views
85
+ * @param key
86
+ * @param localValue
87
+ */
88
+ addLocals(key, localValue) {
89
+ this.localsMap[key] = localValue;
90
+ }
91
+ /**
92
+ * get global locals data
93
+ */
94
+ getLocals() {
95
+ return this.localsMap;
96
+ }
97
+ findEngine(ext) {
98
+ return this.extMap.get(ext);
99
+ }
82
100
  };
83
101
  __decorate([
84
102
  (0, decorator_1.App)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/view",
3
- "version": "3.4.12",
3
+ "version": "3.5.1",
4
4
  "description": "Midway Component for render view",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/core": "^3.4.12",
30
+ "@midwayjs/core": "^3.5.1",
31
31
  "@midwayjs/decorator": "^3.4.11",
32
- "@midwayjs/koa": "^3.4.12",
33
- "@midwayjs/mock": "^3.4.12"
32
+ "@midwayjs/koa": "^3.5.1",
33
+ "@midwayjs/mock": "^3.5.1"
34
34
  },
35
- "gitHead": "96425bbb3a39dbe8f66069facc5b7440886f9cfe"
35
+ "gitHead": "3b63fc768617037644602dd5ad66d3734ce01b16"
36
36
  }