MCPcopy
hub / github.com/FoalTS/foal / render

Function render

packages/core/src/core/templates/render.ts:39–60  ·  view source on GitHub ↗
(templatePath: string, locals: object = {}, dirname?: string)

Source from the content-addressed store, hash-verified

37 * @returns {Promise<HttpResponseOK>}
38 */
39export async function render(templatePath: string, locals: object = {}, dirname?: string): Promise<HttpResponseOK> {
40 const path = dirname ? join(dirname, templatePath) : templatePath;
41 const template = await readFile(path, 'utf8');
42
43 const templateEngine = Config.get('settings.templateEngine', 'string');
44 if (templateEngine) {
45 const { __express } = require(templateEngine);
46 if (__express) {
47 return new Promise<HttpResponseOK>((resolve, reject) => {
48 __express(path, locals, (err: any, html: string) => {
49 if (err) {
50 return reject(err);
51 }
52 resolve(new HttpResponseOK(html));
53 });
54 });
55 }
56 throw new Error(`${templateEngine} is not a template engine compatible with FoalTS.`);
57 }
58
59 return new HttpResponseOK(renderToString(template, locals));
60}

Callers 10

render.spec.tsFile · 0.90
loginMethod · 0.90
indexMethod · 0.90
renderAppMethod · 0.90
indexMethod · 0.90
loginMethod · 0.90
indexMethod · 0.90
indexMethod · 0.90
signinMethod · 0.90
profileMethod · 0.90

Calls 3

joinFunction · 0.85
renderToStringFunction · 0.85
getMethod · 0.65

Tested by 3

loginMethod · 0.72
indexMethod · 0.72
renderAppMethod · 0.72