/src/honeynet_web/honeywall/static/twitter-bootstrap/docs/build/node_modules/hogan.js/wrappers/mustache.js.mustache
Mustache | 64 lines | 57 code | 7 blank | 0 comment | 4 complexity | f68fba5af29a7c107f69d818a7d3201e MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
1/*
2 * Copyright 2011 Twitter, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// A wrapper for compatibility with Mustache.js, quirks and all
17
18{{{template}}}
19{{{compiler}}}
20
21var Mustache = (function (Hogan) {
22
23 // Mustache.js has non-spec partial context behavior
24 function mustachePartial(name, context, partials, indent) {
25 var partialScope = this.f(name, context, partials, 0);
26 var cx = context;
27 if (partialScope) {
28 cx = cx.concat(partialScope);
29 }
30
31 return Hogan.Template.prototype.rp.call(this, name, cx, partials, indent);
32 }
33
34 var HoganTemplateWrapper = function(renderFunc, text, compiler){
35 this.rp = mustachePartial;
36 Hogan.Template.call(this, renderFunc, text, compiler);
37 };
38 HoganTemplateWrapper.prototype = Hogan.Template.prototype;
39
40 // Add a wrapper for Hogan's generate method. Mustache and Hogan keep
41 // separate caches, and Mustache returns wrapped templates.
42 var wrapper;
43 var HoganWrapper = function(){
44 this.cache = {};
45 this.generate = function(code, text, options) {
46 return new HoganTemplateWrapper(new Function('c', 'p', 'i', code), text, wrapper);
47 }
48 };
49 HoganWrapper.prototype = Hogan;
50 wrapper = new HoganWrapper();
51
52 return {
53 to_html: function(text, data, partials, sendFun) {
54 var template = wrapper.compile(text);
55 var result = template.render(data, partials);
56 if (!sendFun) {
57 return result;
58 }
59
60 sendFun(result);
61 }
62 }
63
64})(Hogan);