You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
845 B
32 lines
845 B
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 data.
|
|
*/
|
|
public readonly data?: any,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
public async write(request: Request) {
|
|
const views: ViewEngine = this.make(ViewEngine)
|
|
request.response.body = await views.template(this.view, this.data)
|
|
request.response.headers.set('Content-Type', 'text/html; charset=utf-8')
|
|
return request
|
|
}
|
|
}
|