Mustache.js definitions and tests added

This commit is contained in:
Boris Yankov
2012-10-09 19:21:17 +03:00
parent 61439ee57e
commit 8d563caa07
2 changed files with 58 additions and 0 deletions
+50
View File
@@ -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;
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../Definitions/mustache.d.ts" />
var view = { title: "Joe", calc: function () { return 2 + 4; } };
var output = Mustache.render("{{title}} spends {{calc}}", view);
var person;
var template = "<h1>{{firstName}} {{lastName}}</h1>Blog: {{blogURL}}";
var html = Mustache.to_html(template, person);