-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-hogan.js
52 lines (48 loc) · 1.48 KB
/
render-hogan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* render-hogan
*
* This module implements support for rendering [Mustache](http://mustache.github.com/)
* templates using [Hogan.js](https://github.com/twitter/hogan.js).
*/
define(['hogan'],
function(Hogan) {
/**
* Setup Hogan.js template engine.
*
* When rendering, this engine returns a compiled template function which can
* be cached for performance optimization.
*
* Examples:
*
* render.engine('text/x-mustache-template', hogan());
*
* A Note on MIME Types:
*
* It has become common convention to include templates within HTML by
* enclosing them within script tags:
*
* <script type=“text/template”>...</script>
*
* Recommended practice for Sail.js applications is to be more specific when
* indicating the MIME type, both as a way to communicate explicitly with
* other developers and as a means to use multiple template engines within an
* application.
*
* While no standard exists, the following list of MIME types are used to
* indicate Mustache templates in practice:
*
* * text/x-mustache-template
* [Announcing Handlebars.js](http://yehudakatz.com/2010/09/09/announcing-handlebars-js/)
*
* @return {Function}
* @api public
*/
return function(options) {
return function(str) {
var template = Hogan.compile(str, options);
return function(context, partials, indent) {
return template.render(context, partials, indent);
}
}
}
});