1 | var __assign = (this && this.__assign) || function () {
|
2 | __assign = Object.assign || function(t) {
|
3 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4 | s = arguments[i];
|
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6 | t[p] = s[p];
|
7 | }
|
8 | return t;
|
9 | };
|
10 | return __assign.apply(this, arguments);
|
11 | };
|
12 | import * as Hogan from 'hogan.js';
|
13 | import { defaultTemplates } from './diff2html-templates';
|
14 | var HoganJsUtils = (function () {
|
15 | function HoganJsUtils(_a) {
|
16 | var _b = _a.compiledTemplates, compiledTemplates = _b === void 0 ? {} : _b, _c = _a.rawTemplates, rawTemplates = _c === void 0 ? {} : _c;
|
17 | var compiledRawTemplates = Object.entries(rawTemplates).reduce(function (previousTemplates, _a) {
|
18 | var _b;
|
19 | var name = _a[0], templateString = _a[1];
|
20 | var compiledTemplate = Hogan.compile(templateString, { asString: false });
|
21 | return __assign(__assign({}, previousTemplates), (_b = {}, _b[name] = compiledTemplate, _b));
|
22 | }, {});
|
23 | this.preCompiledTemplates = __assign(__assign(__assign({}, defaultTemplates), compiledTemplates), compiledRawTemplates);
|
24 | }
|
25 | HoganJsUtils.compile = function (templateString) {
|
26 | return Hogan.compile(templateString, { asString: false });
|
27 | };
|
28 | HoganJsUtils.prototype.render = function (namespace, view, params, partials, indent) {
|
29 | var templateKey = this.templateKey(namespace, view);
|
30 | try {
|
31 | var template = this.preCompiledTemplates[templateKey];
|
32 | return template.render(params, partials, indent);
|
33 | }
|
34 | catch (e) {
|
35 | throw new Error("Could not find template to render '" + templateKey + "'");
|
36 | }
|
37 | };
|
38 | HoganJsUtils.prototype.template = function (namespace, view) {
|
39 | return this.preCompiledTemplates[this.templateKey(namespace, view)];
|
40 | };
|
41 | HoganJsUtils.prototype.templateKey = function (namespace, view) {
|
42 | return namespace + "-" + view;
|
43 | };
|
44 | return HoganJsUtils;
|
45 | }());
|
46 | export default HoganJsUtils;
|
47 |
|
\ | No newline at end of file |