-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (73 loc) · 1.7 KB
/
index.js
File metadata and controls
82 lines (73 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const path = require("path");
const schemaUtils = require("schema-utils");
const schema = {
type: "object",
properties: {
memo: {
type: "boolean",
},
autoBody: {
anyOf: [
{
type: "boolean",
},
{
type: "object",
properties: {
formData: { type: "boolean" },
},
additionalProperties: false,
},
],
},
allowedContentTypes: {
anyOf: [
{
type: "array",
items: { type: "string" },
},
{
type: "string",
enum: ["*"],
},
],
},
sanitize: {
type: "boolean",
},
disallowedTags: {
type: "array",
items: {
enum: ["script", "style", "iframe"],
},
},
sanitizeConfig: {
type: "object",
additionalProperties: true,
},
},
additionalProperties: false,
};
module.exports = function (source) {
if (this.cacheable) this.cacheable();
if (typeof source !== "string")
throw Error(
"Template was not found or the type of the passed value is not string"
);
const modulePath = JSON.stringify(
path.join("hmpl-js", "dist", "hmpl.runtime")
);
const result = [];
const template = JSON.stringify(source);
const options = this.getOptions();
schemaUtils.validate(schema, options, {
name: "hmpl-loader",
baseDataPath: "options",
});
const stringOptions = JSON.stringify(options);
result.push(`const hmpl = require(${modulePath});\n`);
result.push(`const template = hmpl.compile(${template},${stringOptions});\n`);
result.push(`module.exports = template;`);
return result.join("");
};
module.exports.seperable = true;