Support deno 1.3.x/0.67.0; replace handlebars with view_engine library
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '../../../di/src/decorator/Injection.ts'
|
||||
import { getCookies, setCookie, delCookie, ServerRequest } from '../external/http.ts'
|
||||
import { getCookies, setCookie, deleteCookie, ServerRequest } from '../external/http.ts'
|
||||
import { InMemCache } from '../support/InMemCache.ts'
|
||||
import { HTTPRequest } from './type/HTTPRequest.ts'
|
||||
|
||||
@@ -117,6 +117,6 @@ export class CookieJar {
|
||||
*/
|
||||
public async delete(key: string): Promise<void> {
|
||||
await this._cache.drop(key)
|
||||
delCookie(this.request.response, key)
|
||||
deleteCookie(this.request.response, key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export default class HTMLResponseFactory extends ResponseFactory {
|
||||
|
||||
public async write(request: Request): Promise<Request> {
|
||||
request = await super.write(request)
|
||||
request.response.headers.set('Content-Type', 'text/html')
|
||||
request.response.headers.set('Content-Type', 'text/html; charset=utf-8')
|
||||
request.response.body = this.value
|
||||
return request
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import ResponseFactory from './ResponseFactory.ts'
|
||||
import ViewEngine from '../../unit/ViewEngine.ts'
|
||||
import {Request} from '../Request.ts'
|
||||
|
||||
/**
|
||||
* Response factory that renders a partial view as HTML.
|
||||
* @return ResponseFactory
|
||||
*/
|
||||
export default class PartialViewResponseFactory extends ResponseFactory {
|
||||
constructor(
|
||||
/**
|
||||
* The view name.
|
||||
* @type string
|
||||
*/
|
||||
public readonly view: string,
|
||||
/**
|
||||
* Optionally, the response context.
|
||||
*/
|
||||
public readonly context?: any,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
public async write(request: Request) {
|
||||
const views: ViewEngine = this.make(ViewEngine)
|
||||
request.response.body = await views.partial(this.view, this.context)
|
||||
return request
|
||||
}
|
||||
}
|
||||
@@ -13,22 +13,19 @@ export default class ViewResponseFactory extends ResponseFactory {
|
||||
* @type string
|
||||
*/
|
||||
public readonly view: string,
|
||||
|
||||
/**
|
||||
* Optionally, the view context.
|
||||
* Optionally, the view data.
|
||||
*/
|
||||
public readonly context?: any,
|
||||
/**
|
||||
* Optionally, the layout name.
|
||||
* @type string
|
||||
*/
|
||||
public readonly layout?: string,
|
||||
public readonly data?: any,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
public async write(request: Request) {
|
||||
const views: ViewEngine = this.make(ViewEngine)
|
||||
request.response.body = await views.render(this.view, this.context, this.layout)
|
||||
request.response.body = await views.template(this.view, this.data)
|
||||
request.response.headers.set('Content-Type', 'text/html; charset=utf-8')
|
||||
return request
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import {HTTPStatus} from '../../const/http.ts'
|
||||
import HTTPErrorResponseFactory from './HTTPErrorResponseFactory.ts'
|
||||
import HTTPError from '../../error/HTTPError.ts'
|
||||
import ViewResponseFactory from './ViewResponseFactory.ts'
|
||||
import PartialViewResponseFactory from './PartialViewResponseFactory.ts'
|
||||
|
||||
/**
|
||||
* Get a new JSON response factory that writes the given object as JSON.
|
||||
@@ -69,22 +68,11 @@ export function http(status: HTTPStatus, message?: string): HTTPErrorResponseFac
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new view response factory for the given view name, passing along context and layout.
|
||||
* Get a new view response factory for the given view name, passing along any view data.
|
||||
* @param {string} view
|
||||
* @param [context]
|
||||
* @param {string} [layout]
|
||||
* @param [data]
|
||||
* @return ViewResponseFactory
|
||||
*/
|
||||
export function view(view: string, context?: any, layout?: string): ViewResponseFactory {
|
||||
return make(ViewResponseFactory, view, context, layout)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new partial view response factory for the given view name, passing along context.
|
||||
* @param {string} view
|
||||
* @param [context]
|
||||
* @return PartialViewResponseFactory
|
||||
*/
|
||||
export function partial(view: string, context?: any): PartialViewResponseFactory {
|
||||
return make(PartialViewResponseFactory, view, context)
|
||||
export function view(view: string, data?: any): ViewResponseFactory {
|
||||
return make(ViewResponseFactory, view, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user