/src/honeynet_web/honeywall/static/twitter-bootstrap/docs/build/node_modules/hogan.js/wrappers/mustache.js.mustache

https://bitbucket.org/cpdean/pig · Mustache · 64 lines · 57 code · 7 blank · 0 comment · 4 complexity · f68fba5af29a7c107f69d818a7d3201e MD5 · raw file

  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. // A wrapper for compatibility with Mustache.js, quirks and all
  16. {{{template}}}
  17. {{{compiler}}}
  18. var Mustache = (function (Hogan) {
  19. // Mustache.js has non-spec partial context behavior
  20. function mustachePartial(name, context, partials, indent) {
  21. var partialScope = this.f(name, context, partials, 0);
  22. var cx = context;
  23. if (partialScope) {
  24. cx = cx.concat(partialScope);
  25. }
  26. return Hogan.Template.prototype.rp.call(this, name, cx, partials, indent);
  27. }
  28. var HoganTemplateWrapper = function(renderFunc, text, compiler){
  29. this.rp = mustachePartial;
  30. Hogan.Template.call(this, renderFunc, text, compiler);
  31. };
  32. HoganTemplateWrapper.prototype = Hogan.Template.prototype;
  33. // Add a wrapper for Hogan's generate method. Mustache and Hogan keep
  34. // separate caches, and Mustache returns wrapped templates.
  35. var wrapper;
  36. var HoganWrapper = function(){
  37. this.cache = {};
  38. this.generate = function(code, text, options) {
  39. return new HoganTemplateWrapper(new Function('c', 'p', 'i', code), text, wrapper);
  40. }
  41. };
  42. HoganWrapper.prototype = Hogan;
  43. wrapper = new HoganWrapper();
  44. return {
  45. to_html: function(text, data, partials, sendFun) {
  46. var template = wrapper.compile(text);
  47. var result = template.render(data, partials);
  48. if (!sendFun) {
  49. return result;
  50. }
  51. sendFun(result);
  52. }
  53. }
  54. })(Hogan);