Support deno 1.3.x/0.67.0; replace handlebars with view_engine library

This commit is contained in:
2020-09-04 09:40:16 -05:00
parent 0f182b592b
commit ff34578d07
23 changed files with 287 additions and 141 deletions

View File

@@ -1,2 +1,5 @@
export * from '../../lib/src/module.ts'
export * from '../../di/module.ts'
export * from '../../di/module.ts'
import * as std from '../../lib/src/external/std.ts'
export { std }

View File

@@ -1,5 +1,27 @@
import { env } from '../../lib/src/unit/Scaffolding.ts';
import { env } from '../../lib/src/unit/Scaffolding.ts'
import {ViewEngine} from '../../lib/src/const/view_engines.ts'
export default {
name: env('APP_NAME', 'Daton'),
views: {
/*
* View engine that should be used to render templates.
* Options are Handlebars, Ejs, or Denjuck.
*/
engine: ViewEngine.Handlebars,
/*
* Relative path from the app directory to the base directory where
* view files should be looked up.
*/
base_dir: 'http/views',
/*
* If using Handlebars, optionally, the path to the directory within the
* base_dir that contains the partials. They will be automatically registered
* with Handlebars.
*/
partials_dir: 'partials',
},
}

View File

@@ -1,11 +1,13 @@
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'
import {Injectable} from '../../../di/module.ts'
@Injectable()
export default class HomeController extends Controller {
get_home(request: Request) {
return view('home', { request })
async get_home(request: Request) {
return view('home', { greeting: 'Hello' })
}
}

View File

@@ -1 +1,6 @@
<h1>Welcome to Daton!</h1>
<html>
{{> header }}
<body>
<h1>{{ greeting }} from Daton!</h1>
</body>
</html>

View File

@@ -1,14 +0,0 @@
<!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

@@ -0,0 +1,3 @@
<head>
<title>Daton</title>
</head>

View File

@@ -8,8 +8,11 @@ import units from './units.ts'
* Let's get up and running. The scaffolding provides the bare minimum
* amount of support required to get Daton up and running. The app handles
* the rest.
*
* Daton will automatically load and process application resources, which is
* why we need to pass in the base path of this script.
*/
const scaffolding = make(Scaffolding)
const scaffolding = make(Scaffolding, import.meta.url)
await scaffolding.up()
/*

View File

@@ -17,11 +17,11 @@ export default [
ConfigUnit,
DatabaseUnit,
ModelsUnit,
ViewEngineUnit,
HttpKernelUnit,
MiddlewareUnit,
ControllerUnit,
ViewEngineUnit,
RoutesUnit,
RoutingUnit,
// HttpServerUnit,
HttpServerUnit,
]