import ResponseFactory from './ResponseFactory.ts' import ViewEngine from '../../unit/ViewEngine.ts' import {Request} from '../Request.ts' /** * Response factory that renders the given view as HTML. * @extends ResponseFactory */ export default class ViewResponseFactory extends ResponseFactory { constructor( /** * The view name. * @type string */ public readonly view: string, /** * Optionally, the view context. */ public readonly context?: any, /** * Optionally, the layout name. * @type string */ public readonly layout?: string, ) { super() } public async write(request: Request) { const views: ViewEngine = this.make(ViewEngine) request.response.body = await views.render(this.view, this.context, this.layout) return request } }