Add view engine unit - handlebars - and response helpers

This commit is contained in:
garrettmills
2020-08-07 09:51:25 -05:00
parent 3e4f8f00f2
commit b5bde7d077
14 changed files with 165 additions and 2 deletions

View File

@@ -8,3 +8,4 @@ export { default as ModelsUnit } from '../../orm/src/ModelsUnit.ts'
export { default as HttpServerUnit } from '../../lib/src/unit/HttpServer.ts'
export { default as RoutingUnit } from '../../lib/src/unit/Routing.ts'
export { default as ServicesUnit } from '../../lib/src/unit/Services.ts'
export { default as ViewEngineUnit } from '../../lib/src/unit/ViewEngine.ts'

View File

@@ -0,0 +1,11 @@
import Controller from '../../../lib/src/http/Controller.ts'
import {Request} from '../../../lib/src/http/Request.ts'
import {view} from '../../../lib/src/http/response/helpers.ts'
export default class HomeController extends Controller {
get_home(request: Request) {
return view('home', { request })
}
}

View File

@@ -0,0 +1,9 @@
import { RouterDefinition } from '../../../lib/src/http/type/RouterDefinition.ts'
export default {
prefix: '/',
middleware: [],
get: {
'/': 'controller::Home.get_home',
},
} as RouterDefinition

1
app/http/views/home.hbs Normal file
View File

@@ -0,0 +1 @@
<h1>Welcome to Daton!</h1>

View File

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{{#if title}}
<title>{{ title }} | Daton</title>
{{else}}
<title>Daton</title>
{{/if}}
</head>
<body>
{{{ body }}}
</body>
</html>

View File

View File

@@ -9,6 +9,7 @@ import {
HttpServerUnit,
RoutingUnit,
ServicesUnit,
ViewEngineUnit,
} from './bundle/daton_units.ts'
export default [
@@ -19,6 +20,7 @@ export default [
HttpKernelUnit,
MiddlewareUnit,
ControllerUnit,
ViewEngineUnit,
RoutesUnit,
RoutingUnit,
HttpServerUnit,