2020-08-23 08:48:15 +00:00
|
|
|
import * as loader from "tc-loader";
|
|
|
|
import * as moment from "moment";
|
2020-09-12 13:49:20 +00:00
|
|
|
import * as log from "../log";
|
|
|
|
import {LogCategory} from "../log";
|
2020-11-29 13:42:02 +00:00
|
|
|
import { tr } from "tc-shared/i18n/localize";
|
2020-08-23 08:48:15 +00:00
|
|
|
|
|
|
|
export function setupJSRender() : boolean {
|
|
|
|
if(!$.views) {
|
|
|
|
loader.critical_error("Missing jsrender viewer extension!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.views.settings.allowCode(true);
|
|
|
|
$.views.tags("rnd", (argument) => {
|
|
|
|
let min = parseInt(argument.substr(0, argument.indexOf('~')));
|
|
|
|
let max = parseInt(argument.substr(argument.indexOf('~') + 1));
|
|
|
|
|
|
|
|
return (Math.round(Math.random() * (min + max + 1) - min)).toString();
|
|
|
|
});
|
|
|
|
|
|
|
|
$.views.tags("fmt_date", (...args) => {
|
|
|
|
return moment(args[0]).format(args[1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$.views.tags("tr", (...args) => {
|
|
|
|
return /* @tr-ignore */ tr(args[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".jsrender-template").each((idx, _entry) => {
|
|
|
|
if(!$.templates(_entry.id, _entry.innerHTML)) {
|
|
|
|
log.error(LogCategory.GENERAL, tr("Failed to setup cache for js renderer template %s!"), _entry.id);
|
|
|
|
} else
|
|
|
|
log.trace(LogCategory.GENERAL, tr("Successfully loaded jsrender template %s"), _entry.id);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|