mirror of
https://github.com/cupcakearmy/cometa.git
synced 2025-09-05 20:40:39 +00:00
Made core static
This commit is contained in:
43
dist/cometa.js
vendored
43
dist/cometa.js
vendored
@@ -5,33 +5,30 @@ const util = require("./util");
|
||||
const parser = require("./parser");
|
||||
const compiler = require("./compiler");
|
||||
const options_1 = require("./options");
|
||||
module.exports = class {
|
||||
module.exports = class Cometa {
|
||||
constructor(opt, rexp) {
|
||||
this.options = options_1.options;
|
||||
this.expressions = options_1.re;
|
||||
this._express = this.renderFile;
|
||||
this.cache = new Map();
|
||||
this.options = Object.assign(this.options, opt);
|
||||
this.expressions = Object.assign(this.expressions, rexp);
|
||||
this.options = Object.assign(options_1.options, opt);
|
||||
this.expressions = Object.assign(options_1.re, rexp);
|
||||
if (module.parent === null)
|
||||
throw new Error('Not imported');
|
||||
this.options.views = path.join(path.dirname(module.parent.filename), this.options.views);
|
||||
}
|
||||
renderFile(file, data, callback) {
|
||||
console.log('Options', this.options);
|
||||
static exec(file, data, callback, env) {
|
||||
util.readFile(file).then(html => {
|
||||
console.log('Options', this.options);
|
||||
if (html === undefined) {
|
||||
callback(`No template found: ${file}`, '');
|
||||
return;
|
||||
}
|
||||
util.checksum(html, true).then(hash => {
|
||||
if (this.options.caching && !this.cache.get(html))
|
||||
this.cache.set(html, {
|
||||
template: compiler.process(html, this.options, this.expressions),
|
||||
if (env.options.caching && !env.cache.get(html)) {
|
||||
process.stdout.write(`Compiling: ${hash}\n`);
|
||||
env.cache.set(html, {
|
||||
template: compiler.process(html, env.options, env.expressions),
|
||||
time: Date.now()
|
||||
});
|
||||
const compiled = this.cache.get(html);
|
||||
}
|
||||
const compiled = env.cache.get(html);
|
||||
if (compiled)
|
||||
callback(null, parser.computeParts(compiled.template, data));
|
||||
else
|
||||
@@ -39,8 +36,26 @@ module.exports = class {
|
||||
});
|
||||
});
|
||||
}
|
||||
renderTemplate(template_name, data, callback) {
|
||||
render(template_name, data, callback) {
|
||||
const template_path = path.join(this.options.views, `${template_name}.${this.options.extension}`);
|
||||
this.renderFile(template_path, data, callback);
|
||||
}
|
||||
renderFile(template_path, data, callback) {
|
||||
Cometa.exec(template_path, data, callback, {
|
||||
options: this.options,
|
||||
expressions: this.expressions,
|
||||
cache: this.cache
|
||||
});
|
||||
}
|
||||
static __express(file, data, callback) {
|
||||
if (Cometa.permCache === undefined) {
|
||||
process.stdout.write('Initializing cache map\n');
|
||||
Cometa.permCache = new Map();
|
||||
}
|
||||
Cometa.exec(file, data, callback, {
|
||||
options: options_1.options,
|
||||
expressions: options_1.re,
|
||||
cache: Cometa.permCache,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user