##// END OF EJS Templates
wip migrating on new typescript build plugin
wip migrating on new typescript build plugin

File last commit:

r152:8bee6a6d5f46 v1.4.0-rc10 default
r174:b00d3153045c default
Show More
template-compile.ts
56 lines | 1.6 KiB | video/mp2t | TypeScriptLexer
/ src / amd / ts / text / template-compile.ts
cin
text/template-compile ported to typescript
r56 import request = require("dojo/request");
import m = require("module");
import { TraceSource } from "../log/TraceSource";
import { TemplateCompiler } from "./TemplateCompiler";
import { TemplateParser } from "./TemplateParser";
import { isNullOrEmptyString } from "../safe";
import { MapOf } from "../interfaces";
type TemplateFn = (obj: object) => string;
const trace = TraceSource.get(m.id);
function compile(str: string) {
if (isNullOrEmptyString(str))
return () => "";
const parser = new TemplateParser(str);
const compiler = new TemplateCompiler();
return compiler.compile(parser);
}
const cache: MapOf<TemplateFn> = {};
interface OnLoadFn<T> {
(res: T): void;
error(e: any): void;
}
compile.load = (id: string, require: Require, callback: OnLoadFn<TemplateFn>) => {
const url = require.toUrl(id);
if (url in cache) {
trace.debug("{0} -> {1}: cached", id, url);
callback(cache[url]);
} else {
trace.debug("{0} -> {1}: load", id, url);
cin
corrected code to support ts strict mode...
r115 request<string>(url).then(compile).then((tc: TemplateFn) => {
cin
text/template-compile ported to typescript
r56 trace.debug("{0}: compiled", url);
callback(cache[url] = tc);
}, (err: any) => {
cin
fixed bug in applying a lifetime while processing the json configuration...
r152 if (callback.error)
callback.error({
inner: err,
from: "@implab/core/text/template-compile"
});
else
trace.error({
message: `Failed to load: ${url}`,
error: err,
from: "@implab/core/text/template-compile"
});
cin
text/template-compile ported to typescript
r56 });
}
};
export = compile;