Rewriting co-views to work with TypeScript 2 stuff and fixing typing issues. (#11548)

This commit is contained in:
Joshua DeVinney 2016-10-03 15:13:32 -05:00 committed by Mohamed Hegazy
parent c9c2a0f8fa
commit e5078805b1
4 changed files with 75 additions and 74 deletions

View File

@ -1,13 +1,13 @@
/// <reference path="../node/node.d.ts" />
/// <reference path="co-views.d.ts" />
/// <reference types="node" />
/// <reference types="co-views" />
import views = require('co-views');
import * as views from 'co-views';
const render = views('views', {
map: {
html: 'swig'
map: {
html: 'swig',
},
default: 'jade'
default: 'jade',
});
const fileName = 'xxx'; // template file name

View File

@ -1,68 +0,0 @@
// Type definitions for co-views v2.1
// Project: https://github.com/tj/co-views/
// Definitions by: devlee <https://github.com/devlee/>
// Definitions: https://github.com/devlee/DefinitelyTyped
/* =================== USAGE ===================
import views = require('co-views');
const render = views('views', {
map: {
html: 'swig'
},
default: 'jade'
});
=============================================== */
declare module "co-views" {
interface EngineMap {
/**
* use for .html files
*/
html: string
}
interface CoViewsOptions {
/**
* default extname
*/
ext?: string,
/**
* default extname
*/
default?: string,
/**
* engine map
*/
map?: EngineMap,
/**
* proxy partials
*/
partials?: Object,
/**
* cache compiled templates
*/
cache?: boolean,
/**
* common locals data
*/
locals?: Object
}
/**
* Pass views `dir` and `opts` to return a render function.
*/
function views(dir?: string, opts?: CoViewsOptions): {
(view: string, locals?: Object): any
};
export = views;
}

50
co-views/index.d.ts vendored Normal file
View File

@ -0,0 +1,50 @@
// Type definitions for co-views v2.1
// Project: https://github.com/tj/co-views/
// Definitions by: devlee <https://github.com/devlee/>, Joshua DeVinney <https://github.com/geoffreak>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace CoViews {
/**
* Pass views `dir` and `opts` to return a render function.
*/
export interface Views {
(dir?: string, opts?: CoViewsOptions): { (view: string, locals?: Object): any }
}
export interface CoViewsOptions {
/**
* default extname
*/
ext?: string,
/**
* default extname
*/
default?: string,
/**
* engine map
*/
map?: Object,
/**
* proxy partials
*/
partials?: Object,
/**
* cache compiled templates
*/
cache?: boolean,
/**
* common locals data
*/
locals?: Object
}
}
declare var CoViews: CoViews.Views;
export = CoViews;

19
co-views/tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"co-views-tests.ts"
]
}