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