-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdirectory-loader.js
More file actions
41 lines (31 loc) · 891 Bytes
/
Copy pathdirectory-loader.js
File metadata and controls
41 lines (31 loc) · 891 Bytes
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
"use strict";
const fs = require("fs");
const path = require("path");
const parser = require("./parser");
const razorleaf = require("./");
class DirectoryLoader {
constructor(root, options) {
const load = name =>
parser.parse(this.read(name), { ...razorleaf.defaults, load, name, ...this.options });
this.root = root;
this.options = { load, ...options };
}
read(name) {
return fs.readFileSync(path.join(this.root, name + ".rl"), "utf8");
}
load(name, loadOptions) {
const options = { ...this.options, name };
if (loadOptions) {
if ("globals" in loadOptions) {
options.globals = { ...options.globals, ...loadOptions.globals };
}
for (const option in loadOptions) {
if (option !== "globals") {
options[option] = loadOptions[option];
}
}
}
return razorleaf.compile(this.read(name), options);
}
}
module.exports = DirectoryLoader;