diff --git a/types/teddy/index.d.ts b/types/teddy/index.d.ts new file mode 100644 index 0000000000..5699a25e49 --- /dev/null +++ b/types/teddy/index.d.ts @@ -0,0 +1,57 @@ +// Type definitions for teddy 0.4 +// Project: https://github.com/rooseveltframework/teddy +// Definitions by: Benjamin Lannon +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +// compiles a template +export function compile(template: string): string; + +// parses a template +export function render(template: string, model: object): string; + +// mutator method to set template root param; must be a string +export function setTemplateRoot(path: string): void; + +// mutator method to set verbosity param. takes human-readable string argument and converts it to an integer for more efficient checks against the setting +export function setVerbosity(n: number | string): void; + +// turn on or off the setting to cache template renders +export function cacheRenders(b: boolean): void; + +// mutator method to set default caches param: the number of cached versions of each templates to store by default if cacheRenders is enabled +export function setDefaultCaches(n: number): void; + +// mutator method to set max caches for a given registered template +export function setMaxCaches(template: string, n: number): void; + +// mutator method to set a whitelist of templates to cache, e.g. { "myTemplate.html": maxCaches} where maxCaches is an integer +export function setCacheWhitelist(o: object): void; + +// mutator method to set a blacklist of templates not to cache as an array +export function setCacheBlacklist(templateArray: ReadonlyArray): void; + +// sets all params to their default values +export function setDefaultParams(): void; + +// invalidates cache of a given template and model combination +// if no model is supplied, deletes all caches of the given template +export function flushCache(template: string, model?: object): void; + +// mutator method to set max passes param: the number of times the parser can iterate over the template +export function setMaxPasses(n: number): void; + +// turn on or off the setting to compile templates at every render +export function compileAtEveryRender(b: boolean): void; + +// turn on or off the setting to minify templates using teddy's internal minifier +export function minify(b: boolean): void; + +// default values for parameters sent to teddy +export let params: object; + +// compiled templates are stored as object collections, e.g. { "myTemplate.html": "

some markup

"} +export let templates: object; + +// cache of fully rendered temmplates, e.g. { "myTemplate.html": "

some markup

"} +export let renderedTemplates: object; diff --git a/types/teddy/teddy-tests.ts b/types/teddy/teddy-tests.ts new file mode 100644 index 0000000000..899b7d94f9 --- /dev/null +++ b/types/teddy/teddy-tests.ts @@ -0,0 +1,30 @@ +import * as teddy from "teddy"; + +teddy.compile("template.html"); + +const markup = teddy.render("template.html", {}); + +teddy.setTemplateRoot("~/"); + +teddy.setVerbosity(3); + +teddy.cacheRenders(true); + +teddy.setDefaultCaches(2); + +teddy.setMaxCaches("template.html", 2); + +teddy.setCacheWhitelist({ "template.html": 5 }); + +teddy.setCacheBlacklist(["template1.html", "template2.html"]); + +teddy.setDefaultParams(); + +teddy.flushCache("template.html"); +teddy.flushCache("template.html", {}); + +teddy.setMaxPasses(500); + +teddy.compileAtEveryRender(true); + +teddy.minify(false); diff --git a/types/teddy/tsconfig.json b/types/teddy/tsconfig.json new file mode 100644 index 0000000000..3e60a19082 --- /dev/null +++ b/types/teddy/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "teddy-tests.ts"] +} diff --git a/types/teddy/tslint.json b/types/teddy/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/teddy/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }