Merge pull request #14594 from mudkipme/koa-hbs

Fix type declaration of koa-hbs
This commit is contained in:
Zhengbo Li
2017-02-14 11:13:15 -08:00
committed by GitHub
2 changed files with 35 additions and 35 deletions
+32 -31
View File
@@ -1,22 +1,21 @@
// Type definitions for koa-favicon v2.x
// Type definitions for koa-hbs v1.x
// Project: https://github.com/gilt/koa-hbs
// Definitions by: Jacob Malone <https://github.com/jcbmln/>
// Definitions by: Jacob Malone <https://github.com/jcbmln/>, Mudkip <https://github.com/mudkipme>
// Definitions: https://github.com/jcbmln/DefinitelyTyped
/* =================== USAGE ===================
import * as Hbs from "koa-hbs";
import * as Koa from "koa";
....import hbs = require("koa-hbs");
var hbs = new Hbs();
var app = new Koa();
app.use(hbs.middleware({
viewPath: __dirname + '/views'
}));
app.use(function *() {
yield this.render('main', {
app.use(async (ctx, next) => {
await ctx.render('main', {
title: 'koa-hbs'
});
});
@@ -25,31 +24,33 @@
/// <reference types="koa" />
declare module "koa-hbs" {
import * as Koa from "koa";
import * as Koa from "koa";
namespace Hbs {
export interface Middleware {
viewPath: Array<string> | string,
handlebars?: Function,
templateOptions?: {},
extname?: string,
partialsPath?: Array<string> | string,
defaultLayout?: string,
layoutsPath?: string,
contentHelperName?: string,
blockHelperName?: string,
disableCache?: boolean
}
declare namespace Hbs {
export interface Middleware {
viewPath: Array<string> | string,
handlebars?: Function,
templateOptions?: {},
extname?: string,
partialsPath?: Array<string> | string,
defaultLayout?: string,
layoutsPath?: string,
contentHelperName?: string,
blockHelperName?: string,
disableCache?: boolean
}
class Hbs {
constructor();
middleware(opts: Hbs.Middleware): any;
}
namespace Hbs {}
export = Hbs;
}
declare class Hbs {
constructor();
middleware(opts: Hbs.Middleware): any;
}
declare const hbs: Hbs;
export = hbs;
declare module "koa" {
export interface Context extends Request, Response {
render(tpl: string, locals?: {[key: string]: any}): Promise<void>;
}
}
+3 -4
View File
@@ -1,16 +1,15 @@
import * as Hbs from 'koa-hbs';
import * as Koa from 'koa';
import hbs = require("koa-hbs");
import * as Path from 'path';
const app = new Koa();
const hbs = new Hbs();
app.use(hbs.middleware({
viewPath: Path.join(__dirname, './views')
}));
app.use(function *(next: any) {
yield this.render('index', {
app.use(async (ctx, next) => {
await ctx.render('index', {
title: 'Hello World!'
});
});