estilo
Version:
Create color schemes for Vim, NeoVim, Airline and Lightline
136 lines (135 loc) • 4.37 kB
JavaScript
import { Cacher } from "./storage.js";
import { compile } from "./compile.js";
import { compileBody, compileToString } from "./compile-string.js";
import { defaultConfig } from "./config.js";
import { parse } from "./parse.js";
import { render, renderAsync, renderString, renderStringAsync, } from "./render.js";
import { EtaError, RuntimeErr } from "./err.js";
/* END TYPES */
export class Eta {
constructor(customConfig) {
Object.defineProperty(this, "config", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "RuntimeErr", {
enumerable: true,
configurable: true,
writable: true,
value: RuntimeErr
});
Object.defineProperty(this, "compile", {
enumerable: true,
configurable: true,
writable: true,
value: compile
});
Object.defineProperty(this, "compileToString", {
enumerable: true,
configurable: true,
writable: true,
value: compileToString
});
Object.defineProperty(this, "compileBody", {
enumerable: true,
configurable: true,
writable: true,
value: compileBody
});
Object.defineProperty(this, "parse", {
enumerable: true,
configurable: true,
writable: true,
value: parse
});
Object.defineProperty(this, "render", {
enumerable: true,
configurable: true,
writable: true,
value: render
});
Object.defineProperty(this, "renderAsync", {
enumerable: true,
configurable: true,
writable: true,
value: renderAsync
});
Object.defineProperty(this, "renderString", {
enumerable: true,
configurable: true,
writable: true,
value: renderString
});
Object.defineProperty(this, "renderStringAsync", {
enumerable: true,
configurable: true,
writable: true,
value: renderStringAsync
});
Object.defineProperty(this, "filepathCache", {
enumerable: true,
configurable: true,
writable: true,
value: {}
});
Object.defineProperty(this, "templatesSync", {
enumerable: true,
configurable: true,
writable: true,
value: new Cacher({})
});
Object.defineProperty(this, "templatesAsync", {
enumerable: true,
configurable: true,
writable: true,
value: new Cacher({})
});
// resolvePath takes a relative path from the "views" directory
Object.defineProperty(this, "resolvePath", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
Object.defineProperty(this, "readFile", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
if (customConfig) {
this.config = { ...defaultConfig, ...customConfig };
}
else {
this.config = { ...defaultConfig };
}
}
// METHODS
configure(customConfig) {
this.config = { ...this.config, ...customConfig };
}
withConfig(customConfig) {
return { ...this, config: { ...this.config, ...customConfig } };
}
loadTemplate(name, template, // template string or template function
options) {
if (typeof template === "string") {
const templates = options && options.async
? this.templatesAsync
: this.templatesSync;
templates.define(name, this.compile(template, options));
}
else {
let templates = this.templatesSync;
if (template.constructor.name === "AsyncFunction" ||
(options && options.async)) {
templates = this.templatesAsync;
}
templates.define(name, template);
}
}
}
// for instance checking against thrown errors
export { EtaError };