Skip to content

Commit

Permalink
Merge pull request #47 from ryota-ka/parameterized-context
Browse files Browse the repository at this point in the history
Support the parameterized context
  • Loading branch information
chrisyip authored Sep 28, 2022
2 parents 19db997 + bed4bb9 commit d7f3ee8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
42 changes: 35 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/cheerio": "^0.22.12",
"@types/fs-extra": "^8.0.0",
"@types/got": "^9.6.5",
"@types/koa": "^2.0.49",
"@types/koa": "^2.13.5",
"@types/koa-router": "^7.0.42",
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.forin": "^4.4.6",
Expand Down
8 changes: 4 additions & 4 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ export class KoaPug {
* Bind render function to Koa context
* @param app Koa instance
*/
use (app: Koa) {
use <StateT = Koa.DefaultState, CustomT = Koa.DefaultContext>(app: Koa<StateT, CustomT>) {
const self = this
app.context.render = async function (tpl: string, locals?: any, options?: any) {
const ctx = this
const finalLocals = merge({}, self.helpers, self.defaultLocals, ctx.state, locals)
const finalLocals = merge({}, self.helpers, self.defaultLocals, (ctx as any).state, locals)
ctx.body = await self.render(tpl, finalLocals, options)
ctx.type = 'text/html'
}
Expand All @@ -164,13 +164,13 @@ declare module 'koa' {
}
}

interface PugOptions extends pug.Options {
interface PugOptions<StateT = Koa.DefaultState, CustomT = Koa.DefaultContext> extends pug.Options {
[key: string]: any

/**
* Koa instance
*/
app?: Koa
app?: Koa<StateT, CustomT>

/**
* Paths of helpers.
Expand Down

0 comments on commit d7f3ee8

Please sign in to comment.