Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for layout template files & Code clean-up #165

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@
=============================================== */
import { Middleware } from 'koa'
type viewsOptions = {
/*
/**
* Whether to use ctx.body to receive the rendered template string. Defaults to true.
*/
autoRender?: boolean,
/*
/**
* Default extension for your views
*/
extension?: string,
/*
/**
* Map a file extension to an engine
*/
map?: any,
/*
/**
* replace consolidate as default engine source
*/
engineSource?: any,
/*
/**
* These options will get passed to the view engine. This is the time to add partials and helpers etc.
*/
options?: any,
}

type Renderer = (viewPath: string, locals?: any) => Promise<string>

/**
* return Function or Koa.middleware
* @param root Where your views are located. Must be an absolute path. All rendered views are relative to this path
* @param opts (optional)
*/
declare function views(root: string, opts?: viewsOptions): Middleware
declare function views(root: string, opts?: viewsOptions): Middleware & (() => Renderer)
declare namespace views {
const viewsOptions: viewsOptions;
}
Expand All @@ -57,6 +59,6 @@ export = views

declare module 'koa' {
interface ExtendableContext {
render(viewPath: string, locals?: any): Promise<void>
render: Renderer
}
}
Loading