diff --git a/Definitions/mustache.d.ts b/Definitions/mustache.d.ts new file mode 100644 index 000000000..83dcb26ea --- /dev/null +++ b/Definitions/mustache.d.ts @@ -0,0 +1,50 @@ +// Type definitions for Mustache 0.7 +// Project: https://github.com/janl/mustache.js +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface MustacheScanner { + string: string; + tail: string; + pos: number; + + eos(): bool; + scan(re: RegExp): string; + scanUntil(re: RegExp): string; +} + +interface MustacheContext { + view; + parent; + + clearCache(); + push(view): MustacheContext; + lookup(name: string): any; +} + +interface MustacheWriter { + clearCache(); + compile(template: string, tags); + compilePartial(name, template, tags); + compileTokens(tokens, template); + render(template, view, partials); +} + +interface MustacheStatic { + name: string; + version: string; + tags: string; + Scanner: MustacheScanner; + Context: MustacheContext; + Writer: MustacheWriter; + escape; + + parse(template: string, tags); + clearCache(): MustacheWriter; + compile(template: string, tags): MustacheWriter; + compilePartial(name: string, template: string, tags): MustacheWriter; + compileTokens(tokens, template: string): MustacheWriter; + render(template: string, view: any, partials?: any): MustacheWriter; + to_html(template: string, view: any, partials?: any, send?): string; +} + +declare var Mustache: MustacheStatic; diff --git a/Tests/mustache-tests.ts b/Tests/mustache-tests.ts new file mode 100644 index 000000000..0ae9f7ed1 --- /dev/null +++ b/Tests/mustache-tests.ts @@ -0,0 +1,8 @@ +/// + +var view = { title: "Joe", calc: function () { return 2 + 4; } }; +var output = Mustache.render("{{title}} spends {{calc}}", view); + +var person; +var template = "

{{firstName}} {{lastName}}

Blog: {{blogURL}}"; +var html = Mustache.to_html(template, person); \ No newline at end of file