UNPKG

@midwayjs/view

Version:

Midway Component for render view

77 lines 3.46 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewConfiguration = void 0; const core_1 = require("@midwayjs/core"); const DefaultConfig = require("./config/config.default"); const LocalConfig = require("./config/config.local"); const viewManager_1 = require("./viewManager"); const contextView_1 = require("./contextView"); let ViewConfiguration = class ViewConfiguration { async onReady(container) { this.applicationManager .getApplications(['koa', 'egg', 'faas']) .forEach((app) => { Object.defineProperties(app.context, { /** * Render a file, then set to body, the parameter is same as {@link @ContextView#render} * @return {Promise} result */ render: { value: async function (...args) { const contextView = await this.requestContext.getAsync(contextView_1.ContextView); return contextView.render(...args).then(body => { this.body = body; }); }, }, /** * Render a file, same as {@link @ContextView#render} * @return {Promise} result */ renderView: { value: async function (...args) { const contextView = await this.requestContext.getAsync(contextView_1.ContextView); return contextView.render(...args); }, }, /** * Render template string, same as {@link @ContextView#renderString} * @return {Promise} result */ renderString: { value: async function (...args) { const contextView = await this.requestContext.getAsync(contextView_1.ContextView); return contextView.renderString(...args); }, }, }); }); await container.getAsync(viewManager_1.ViewManager); } }; __decorate([ (0, core_1.Inject)(), __metadata("design:type", core_1.MidwayApplicationManager) ], ViewConfiguration.prototype, "applicationManager", void 0); ViewConfiguration = __decorate([ (0, core_1.Configuration)({ namespace: 'view', importConfigs: [ { default: DefaultConfig, local: LocalConfig, }, ], }) ], ViewConfiguration); exports.ViewConfiguration = ViewConfiguration; //# sourceMappingURL=configuration.js.map