UNPKG

2.54 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13var __importStar = (this && this.__importStar) || function (mod) {
14 if (mod && mod.__esModule) return mod;
15 var result = {};
16 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
17 result["default"] = mod;
18 return result;
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21var Hogan = __importStar(require("hogan.js"));
22var diff2html_templates_1 = require("./diff2html-templates");
23var HoganJsUtils = (function () {
24 function HoganJsUtils(_a) {
25 var _b = _a.compiledTemplates, compiledTemplates = _b === void 0 ? {} : _b, _c = _a.rawTemplates, rawTemplates = _c === void 0 ? {} : _c;
26 var compiledRawTemplates = Object.entries(rawTemplates).reduce(function (previousTemplates, _a) {
27 var _b;
28 var name = _a[0], templateString = _a[1];
29 var compiledTemplate = Hogan.compile(templateString, { asString: false });
30 return __assign(__assign({}, previousTemplates), (_b = {}, _b[name] = compiledTemplate, _b));
31 }, {});
32 this.preCompiledTemplates = __assign(__assign(__assign({}, diff2html_templates_1.defaultTemplates), compiledTemplates), compiledRawTemplates);
33 }
34 HoganJsUtils.compile = function (templateString) {
35 return Hogan.compile(templateString, { asString: false });
36 };
37 HoganJsUtils.prototype.render = function (namespace, view, params, partials, indent) {
38 var templateKey = this.templateKey(namespace, view);
39 try {
40 var template = this.preCompiledTemplates[templateKey];
41 return template.render(params, partials, indent);
42 }
43 catch (e) {
44 throw new Error("Could not find template to render '" + templateKey + "'");
45 }
46 };
47 HoganJsUtils.prototype.template = function (namespace, view) {
48 return this.preCompiledTemplates[this.templateKey(namespace, view)];
49 };
50 HoganJsUtils.prototype.templateKey = function (namespace, view) {
51 return namespace + "-" + view;
52 };
53 return HoganJsUtils;
54}());
55exports.default = HoganJsUtils;
56//# sourceMappingURL=hoganjs-utils.js.map
\No newline at end of file