diff --git a/index.d.ts b/index.d.ts index 083a555a42..a32897d10c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -166,26 +166,6 @@ declare module 'egg' { realStatus: number; } - export interface ContextView { // tslint:disable-line - /** - * Render a file by view engine - * @param {String} name - the file path based on root - * @param {Object} [locals] - data used by template - * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine - * @return {Promise} result - return a promise with a render result - */ - render(name: string, locals?: any, options?: any): Promise; - - /** - * Render a template string by view engine - * @param {String} tpl - template string - * @param {Object} [locals] - data used by template - * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine - * @return {Promise} result - return a promise with a render result - */ - renderString(name: string, locals?: any, options?: any): Promise; - } - export type LoggerLevel = EggLoggerLevel; /** @@ -436,14 +416,6 @@ declare module 'egg' { maxFiles: number; } & PlainObject; - view: { - root: string; - cache: boolean; - defaultExtension: string; - defaultViewEngine: string; - mapping: PlainObject; - }; - watcher: PlainObject; onClientError(err: Error, socket: Socket, app: EggApplication): ClientErrorResponse | Promise; @@ -902,11 +874,6 @@ declare module 'egg' { */ starttime: number; - /** - * View instance that is created every request - */ - view: ContextView; - /** * http request helper base on httpclient, it will auto save httpclient log. * Keep the same api with httpclient.request(url, args). @@ -914,24 +881,6 @@ declare module 'egg' { */ curl(url: string, opt?: RequestOptions): Promise; - /** - * Render a file by view engine - * @param {String} name - the file path based on root - * @param {Object} [locals] - data used by template - * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine - * @return {Promise} result - return a promise with a render result - */ - render(name: string, locals?: any, options?: any): Promise; - - /** - * Render a template string by view engine - * @param {String} tpl - template string - * @param {Object} [locals] - data used by template - * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine - * @return {Promise} result - return a promise with a render result - */ - renderString(name: string, locals?: any, options?: any): Promise; - __(key: string, ...values: string[]): string; gettext(key: string, ...values: string[]): string; diff --git a/test/fixtures/apps/app-ts/app/controller/foo.ts b/test/fixtures/apps/app-ts/app/controller/foo.ts index 5c7c862972..9a9275f4e3 100644 --- a/test/fixtures/apps/app-ts/app/controller/foo.ts +++ b/test/fixtures/apps/app-ts/app/controller/foo.ts @@ -19,6 +19,7 @@ export default class FooController extends Controller { this.app.logger.info(e.name, body.foo); } } + async getBar() { try { this.ctx.body = await this.service.foo.bar(); @@ -26,6 +27,7 @@ export default class FooController extends Controller { this.ctx.logger.error(e); } } + async httpclient() { await this.app.httpclient.request('url', { method: 'POST', @@ -37,4 +39,18 @@ export default class FooController extends Controller { method: 'POST', }); } + + async testViewRender() { + const { ctx } = this; + this.app.logger.info(this.app.view.get('nunjucks')); + this.app.logger.info(this.app.config.view.root); + this.app.logger.info(this.app.config.view.defaultExtension); + ctx.body = await this.ctx.view.render('test.tpl', { + test: '123' + }); + } + + async testViewRenderString() { + this.ctx.body = await this.ctx.view.renderString('test'); + } }