@tsed/engines 1.1.4 → 7.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/.mocharc.js +5 -0
  2. package/.nycrc +26 -0
  3. package/lib/cjs/components/AtplEngine.js +13 -0
  4. package/lib/cjs/components/AtplEngine.js.map +1 -0
  5. package/lib/cjs/components/BracketEngine.js +18 -0
  6. package/lib/cjs/components/BracketEngine.js.map +1 -0
  7. package/lib/cjs/components/DotEngine.js +20 -0
  8. package/lib/cjs/components/DotEngine.js.map +1 -0
  9. package/lib/cjs/components/DustEngine.js +60 -0
  10. package/lib/cjs/components/DustEngine.js.map +1 -0
  11. package/lib/cjs/components/EctEngine.js +27 -0
  12. package/lib/cjs/components/EctEngine.js.map +1 -0
  13. package/lib/cjs/components/EjsEngine.js +13 -0
  14. package/lib/cjs/components/EjsEngine.js.map +1 -0
  15. package/lib/cjs/components/Engine.js +63 -0
  16. package/lib/cjs/components/Engine.js.map +1 -0
  17. package/lib/cjs/components/HamlCoffeeEngine.js +13 -0
  18. package/lib/cjs/components/HamlCoffeeEngine.js.map +1 -0
  19. package/lib/cjs/components/HamlEngine.js +19 -0
  20. package/lib/cjs/components/HamlEngine.js.map +1 -0
  21. package/lib/cjs/components/HamletEngine.js +19 -0
  22. package/lib/cjs/components/HamletEngine.js.map +1 -0
  23. package/lib/cjs/components/HandlebarsEngine.js +25 -0
  24. package/lib/cjs/components/HandlebarsEngine.js.map +1 -0
  25. package/lib/cjs/components/HoganEngine.js +21 -0
  26. package/lib/cjs/components/HoganEngine.js.map +1 -0
  27. package/lib/cjs/components/HtmlingEngine.js +17 -0
  28. package/lib/cjs/components/HtmlingEngine.js.map +1 -0
  29. package/lib/cjs/components/JazzEngine.js +17 -0
  30. package/lib/cjs/components/JazzEngine.js.map +1 -0
  31. package/lib/cjs/components/JqtplEngine.js +17 -0
  32. package/lib/cjs/components/JqtplEngine.js.map +1 -0
  33. package/lib/cjs/components/JustEngine.js +27 -0
  34. package/lib/cjs/components/JustEngine.js.map +1 -0
  35. package/lib/cjs/components/LiquorEngine.js +13 -0
  36. package/lib/cjs/components/LiquorEngine.js.map +1 -0
  37. package/lib/cjs/components/LodashEngine.js +20 -0
  38. package/lib/cjs/components/LodashEngine.js.map +1 -0
  39. package/lib/cjs/components/MarkoEngine.js +29 -0
  40. package/lib/cjs/components/MarkoEngine.js.map +1 -0
  41. package/lib/cjs/components/MoteEngine.js +13 -0
  42. package/lib/cjs/components/MoteEngine.js.map +1 -0
  43. package/lib/cjs/components/MustacheEngine.js +16 -0
  44. package/lib/cjs/components/MustacheEngine.js.map +1 -0
  45. package/lib/cjs/components/NunjucksEngine.js +56 -0
  46. package/lib/cjs/components/NunjucksEngine.js.map +1 -0
  47. package/lib/cjs/components/PlatesEngine.js +19 -0
  48. package/lib/cjs/components/PlatesEngine.js.map +1 -0
  49. package/lib/cjs/components/PugEngine.js +21 -0
  50. package/lib/cjs/components/PugEngine.js.map +1 -0
  51. package/lib/cjs/components/RactiveEngine.js +36 -0
  52. package/lib/cjs/components/RactiveEngine.js.map +1 -0
  53. package/lib/cjs/components/ReactEngine.js +136 -0
  54. package/lib/cjs/components/ReactEngine.js.map +1 -0
  55. package/lib/cjs/components/SlmEngine.js +13 -0
  56. package/lib/cjs/components/SlmEngine.js.map +1 -0
  57. package/lib/cjs/components/SquirrellyEngine.js +23 -0
  58. package/lib/cjs/components/SquirrellyEngine.js.map +1 -0
  59. package/lib/cjs/components/SwigEngine.js +21 -0
  60. package/lib/cjs/components/SwigEngine.js.map +1 -0
  61. package/lib/cjs/components/TemplayedEngine.js +16 -0
  62. package/lib/cjs/components/TemplayedEngine.js.map +1 -0
  63. package/lib/cjs/components/ToffeeEngine.js +22 -0
  64. package/lib/cjs/components/ToffeeEngine.js.map +1 -0
  65. package/lib/cjs/components/TwigEngine.js +28 -0
  66. package/lib/cjs/components/TwigEngine.js.map +1 -0
  67. package/lib/cjs/components/TwingEngine.js +29 -0
  68. package/lib/cjs/components/TwingEngine.js.map +1 -0
  69. package/lib/cjs/components/UnderscoreEngine.js +28 -0
  70. package/lib/cjs/components/UnderscoreEngine.js.map +1 -0
  71. package/lib/cjs/components/VashEngine.js +35 -0
  72. package/lib/cjs/components/VashEngine.js.map +1 -0
  73. package/lib/cjs/components/VelocityEngine.js +18 -0
  74. package/lib/cjs/components/VelocityEngine.js.map +1 -0
  75. package/lib/cjs/components/VueEngine.js +139 -0
  76. package/lib/cjs/components/VueEngine.js.map +1 -0
  77. package/lib/cjs/components/WalrusEngine.js +17 -0
  78. package/lib/cjs/components/WalrusEngine.js.map +1 -0
  79. package/lib/cjs/decorators/viewEngine.js +11 -0
  80. package/lib/cjs/decorators/viewEngine.js.map +1 -0
  81. package/lib/cjs/index.js +49 -0
  82. package/lib/cjs/index.js.map +1 -0
  83. package/lib/cjs/package.json +3 -0
  84. package/lib/cjs/registries/EnginesContainer.js +31 -0
  85. package/lib/cjs/registries/EnginesContainer.js.map +1 -0
  86. package/lib/cjs/utils/cache.js +140 -0
  87. package/lib/cjs/utils/cache.js.map +1 -0
  88. package/lib/cjs/utils/getEngines.js +47 -0
  89. package/lib/cjs/utils/getEngines.js.map +1 -0
  90. package/lib/esm/components/AtplEngine.js +10 -0
  91. package/lib/esm/components/AtplEngine.js.map +1 -0
  92. package/lib/esm/components/BracketEngine.js +15 -0
  93. package/lib/esm/components/BracketEngine.js.map +1 -0
  94. package/lib/esm/components/DotEngine.js +17 -0
  95. package/lib/esm/components/DotEngine.js.map +1 -0
  96. package/lib/esm/components/DustEngine.js +57 -0
  97. package/lib/esm/components/DustEngine.js.map +1 -0
  98. package/lib/esm/components/EctEngine.js +24 -0
  99. package/lib/esm/components/EctEngine.js.map +1 -0
  100. package/lib/esm/components/EjsEngine.js +10 -0
  101. package/lib/esm/components/EjsEngine.js.map +1 -0
  102. package/lib/esm/components/Engine.js +59 -0
  103. package/lib/esm/components/Engine.js.map +1 -0
  104. package/lib/esm/components/HamlCoffeeEngine.js +10 -0
  105. package/lib/esm/components/HamlCoffeeEngine.js.map +1 -0
  106. package/lib/esm/components/HamlEngine.js +16 -0
  107. package/lib/esm/components/HamlEngine.js.map +1 -0
  108. package/lib/esm/components/HamletEngine.js +16 -0
  109. package/lib/esm/components/HamletEngine.js.map +1 -0
  110. package/lib/esm/components/HandlebarsEngine.js +22 -0
  111. package/lib/esm/components/HandlebarsEngine.js.map +1 -0
  112. package/lib/esm/components/HoganEngine.js +18 -0
  113. package/lib/esm/components/HoganEngine.js.map +1 -0
  114. package/lib/esm/components/HtmlingEngine.js +14 -0
  115. package/lib/esm/components/HtmlingEngine.js.map +1 -0
  116. package/lib/esm/components/JazzEngine.js +14 -0
  117. package/lib/esm/components/JazzEngine.js.map +1 -0
  118. package/lib/esm/components/JqtplEngine.js +14 -0
  119. package/lib/esm/components/JqtplEngine.js.map +1 -0
  120. package/lib/esm/components/JustEngine.js +24 -0
  121. package/lib/esm/components/JustEngine.js.map +1 -0
  122. package/lib/esm/components/LiquorEngine.js +10 -0
  123. package/lib/esm/components/LiquorEngine.js.map +1 -0
  124. package/lib/esm/components/LodashEngine.js +17 -0
  125. package/lib/esm/components/LodashEngine.js.map +1 -0
  126. package/lib/esm/components/MarkoEngine.js +26 -0
  127. package/lib/esm/components/MarkoEngine.js.map +1 -0
  128. package/lib/esm/components/MoteEngine.js +10 -0
  129. package/lib/esm/components/MoteEngine.js.map +1 -0
  130. package/lib/esm/components/MustacheEngine.js +13 -0
  131. package/lib/esm/components/MustacheEngine.js.map +1 -0
  132. package/lib/esm/components/NunjucksEngine.js +53 -0
  133. package/lib/esm/components/NunjucksEngine.js.map +1 -0
  134. package/lib/esm/components/PlatesEngine.js +16 -0
  135. package/lib/esm/components/PlatesEngine.js.map +1 -0
  136. package/lib/esm/components/PugEngine.js +18 -0
  137. package/lib/esm/components/PugEngine.js.map +1 -0
  138. package/lib/esm/components/RactiveEngine.js +33 -0
  139. package/lib/esm/components/RactiveEngine.js.map +1 -0
  140. package/lib/esm/components/ReactEngine.js +133 -0
  141. package/lib/esm/components/ReactEngine.js.map +1 -0
  142. package/lib/esm/components/SlmEngine.js +10 -0
  143. package/lib/esm/components/SlmEngine.js.map +1 -0
  144. package/lib/esm/components/SquirrellyEngine.js +20 -0
  145. package/lib/esm/components/SquirrellyEngine.js.map +1 -0
  146. package/lib/esm/components/SwigEngine.js +18 -0
  147. package/lib/esm/components/SwigEngine.js.map +1 -0
  148. package/lib/esm/components/TemplayedEngine.js +13 -0
  149. package/lib/esm/components/TemplayedEngine.js.map +1 -0
  150. package/lib/esm/components/ToffeeEngine.js +19 -0
  151. package/lib/esm/components/ToffeeEngine.js.map +1 -0
  152. package/lib/esm/components/TwigEngine.js +25 -0
  153. package/lib/esm/components/TwigEngine.js.map +1 -0
  154. package/lib/esm/components/TwingEngine.js +26 -0
  155. package/lib/esm/components/TwingEngine.js.map +1 -0
  156. package/lib/esm/components/UnderscoreEngine.js +25 -0
  157. package/lib/esm/components/UnderscoreEngine.js.map +1 -0
  158. package/lib/esm/components/VashEngine.js +32 -0
  159. package/lib/esm/components/VashEngine.js.map +1 -0
  160. package/lib/esm/components/VelocityEngine.js +15 -0
  161. package/lib/esm/components/VelocityEngine.js.map +1 -0
  162. package/lib/esm/components/VueEngine.js +136 -0
  163. package/lib/esm/components/VueEngine.js.map +1 -0
  164. package/lib/esm/components/WalrusEngine.js +14 -0
  165. package/lib/esm/components/WalrusEngine.js.map +1 -0
  166. package/lib/esm/decorators/viewEngine.js +7 -0
  167. package/lib/esm/decorators/viewEngine.js.map +1 -0
  168. package/lib/esm/index.js +46 -0
  169. package/lib/esm/index.js.map +1 -0
  170. package/lib/esm/package.json +3 -0
  171. package/lib/esm/registries/EnginesContainer.js +27 -0
  172. package/lib/esm/registries/EnginesContainer.js.map +1 -0
  173. package/lib/esm/utils/cache.js +127 -0
  174. package/lib/esm/utils/cache.js.map +1 -0
  175. package/lib/esm/utils/getEngines.js +42 -0
  176. package/lib/esm/utils/getEngines.js.map +1 -0
  177. package/lib/{components → types/components}/AtplEngine.d.ts +0 -0
  178. package/lib/{components → types/components}/BracketEngine.d.ts +0 -0
  179. package/lib/{components → types/components}/DotEngine.d.ts +0 -0
  180. package/lib/{components → types/components}/DustEngine.d.ts +0 -0
  181. package/lib/{components → types/components}/EctEngine.d.ts +0 -0
  182. package/lib/{components → types/components}/EjsEngine.d.ts +0 -0
  183. package/lib/{components → types/components}/Engine.d.ts +4 -1
  184. package/lib/{components → types/components}/HamlCoffeeEngine.d.ts +0 -0
  185. package/lib/{components → types/components}/HamlEngine.d.ts +0 -0
  186. package/lib/{components → types/components}/HamletEngine.d.ts +0 -0
  187. package/lib/{components → types/components}/HandlebarsEngine.d.ts +0 -0
  188. package/lib/{components → types/components}/HoganEngine.d.ts +0 -0
  189. package/lib/{components → types/components}/HtmlingEngine.d.ts +0 -0
  190. package/lib/{components → types/components}/JazzEngine.d.ts +0 -0
  191. package/lib/{components → types/components}/JqtplEngine.d.ts +0 -0
  192. package/lib/{components → types/components}/JustEngine.d.ts +0 -0
  193. package/lib/{components → types/components}/LiquorEngine.d.ts +0 -0
  194. package/lib/{components → types/components}/LodashEngine.d.ts +0 -0
  195. package/lib/{components → types/components}/MarkoEngine.d.ts +0 -0
  196. package/lib/{components → types/components}/MoteEngine.d.ts +0 -0
  197. package/lib/{components → types/components}/MustacheEngine.d.ts +0 -0
  198. package/lib/{components → types/components}/NunjucksEngine.d.ts +0 -0
  199. package/lib/{components → types/components}/PlatesEngine.d.ts +0 -0
  200. package/lib/{components → types/components}/PugEngine.d.ts +0 -0
  201. package/lib/{components → types/components}/RactiveEngine.d.ts +0 -0
  202. package/lib/{components → types/components}/ReactEngine.d.ts +3 -0
  203. package/lib/{components → types/components}/SlmEngine.d.ts +0 -0
  204. package/lib/{components → types/components}/SquirrellyEngine.d.ts +0 -0
  205. package/lib/{components → types/components}/SwigEngine.d.ts +0 -0
  206. package/lib/{components → types/components}/TemplayedEngine.d.ts +0 -0
  207. package/lib/{components → types/components}/ToffeeEngine.d.ts +0 -0
  208. package/lib/{components → types/components}/TwigEngine.d.ts +0 -0
  209. package/lib/{components → types/components}/TwingEngine.d.ts +0 -0
  210. package/lib/{components → types/components}/UnderscoreEngine.d.ts +0 -0
  211. package/lib/{components → types/components}/VashEngine.d.ts +0 -0
  212. package/lib/{components → types/components}/VelocityEngine.d.ts +0 -0
  213. package/lib/{components → types/components}/VueEngine.d.ts +2 -2
  214. package/lib/{components → types/components}/WalrusEngine.d.ts +0 -0
  215. package/lib/{decorators → types/decorators}/viewEngine.d.ts +0 -0
  216. package/lib/{index.d.ts → types/index.d.ts} +6 -3
  217. package/lib/{registries → types/registries}/EnginesContainer.d.ts +0 -0
  218. package/lib/{utils → types/utils}/cache.d.ts +3 -3
  219. package/lib/{utils → types/utils}/getEngines.d.ts +0 -0
  220. package/package.json +35 -27
  221. package/readme.md +91 -90
  222. package/tsconfig.compile.esm.json +25 -0
  223. package/lib/index.js +0 -1211
  224. package/lib/index.js.map +0 -1
  225. package/lib/index.modern.js +0 -1198
  226. package/lib/index.modern.js.map +0 -1
package/lib/index.js DELETED
@@ -1,1211 +0,0 @@
1
- var tslib = require('tslib');
2
- var fs = require('fs-extra');
3
- var path = require('path');
4
- var util = require('util');
5
- var fs$1 = require('fs');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
10
-
11
- function _extends() {
12
- _extends = Object.assign || function (target) {
13
- for (var i = 1; i < arguments.length; i++) {
14
- var source = arguments[i];
15
-
16
- for (var key in source) {
17
- if (Object.prototype.hasOwnProperty.call(source, key)) {
18
- target[key] = source[key];
19
- }
20
- }
21
- }
22
-
23
- return target;
24
- };
25
-
26
- return _extends.apply(this, arguments);
27
- }
28
-
29
- var id = 0;
30
-
31
- function _classPrivateFieldLooseKey(name) {
32
- return "__private_" + id++ + "_" + name;
33
- }
34
-
35
- function _classPrivateFieldLooseBase(receiver, privateKey) {
36
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
37
- throw new TypeError("attempted to use private field on non-instance");
38
- }
39
-
40
- return receiver;
41
- }
42
-
43
- var _providers = /*#__PURE__*/_classPrivateFieldLooseKey("providers");
44
-
45
- class EnginesContainer {
46
- constructor() {
47
- Object.defineProperty(this, _providers, {
48
- writable: true,
49
- value: void 0
50
- });
51
- _classPrivateFieldLooseBase(this, _providers)[_providers] = new Map();
52
- }
53
-
54
- has(key) {
55
- return _classPrivateFieldLooseBase(this, _providers)[_providers].has(key);
56
- }
57
-
58
- get(key) {
59
- const provider = _classPrivateFieldLooseBase(this, _providers)[_providers].get(key);
60
-
61
- if (provider && !provider.instance) {
62
- provider.instance = new provider.useClass(provider.name, provider.options);
63
- }
64
-
65
- return provider == null ? void 0 : provider.instance;
66
- }
67
-
68
- set(key, provider) {
69
- _classPrivateFieldLooseBase(this, _providers)[_providers].set(key, provider);
70
-
71
- _classPrivateFieldLooseBase(this, _providers)[_providers].set(provider.name, provider);
72
- }
73
-
74
- getSupportedEngines() {
75
- return [..._classPrivateFieldLooseBase(this, _providers)[_providers].keys()].filter(key => typeof key === "string");
76
- }
77
-
78
- }
79
- const engines = new EnginesContainer();
80
-
81
- function ViewEngine(name, options = {}) {
82
- return target => {
83
- engines.set(target, {
84
- name,
85
- useClass: target,
86
- options
87
- });
88
- };
89
- }
90
-
91
- const readCache = new Map();
92
- const cacheStore = new Map();
93
- const requires = new Map();
94
- const extend = require("util")._extend;
95
- function requireEngine(name, toName = name) {
96
- if (!requires.has(toName)) {
97
- setRequireEngine(name, toName);
98
- }
99
-
100
- return requires.get(toName);
101
- }
102
- function setRequireEngine(name, toName = name) {
103
- requires.set(toName, require(name));
104
- }
105
- function setToCache(key, value) {
106
- readCache.set(key, value);
107
- }
108
- function getFromCache(key) {
109
- return readCache.get(key);
110
- }
111
- /**
112
- * Clear the cache.
113
- *
114
- * @api public
115
- */
116
-
117
- const clearCache = () => {
118
- readCache.clear();
119
- cacheStore.clear();
120
- };
121
- /**
122
- * Conditionally cache `compiled` template based
123
- * on the `options` filename and `.cache` boolean.
124
- *
125
- * @param {Object} options
126
- * @param {Function} compiled
127
- * @return {Function}
128
- */
129
-
130
- function cache(options, compiled) {
131
- // cachable
132
- if (compiled && options.filename && options.cache) {
133
- readCache.delete(options.filename);
134
- cacheStore.set(options.filename, compiled);
135
- return compiled;
136
- } // check cache
137
-
138
-
139
- if (options.filename && options.cache) {
140
- return cacheStore.get(options.filename);
141
- }
142
-
143
- return compiled;
144
- }
145
- /**
146
- * Read `path` with `options` with
147
- * callback `(err, str)`. When `options.cache`
148
- * is true the template string will be cached.
149
- *
150
- * @param path
151
- * @param {String} options
152
- */
153
-
154
- async function read(path, options) {
155
- let str = readCache.get(path); // cached (only if cached is a string and not a compiled template function)
156
-
157
- if (options.cache && str && typeof str === "string") {
158
- return str;
159
- } // read
160
-
161
-
162
- str = await fs__default['default'].readFile(path, "utf8"); // remove extraneous utf8 BOM marker
163
-
164
- str = str.replace(/^\uFEFF/, "");
165
-
166
- if (options.cache) {
167
- readCache.set(path, str);
168
- }
169
-
170
- return str;
171
- }
172
- /**
173
- * Read `path` with `options` with
174
- * callback `(err, str)`. When `options.cache`
175
- * is true the partial string will be cached.
176
- *
177
- * @param path
178
- * @param {String} options
179
- * @api private
180
- */
181
-
182
- async function readPartials(path$1, options) {
183
- if (!options.partials) {
184
- return;
185
- }
186
-
187
- const keys = Object.keys(options.partials);
188
- const partials = {};
189
- return new Promise((resolve, reject) => {
190
- async function next(index) {
191
- if (index === keys.length) {
192
- return resolve(partials);
193
- }
194
-
195
- const key = keys[index];
196
- const partialPath = options.partials[key];
197
-
198
- if (partialPath === undefined || partialPath === null || partialPath === false) {
199
- return next(++index);
200
- }
201
-
202
- let file;
203
-
204
- if (path.isAbsolute(partialPath)) {
205
- if (path.extname(partialPath) !== "") {
206
- file = partialPath;
207
- } else {
208
- file = path.join(partialPath + path.extname(path$1));
209
- }
210
- } else {
211
- file = path.join(path.dirname(path$1), partialPath + path.extname(path$1));
212
- }
213
-
214
- try {
215
- partials[key] = await read(file, options);
216
- next(++index);
217
- } catch (err) {
218
- reject(err);
219
- }
220
- }
221
-
222
- next(0);
223
- });
224
- }
225
-
226
- class Engine {
227
- constructor(name, options) {
228
- this.name = name;
229
- const reqs = [].concat(options.requires || [name]);
230
- reqs.forEach(req => {
231
- try {
232
- requireEngine(req, name);
233
- this.driverName = req;
234
- } catch (er) {}
235
- });
236
- }
237
-
238
- get engine() {
239
- return requireEngine(this.name);
240
- }
241
-
242
- compile(template, options) {
243
- options = this.$cacheOptions(template, options, false);
244
- return cache(options) || cache(options, this.$compile.call(this, template, options));
245
- }
246
-
247
- compileFile(file, options) {
248
- options = this.$cacheOptions(file, options, true);
249
- return cache(options) || cache(options, this.$compileFile.call(this, file, options));
250
- }
251
-
252
- async render(template, options) {
253
- const compile = await this.compile(template, options);
254
- return compile(options);
255
- }
256
-
257
- async renderFile(file, options) {
258
- const opts = await this.readPartials(file, options);
259
- const compile = await this.compileFile(file, opts);
260
- return compile(opts);
261
- }
262
-
263
- async readPartials(file, options) {
264
- options.filename = file;
265
- const partials = await readPartials(file, options);
266
- const opts = extend({}, options);
267
- opts.partials = partials;
268
- return opts;
269
- }
270
-
271
- $cacheOptions(template, options, fromFile) {
272
- return options;
273
- }
274
-
275
- $compile(template, options) {
276
- return this.engine.compile(template, options);
277
- }
278
-
279
- async $compileFile(file, options) {
280
- const template = await read(file, options);
281
- return this.$compile(template, options);
282
- }
283
-
284
- }
285
-
286
- exports.AtplEngine = class AtplEngine extends Engine {};
287
- exports.AtplEngine = tslib.__decorate([ViewEngine("atpl")], exports.AtplEngine);
288
-
289
- exports.BracketEngine = class BracketEngine extends Engine {
290
- $compile(template, options) {
291
- return this.engine.default.compile(template, options);
292
- }
293
-
294
- };
295
- exports.BracketEngine = tslib.__decorate([ViewEngine("bracket", {
296
- requires: "bracket-template"
297
- })], exports.BracketEngine);
298
-
299
- exports.DotEngine = class DotEngine extends Engine {
300
- getSettings(options) {
301
- const settings = extend({}, this.engine.templateSettings);
302
- return extend(settings, options ? options.dot : {});
303
- }
304
-
305
- $compile(template, options) {
306
- return this.engine.template(template, this.getSettings(options), options);
307
- }
308
-
309
- };
310
- exports.DotEngine = tslib.__decorate([ViewEngine("dot")], exports.DotEngine);
311
-
312
- exports.DustEngine = class DustEngine extends Engine {
313
- constructor() {
314
- super(...arguments);
315
- this.views = ".";
316
- this.ext = "dust";
317
- }
318
-
319
- configure(options) {
320
- if (options) {
321
- if (options.ext) {
322
- this.ext = options.ext;
323
- }
324
-
325
- if (options.views) {
326
- this.views = options.views;
327
- }
328
-
329
- if (options.settings && options.settings.views) {
330
- this.views = options.settings.views;
331
- }
332
- }
333
-
334
- if (!options || options && !options.cache) this.engine.cache = {};
335
-
336
- this.engine.onLoad = async (path$1, callback) => {
337
- if (path.extname(path$1) === "") {
338
- path$1 += `.${this.ext}`;
339
- }
340
-
341
- if (path$1[0] !== "/") {
342
- path$1 = `${this.views}/${path$1}`;
343
- }
344
-
345
- try {
346
- callback(null, await read(path$1, options));
347
- } catch (er) {
348
- callback(er);
349
- }
350
- };
351
- }
352
-
353
- $compile(template, options) {
354
- this.configure(options);
355
- let templateName;
356
-
357
- if (options.filename) {
358
- templateName = options.filename.replace(new RegExp("^" + this.views + "/"), "").replace(new RegExp("\\." + this.ext), "");
359
- }
360
-
361
- return util.promisify(this.engine.compileFn(template, templateName));
362
- }
363
-
364
- };
365
- exports.DustEngine = tslib.__decorate([ViewEngine("dust", {
366
- requires: ["dustjs-helpers", "dustjs-linkedin"]
367
- })], exports.DustEngine);
368
-
369
- exports.EctEngine = class EctEngine extends Engine {
370
- $compile(template, options) {
371
- const ECT = this.engine;
372
- const engine = new ECT({
373
- root: {
374
- page: template
375
- }
376
- });
377
- const compile = util.promisify(engine.render.bind(engine));
378
- return options => compile("page", options);
379
- }
380
-
381
- async $compileFile(file, options) {
382
- const ECT = this.engine;
383
- const engine = new ECT(options);
384
- engine.configure({
385
- cache: options.cache
386
- });
387
- const compile = util.promisify(engine.render.bind(engine));
388
- return options => compile(file, options);
389
- }
390
-
391
- };
392
- exports.EctEngine = tslib.__decorate([ViewEngine("ect")], exports.EctEngine);
393
-
394
- exports.EjsEngine = class EjsEngine extends Engine {};
395
- exports.EjsEngine = tslib.__decorate([ViewEngine("ejs")], exports.EjsEngine);
396
-
397
- exports.HamlEngine = class HamlEngine extends Engine {
398
- $compile(template, options) {
399
- return options => {
400
- options.locals = options;
401
- return Promise.resolve(this.engine.render(template, options).trimLeft());
402
- };
403
- }
404
-
405
- };
406
- exports.HamlEngine = tslib.__decorate([ViewEngine("haml")], exports.HamlEngine);
407
-
408
- exports.HamlCoffeeEngine = class HamlCoffeeEngine extends Engine {};
409
- exports.HamlCoffeeEngine = tslib.__decorate([ViewEngine("haml-coffee")], exports.HamlCoffeeEngine);
410
-
411
- exports.HamletEngine = class HamletEngine extends Engine {
412
- $compile(template, options) {
413
- return options => {
414
- options.locals = options;
415
- return Promise.resolve(this.engine.render(template, options).trimLeft());
416
- };
417
- }
418
-
419
- };
420
- exports.HamletEngine = tslib.__decorate([ViewEngine("hamlet")], exports.HamletEngine);
421
-
422
- exports.HandlebarsEngine = class HandlebarsEngine extends Engine {
423
- configure(options) {
424
- for (const partial in options.partials) {
425
- this.engine.registerPartial(partial, options.partials[partial]);
426
- }
427
-
428
- for (const helper in options.helpers) {
429
- this.engine.registerHelper(helper, options.helpers[helper]);
430
- }
431
- }
432
-
433
- $compile(template, options) {
434
- this.configure(options);
435
- return this.engine.compile(template, options);
436
- }
437
-
438
- };
439
- exports.HandlebarsEngine = tslib.__decorate([ViewEngine("handlebars")], exports.HandlebarsEngine);
440
-
441
- exports.HoganEngine = class HoganEngine extends Engine {
442
- $compile(template, options) {
443
- const compile = this.engine.compile(template, options);
444
- return options => {
445
- return compile.render(options, options.partials);
446
- };
447
- }
448
-
449
- };
450
- exports.HoganEngine = tslib.__decorate([ViewEngine("hogan", {
451
- requires: "hogan.js"
452
- })], exports.HoganEngine);
453
-
454
- exports.HtmlingEngine = class HtmlingEngine extends Engine {
455
- $compile(template) {
456
- const compile = this.engine.string(template);
457
- return options => compile.render(options);
458
- }
459
-
460
- };
461
- exports.HtmlingEngine = tslib.__decorate([ViewEngine("htmling")], exports.HtmlingEngine);
462
-
463
- exports.JazzEngine = class JazzEngine extends Engine {
464
- $compile(template, options) {
465
- const compile = this.engine.compile(template, options);
466
- return options => new Promise(resolve => compile.eval(options, resolve));
467
- }
468
-
469
- };
470
- exports.JazzEngine = tslib.__decorate([ViewEngine("jazz")], exports.JazzEngine);
471
-
472
- exports.JqtplEngine = class JqtplEngine extends Engine {
473
- $compile(template, options) {
474
- this.engine.template(template, template);
475
- return options => this.engine.tmpl(template, options);
476
- }
477
-
478
- };
479
- exports.JqtplEngine = tslib.__decorate([ViewEngine("jqtpl")], exports.JqtplEngine);
480
-
481
- exports.JustEngine = class JustEngine extends Engine {
482
- $compile(template, options) {
483
- const JUST = this.engine;
484
- const engine = new JUST({
485
- root: {
486
- page: template
487
- }
488
- });
489
- const compile = util.promisify(engine.render.bind(engine));
490
- return options => compile("page", options);
491
- }
492
-
493
- async $compileFile(file, options) {
494
- const JUST = this.engine;
495
- const engine = new JUST(options);
496
- engine.configure({
497
- useCache: options.cache
498
- });
499
- const compile = util.promisify(engine.render.bind(engine));
500
- return options => compile(file, options);
501
- }
502
-
503
- };
504
- exports.JustEngine = tslib.__decorate([ViewEngine("just")], exports.JustEngine);
505
-
506
- exports.LiquorEngine = class LiquorEngine extends Engine {};
507
- exports.LiquorEngine = tslib.__decorate([ViewEngine("liquor")], exports.LiquorEngine);
508
-
509
- exports.LodashEngine = class LodashEngine extends Engine {
510
- render(template, options) {
511
- const compile = this.compile(template, options);
512
- return compile(options).replace(/\n$/, "");
513
- }
514
-
515
- $compile(template, options) {
516
- return this.engine.template(template, options);
517
- }
518
-
519
- };
520
- exports.LodashEngine = tslib.__decorate([ViewEngine("lodash")], exports.LodashEngine);
521
-
522
- exports.MarkoEngine = class MarkoEngine extends Engine {
523
- $cacheOptions(template, options, fromFile) {
524
- options.writeToDisk = !!options.cache;
525
-
526
- if (!fromFile) {
527
- options.filename = options.filename || "string.marko";
528
- }
529
-
530
- return options;
531
- }
532
-
533
- async $compileFile(file, options) {
534
- const $cmp = this.engine.load(file, options);
535
- return util.promisify($cmp.renderToString.bind($cmp));
536
- }
537
-
538
- $compile(template, options) {
539
- const $cmp = this.engine.load(options.filename, template, options);
540
- return util.promisify($cmp.renderToString.bind($cmp));
541
- }
542
-
543
- };
544
- exports.MarkoEngine = tslib.__decorate([ViewEngine("marko")], exports.MarkoEngine);
545
-
546
- exports.MoteEngine = class MoteEngine extends Engine {};
547
- exports.MoteEngine = tslib.__decorate([ViewEngine("mote")], exports.MoteEngine);
548
-
549
- exports.MustacheEngine = class MustacheEngine extends Engine {
550
- $compile(template, options) {
551
- return options => this.engine.render(template, options, options.partials);
552
- }
553
-
554
- };
555
- exports.MustacheEngine = tslib.__decorate([ViewEngine("mustache")], exports.MustacheEngine);
556
-
557
- exports.NunjucksEngine = class NunjucksEngine extends Engine {
558
- configure(options) {
559
- const engine = options.nunjucksEnv || this.engine;
560
- let env = engine; // deprecated fallback support for express
561
- // <https://github.com/tj/consolidate.js/pull/152>
562
- // <https://github.com/tj/consolidate.js/pull/224>
563
-
564
- if (options.settings && options.settings.views) {
565
- env = engine.configure(options.settings.views);
566
- } else if (options.nunjucks && options.nunjucks.configure) {
567
- // eslint-disable-next-line prefer-spread
568
- env = engine.configure.apply(engine, options.nunjucks.configure);
569
- } //
570
- // because `renderString` does not initiate loaders
571
- // we must manually create a loader for it based off
572
- // either `options.settings.views` or `options.nunjucks` or `options.nunjucks.root`
573
- //
574
- // <https://github.com/mozilla/nunjucks/issues/730>
575
- // <https://github.com/crocodilejs/node-email-templates/issues/182>
576
- //
577
- // so instead we simply check if we passed a custom loader
578
- // otherwise we create a simple file based loader
579
-
580
-
581
- if (options.loader) {
582
- return new engine.Environment(options.loader);
583
- }
584
-
585
- if (options.settings && options.settings.views) {
586
- return new engine.Environment(new engine.FileSystemLoader(options.settings.views));
587
- }
588
-
589
- if (options.nunjucks && options.nunjucks.loader) {
590
- if (typeof options.nunjucks.loader === "string") {
591
- return new engine.Environment(new engine.FileSystemLoader(options.nunjucks.loader));
592
- }
593
-
594
- return new engine.Environment(new engine.FileSystemLoader(options.nunjucks.loader[0], options.nunjucks.loader[1]));
595
- }
596
-
597
- return env;
598
- }
599
-
600
- $compile(template, options) {
601
- let engine = this.configure(options);
602
- const render = util.promisify(engine.renderString.bind(engine));
603
- return options => render(template, options);
604
- }
605
-
606
- };
607
- exports.NunjucksEngine = tslib.__decorate([ViewEngine("nunjucks")], exports.NunjucksEngine);
608
-
609
- exports.PlatesEngine = class PlatesEngine extends Engine {
610
- $compile(template, options) {
611
- return options => {
612
- const map = options.map || undefined;
613
- return this.engine.bind(template, options, map);
614
- };
615
- }
616
-
617
- };
618
- exports.PlatesEngine = tslib.__decorate([ViewEngine("plates")], exports.PlatesEngine);
619
-
620
- exports.PugEngine = class PugEngine extends Engine {
621
- $compile(template, options) {
622
- return this.engine.compile(template, options);
623
- }
624
-
625
- async $compileFile(file, options) {
626
- return this.engine.compileFile(file, options);
627
- }
628
-
629
- };
630
- exports.PugEngine = tslib.__decorate([ViewEngine("pug", {
631
- requires: ["pug", "then-pug"]
632
- })], exports.PugEngine);
633
-
634
- exports.RactiveEngine = class RactiveEngine extends Engine {
635
- $compile(template, options) {
636
- const Engine = this.engine;
637
- const compile = this.engine.parse(template);
638
- return options => {
639
- options.template = compile;
640
- return new Engine(this.clean(options)).toHTML();
641
- };
642
- }
643
-
644
- clean(options) {
645
- if (options.data === null || options.data === undefined) {
646
- // Shallow clone the options object
647
- options.data = extend({}, options); // Remove consolidate-specific properties from the clone
648
-
649
- let i;
650
- let length;
651
- let properties = ["template", "filename", "cache", "partials"];
652
-
653
- for (i = 0, length = properties.length; i < length; i++) {
654
- const property = properties[i];
655
- delete options.data[property];
656
- }
657
- }
658
-
659
- return options;
660
- }
661
-
662
- };
663
- exports.RactiveEngine = tslib.__decorate([ViewEngine("ractive")], exports.RactiveEngine);
664
-
665
- exports.ReactEngine = class ReactEngine extends Engine {
666
- constructor(name, options) {
667
- super(name, options);
668
- this.patchRequire();
669
- }
670
-
671
- patchRequire() {
672
- if (require.extensions) {
673
- // Ensure JSX is transformed on require
674
- if (!require.extensions[".jsx"]) {
675
- require.extensions[".jsx"] = this.requireReact.bind(this);
676
- } // Supporting .react extension as well as test cases
677
- // Using .react extension is not recommended.
678
-
679
-
680
- if (!require.extensions[".react"]) {
681
- require.extensions[".react"] = this.requireReact.bind(this);
682
- }
683
- }
684
- }
685
-
686
- configure(options) {
687
- const base = options.base;
688
- delete options.base;
689
- const enableCache = options.cache;
690
- delete options.cache;
691
- const isNonStatic = options.isNonStatic;
692
- delete options.isNonStatic;
693
- return {
694
- base,
695
- enableCache,
696
- isNonStatic
697
- };
698
- }
699
-
700
- $compile(template, options) {
701
- // Assign HTML Base
702
- const {
703
- base,
704
- enableCache,
705
- isNonStatic
706
- } = this.configure(options); // Start Conversion
707
-
708
- const ReactDOM = requireEngine("react-dom/server", "ReactDOM");
709
- const Code = this.requireReactString(template);
710
- const Factory = this.engine.createFactory(Code);
711
- return () => {
712
- const parsed = new Factory(options);
713
- const content = isNonStatic ? ReactDOM.renderToString(parsed) : ReactDOM.renderToStaticMarkup(parsed);
714
-
715
- if (base) {
716
- options.content = content;
717
- return this.renderWithBase(template, base, enableCache, options);
718
- }
719
-
720
- return content;
721
- };
722
- }
723
-
724
- async $compileFile(file, options) {
725
- // Assign HTML Base
726
- const {
727
- base,
728
- enableCache,
729
- isNonStatic
730
- } = this.configure(options);
731
- let path$1 = path.resolve(file);
732
- delete require.cache[path$1];
733
- const ReactDOM = requireEngine("react-dom/server", "ReactDOM");
734
-
735
- const Code = require(path$1);
736
-
737
- const Factory = this.engine.createFactory(Code);
738
- return () => {
739
- const parsed = new Factory(options);
740
- const content = isNonStatic ? ReactDOM.renderToString(parsed) : ReactDOM.renderToStaticMarkup(parsed);
741
-
742
- if (base) {
743
- options.content = content;
744
- return this.renderWithBase(file, base, enableCache, options);
745
- }
746
-
747
- return content;
748
- };
749
- }
750
-
751
- renderWithBase(key, base, enableCache, options) {
752
- const baseStr = getFromCache(key) || fs$1.readFileSync(path.resolve(base), "utf8");
753
-
754
- if (enableCache) {
755
- setToCache(key, baseStr);
756
- }
757
-
758
- return this.reactBaseTmpl(baseStr, options);
759
- }
760
-
761
- transformFileSync(filename) {
762
- try {
763
- const babel = requireEngine("@babel/core", "babel");
764
- return babel.transformFileSync(filename, {
765
- presets: ["@babel/preset-react"]
766
- }).code;
767
- } catch (err) {
768
- const babel = requireEngine("babel-core", "babel");
769
- return babel.transformFileSync(filename, {
770
- presets: ["react"]
771
- }).code;
772
- }
773
- }
774
-
775
- transform(src) {
776
- try {
777
- const babel = requireEngine("@babel/core", "babel");
778
- return babel.transform(src, {
779
- presets: ["@babel/preset-react"]
780
- }).code;
781
- } catch (err) {
782
- const babel = requireEngine("babel-core", "babel");
783
- return babel.transform(src, {
784
- presets: ["react"]
785
- }).code;
786
- }
787
- }
788
-
789
- requireReact(module, filename) {
790
- const compiled = this.transformFileSync(filename);
791
- return module._compile(compiled, filename);
792
- }
793
-
794
- requireReactString(src, filename) {
795
- if (!filename) filename = ""; // @ts-ignore
796
-
797
- const m = new module.constructor();
798
- filename = filename || ""; // Compile Using React
799
-
800
- const compiled = this.transform(src); // Compile as a module
801
-
802
- m.paths = module.paths;
803
-
804
- m._compile(compiled, filename);
805
-
806
- return m.exports;
807
- }
808
-
809
- reactBaseTmpl(data, options) {
810
- let exp;
811
- let regex; // Iterates through the keys in file object
812
- // and interpolate / replace {{key}} with it's value
813
-
814
- for (const k in options) {
815
- if (options.hasOwnProperty(k)) {
816
- exp = `{{${k}}}`;
817
- regex = new RegExp(exp, "g");
818
-
819
- if (data.match(regex)) {
820
- data = data.replace(regex, options[k]);
821
- }
822
- }
823
- }
824
-
825
- return data;
826
- }
827
-
828
- };
829
- exports.ReactEngine = tslib.__decorate([ViewEngine("react", {
830
- requires: ["react"]
831
- }), tslib.__metadata("design:paramtypes", [String, Object])], exports.ReactEngine);
832
-
833
- exports.SlmEngine = class SlmEngine extends Engine {};
834
- exports.SlmEngine = tslib.__decorate([ViewEngine("slm")], exports.SlmEngine);
835
-
836
- exports.SquirrellyEngine = class SquirrellyEngine extends Engine {
837
- $compile(template, options) {
838
- for (const partial in options.partials) {
839
- this.engine.definePartial(partial, options.partials[partial]);
840
- }
841
-
842
- for (const helper in options.helpers) {
843
- this.engine.defineHelper(helper, options.helpers[helper]);
844
- }
845
-
846
- const compile = this.engine.Compile(template, options);
847
- return options => compile(options, this.engine);
848
- }
849
-
850
- };
851
- exports.SquirrellyEngine = tslib.__decorate([ViewEngine("squirrelly")], exports.SquirrellyEngine);
852
-
853
- exports.SwigEngine = class SwigEngine extends Engine {
854
- $compile(template, options) {
855
- if (options.cache === true) options.cache = "memory";
856
- this.engine.setDefaults({
857
- cache: options.cache
858
- });
859
- return this.engine.compile(template, options);
860
- }
861
-
862
- };
863
- exports.SwigEngine = tslib.__decorate([ViewEngine("swig", {
864
- requires: ["swig", "swig-templates"]
865
- })], exports.SwigEngine);
866
-
867
- exports.TemplayedEngine = class TemplayedEngine extends Engine {
868
- $compile(template, options) {
869
- return this.engine(template);
870
- }
871
-
872
- };
873
- exports.TemplayedEngine = tslib.__decorate([ViewEngine("templayed")], exports.TemplayedEngine);
874
-
875
- exports.ToffeeEngine = class ToffeeEngine extends Engine {
876
- $compile(template, options) {
877
- const compile = util.promisify(this.engine.str_render.bind(this.engine));
878
- return options => compile(template, options);
879
- }
880
-
881
- async $compileFile(file, options) {
882
- const compile = util.promisify(this.engine.__consolidate_engine_render.bind(this.engine));
883
- return options => compile(file, options);
884
- }
885
-
886
- };
887
- exports.ToffeeEngine = tslib.__decorate([ViewEngine("toffee")], exports.ToffeeEngine);
888
-
889
- exports.TwingEngine = class TwingEngine extends Engine {
890
- $compile(template, options) {
891
- const engine = this.engine;
892
-
893
- if (!this.instance) {
894
- let loader = new engine.TwingLoaderNull();
895
-
896
- if (options.settings && options.settings.views && fs$1.existsSync(options.settings.views)) {
897
- loader = new engine.TwingLoaderFilesystem(options.settings.views);
898
- }
899
-
900
- this.instance = new engine.TwingEnvironment(loader);
901
- }
902
-
903
- const $cmp = this.instance.createTemplate(template);
904
- return async options => {
905
- const compile = await $cmp;
906
- return compile.render(options);
907
- };
908
- }
909
-
910
- };
911
- exports.TwingEngine = tslib.__decorate([ViewEngine("twing")], exports.TwingEngine);
912
-
913
- exports.TwigEngine = class TwigEngine extends Engine {
914
- $cacheOptions(template, options) {
915
- return _extends({}, options, {
916
- data: template,
917
- allowInlineIncludes: options.allowInlineIncludes,
918
- namespaces: options.namespaces,
919
- path: options.path
920
- });
921
- }
922
-
923
- $compile(template, options) {
924
- const {
925
- twig: engine
926
- } = this.engine;
927
- options.data = template;
928
- const compile = engine(options);
929
- return options => compile.render(options);
930
- }
931
-
932
- };
933
- exports.TwigEngine = tslib.__decorate([ViewEngine("twig")], exports.TwigEngine);
934
-
935
- exports.UnderscoreEngine = class UnderscoreEngine extends Engine {
936
- async render(template, options) {
937
- const tpl = await this.compile(template, options)(options);
938
- return tpl.replace(/\n$/, "");
939
- }
940
-
941
- $cacheOptions(template, options) {
942
- const partials = {};
943
-
944
- for (const partial in options.partials) {
945
- partials[partial] = this.engine.template(options.partials[partial]);
946
- }
947
-
948
- options.partials = partials;
949
- return options;
950
- }
951
-
952
- $compile(template, options) {
953
- return this.engine.template(template, null, options);
954
- }
955
-
956
- };
957
- exports.UnderscoreEngine = tslib.__decorate([ViewEngine("underscore")], exports.UnderscoreEngine);
958
-
959
- exports.VashEngine = class VashEngine extends Engine {
960
- compile(template, options) {
961
- if (options.helpers) {
962
- for (const key in options.helpers) {
963
- if (!options.helpers.hasOwnProperty(key) || typeof options.helpers[key] !== "function") {
964
- continue;
965
- }
966
-
967
- this.engine.helpers[key] = options.helpers[key];
968
- }
969
- }
970
-
971
- const compile = util.promisify(this.engine.compile(template, options));
972
- return async options => {
973
- const ctx = await compile(options);
974
- ctx.finishLayout();
975
- return ctx.toString();
976
- };
977
- }
978
-
979
- async render(template, options) {
980
- const compile = this.compile(template, options);
981
- const tpl = await compile(options);
982
- return tpl.replace(/\n$/, "");
983
- }
984
-
985
- };
986
- exports.VashEngine = tslib.__decorate([ViewEngine("vash")], exports.VashEngine);
987
-
988
- exports.VelocityEngine = class VelocityEngine extends Engine {
989
- $compile(template, options) {
990
- return async options => {
991
- return this.engine.render(template, options).trimLeft();
992
- };
993
- }
994
-
995
- };
996
- exports.VelocityEngine = tslib.__decorate([ViewEngine("velocityjs")], exports.VelocityEngine);
997
-
998
- var _renderToString;
999
-
1000
- function requireFromString(src, filename) {
1001
- const Module = module.constructor;
1002
- const m = new Module();
1003
-
1004
- m._compile(src, filename);
1005
-
1006
- return m.exports;
1007
- }
1008
- /**
1009
- * simple hash a string
1010
- * https://stackoverflow.com/a/34842797/493756
1011
- */
1012
-
1013
-
1014
- function hashCode(str) {
1015
- return str.split("").reduce((prevHash, currVal) => (prevHash << 5) - prevHash + currVal.charCodeAt(0), 0);
1016
- }
1017
-
1018
- exports.VueEngine = (_renderToString = /*#__PURE__*/_classPrivateFieldLooseKey("renderToString"), class VueEngine extends Engine {
1019
- constructor(name, options) {
1020
- super(name, options);
1021
- Object.defineProperty(this, _renderToString, {
1022
- writable: true,
1023
- value: void 0
1024
- });
1025
- const ssrRenderer = this.vueServerRenderer.createRenderer();
1026
- _classPrivateFieldLooseBase(this, _renderToString)[_renderToString] = util.promisify(ssrRenderer.renderToString.bind(this));
1027
- requireEngine("vue-pronto/lib/index", "pronto");
1028
- }
1029
-
1030
- get pronto() {
1031
- return requireEngine("pronto");
1032
- }
1033
-
1034
- get vueify() {
1035
- return requireEngine("vueify");
1036
- }
1037
-
1038
- get vueServerRenderer() {
1039
- return requireEngine("vue-server-renderer");
1040
- }
1041
-
1042
- $cacheOptions(template, options, fromFile) {
1043
- const fullPath = path.join(__dirname, `/${hashCode(template)}`);
1044
-
1045
- if (!fromFile) {
1046
- return _extends({}, options, {
1047
- filename: fullPath
1048
- });
1049
- }
1050
-
1051
- return options;
1052
- }
1053
-
1054
- $compile(template, options) {
1055
- // make up a fake path
1056
- const fullPath = path.join(__dirname, `/${hashCode(template)}`);
1057
- const promise = this.getComponent(fullPath, template, options);
1058
- return async options => {
1059
- return this.renderComponent(await promise, options);
1060
- };
1061
- }
1062
-
1063
- async $compileFile(file, options) {
1064
- // prontoRenderer assume that the filepath is relative to a passed "rootpath"
1065
- // and if you don't pass a rootpath it will try to find one
1066
- // based on its current __dirname
1067
- // https://github.com/express-vue/vue-pronto/blob/c88e380fee8656bc3ed21c7d3adb2ef331be07d5/lib/utils/findPaths.js#L10-L18
1068
- const fullPath = path.resolve(file);
1069
- const rootPath = process.cwd();
1070
- const filepath = fullPath.replace(`${rootPath}/`, "");
1071
- const prontoOptions = {
1072
- rootPath,
1073
- vueVersion: {
1074
- disabled: true
1075
- }
1076
- };
1077
-
1078
- if (!options.cache) {
1079
- // disable pronto lru cache
1080
- prontoOptions.cacheOptions = {
1081
- max: 0
1082
- };
1083
- }
1084
-
1085
- let prontoRenderer = new this.pronto.ProntoVueify(prontoOptions);
1086
-
1087
- if (!options.cache) {
1088
- // disable pronto internal cache
1089
- // yup
1090
- prontoRenderer.internalCache = {
1091
- get: () => {},
1092
- set: () => {}
1093
- };
1094
- } else {
1095
- // so, this ties each "renderer" to a rootPath
1096
- // so I have to create a new prontoRenderer each time
1097
- // which sucks! because I loose the internal cache of it,
1098
- // unless, I keep tabs on both lru and internal caches and replace them every time.
1099
- const internalCache = prontoRenderer.internalCache;
1100
- prontoRenderer.internalCache = {
1101
- get: internalCache.get.bind(internalCache),
1102
-
1103
- set(filename, component) {
1104
- internalCache.set(filename, _extends({}, component, {
1105
- data: component.data || (() => options)
1106
- }));
1107
- }
1108
-
1109
- };
1110
- }
1111
-
1112
- return options => {
1113
- return prontoRenderer.RenderToString(filepath, {}, {
1114
- propsData: options
1115
- });
1116
- };
1117
- }
1118
-
1119
- async getComponent(fullPath, template, options) {
1120
- // assume that the str the content of a <template> ... </template>
1121
- if (/<template/.test(template.trim())) {
1122
- // assume that the str is a fileContent of a .vue file
1123
- const compile = util.promisify(this.vueify.compiler.compile.bind(this.vueify.compiler));
1124
- const cmp = await compile(template, fullPath);
1125
- return requireFromString(cmp, fullPath);
1126
- }
1127
-
1128
- return {
1129
- template,
1130
-
1131
- data() {
1132
- return options;
1133
- }
1134
-
1135
- };
1136
- }
1137
-
1138
- async renderComponent(Component, options) {
1139
- let Factory = this.engine.extend(Component);
1140
- let instance = new Factory({
1141
- propsData: options
1142
- });
1143
- return _classPrivateFieldLooseBase(this, _renderToString)[_renderToString](instance);
1144
- }
1145
-
1146
- });
1147
- exports.VueEngine = tslib.__decorate([ViewEngine("vue", {
1148
- requires: "vue"
1149
- }), tslib.__metadata("design:paramtypes", [String, Object])], exports.VueEngine);
1150
-
1151
- exports.WalrusEngine = class WalrusEngine extends Engine {
1152
- $compile(template, options) {
1153
- const compile = this.engine.parse(template);
1154
- return options => compile.compile(options);
1155
- }
1156
-
1157
- };
1158
- exports.WalrusEngine = tslib.__decorate([ViewEngine("walrus")], exports.WalrusEngine);
1159
-
1160
- const callbackify = async (fn, cb) => {
1161
- try {
1162
- const html = await fn();
1163
- cb && cb(null, html);
1164
- return html;
1165
- } catch (er) {
1166
- if (cb) {
1167
- cb(er);
1168
- } else {
1169
- throw er;
1170
- }
1171
- }
1172
- };
1173
-
1174
- function getEngine(name) {
1175
- const cb = async (path, options, cb) => {
1176
- return callbackify(() => engines.get(name).renderFile(path, options), cb);
1177
- };
1178
-
1179
- cb.render = async (template, options, cb) => {
1180
- return callbackify(() => engines.get(name).render(template, options), cb);
1181
- };
1182
-
1183
- return cb;
1184
- }
1185
- let localEngines;
1186
- function getEngines() {
1187
- localEngines = localEngines || engines.getSupportedEngines().reduce((acc, key) => {
1188
- return _extends({}, acc, {
1189
- [key]: getEngine(key)
1190
- });
1191
- }, {});
1192
- return localEngines;
1193
- }
1194
-
1195
- exports.Engine = Engine;
1196
- exports.EnginesContainer = EnginesContainer;
1197
- exports.ViewEngine = ViewEngine;
1198
- exports.cache = cache;
1199
- exports.clearCache = clearCache;
1200
- exports.engines = engines;
1201
- exports.extend = extend;
1202
- exports.getEngine = getEngine;
1203
- exports.getEngines = getEngines;
1204
- exports.getFromCache = getFromCache;
1205
- exports.read = read;
1206
- exports.readPartials = readPartials;
1207
- exports.requireEngine = requireEngine;
1208
- exports.requires = requires;
1209
- exports.setRequireEngine = setRequireEngine;
1210
- exports.setToCache = setToCache;
1211
- //# sourceMappingURL=index.js.map