From 119b5046d78e7438f4a284c52b6ec5a9ac8c5165 Mon Sep 17 00:00:00 2001 From: Tomek Wiszniewski Date: Thu, 21 Jan 2016 11:24:17 +0100 Subject: [PATCH] Document the API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I couldn’t find the API in the docs. This is what I found out by reading the source. Let’s save others the pain. Mark partials as optional --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index cbaf011..4f1d96d 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,25 @@ var output = Mustache.render("{{title}} spends {{calc}}", view); In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template. +## API + +Following is an [rtype](https://git.io/rtype) signature of the most commonly used functions. + +```js +Mustache.render( + template : String, + view : Object, + partials? : Object, +) => String + +Mustache.parse( + template : String, + tags = ['{{', '}}'] : Tags, +) => String + +interface Tags [String, String] +``` + ## Templates A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key. There are several types of tags available in mustache.js, described below.