This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2020-07-22 13:19:23 -07:00
|
|
|
import {Template} from "./classes";
|
|
|
|
import Compressor from "./compressor";
|
|
|
|
import {templates} from "./data";
|
|
|
|
|
2020-07-24 07:26:03 -07:00
|
|
|
const templatesWithAliases = {}
|
|
|
|
for (let base in templates) {
|
|
|
|
if (templates.hasOwnProperty(base)) {
|
|
|
|
const template = templates[base];
|
|
|
|
templatesWithAliases[base] = template;
|
|
|
|
for (let alias of template.aliases) {
|
|
|
|
templatesWithAliases[alias] = template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 09:50:33 -07:00
|
|
|
export const getTemplate = (id) => {
|
|
|
|
return templatesWithAliases[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const buildTemplate = (path) => {
|
2020-07-22 13:19:23 -07:00
|
|
|
const templateStr = path.split(',');
|
2020-07-24 07:26:03 -07:00
|
|
|
const base = templatesWithAliases[templateStr[0]]
|
2020-07-22 13:19:23 -07:00
|
|
|
|
|
|
|
return templateStr.length === 1
|
2020-07-24 07:26:03 -07:00
|
|
|
? templatesWithAliases[templateStr[0]]
|
2020-07-22 13:19:23 -07:00
|
|
|
: Template.from(Compressor.uncompress(templateStr, base ? base.toArray() : null));
|
|
|
|
}
|