本文整理汇总了TypeScript中ejs.TemplateFunction类的典型用法代码示例。如果您正苦于以下问题:TypeScript TemplateFunction类的具体用法?TypeScript TemplateFunction怎么用?TypeScript TemplateFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplateFunction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generate
public generate(
nschema: NSchemaInterface,
nsconfig: NineSchemaConfig,
template: TemplateFunction,
target: Target
) {
const config: FSharpConfig = nsconfig as FSharpConfig;
config.$nschema = nschema;
config.$fsharp = this;
config.$target = target;
const result = template(config);
const location = target.location;
const filepath =
location.indexOf(".") === 0
? path.resolve(
process.cwd(),
location,
config.namespace || "",
target.$fileName || `${config.name}.fs`
)
: path.resolve(
location,
config.namespace || "",
config.$fileName || `${config.name}.fs`
);
console.log(`fsharp: writing to file: ${filepath}`);
return nschema.writeFile(filepath, result).then(null, err => {
console.log("error: ");
console.log(err);
});
}
示例2: generate
public generate(
nschema: NSchemaInterface,
$nsconfig: NineSchemaConfig,
template: TemplateFunction,
target: Target
) {
const nsconfig: any = $nsconfig.$u.clone($nsconfig);
const config: TypeScriptConfig = nsconfig as TypeScriptConfig;
config.$nschema = nschema;
config.$typescript = this;
config.$target = target;
if (typeof config.$skipWrite === "undefined") {
config.$skipWrite = false;
}
if (config.$context) {
throw new Error("must not have a $context variable");
}
config.$context = {
imports: {}
};
const result = template(config);
if (config.$skipWrite) {
return Promise.resolve({
config,
generated: result
});
} else {
const location = target.location;
const filepath =
location.indexOf(".") === 0
? path.resolve(
process.cwd(),
location,
config.namespace || "",
target.$fileName || `${config.name}.ts`
)
: path.resolve(
location,
config.namespace || "",
config.$fileName || `${config.name}.ts`
);
console.log(`typescript: writing to file: ${filepath}`);
return nschema.writeFile(filepath, result).then(
_ => {
return {
config,
generated: result
};
},
err => {
console.log("error: ");
console.log(err);
}
);
}
}
示例3: require
/// <reference types="node" />
import ejs = require("ejs");
import { readFileSync as read } from 'fs';
import LRU = require("lru-cache");
import { TemplateFunction, AsyncTemplateFunction, Options } from "ejs";
const fileName = 'test.ejs';
const people = ['geddy', 'neil', 'alex'];
const data = { people };
const template = '<%= people.join(", "); %>';
const options = { filename: fileName };
let result: string;
let ejsFunction: TemplateFunction;
let asyncResult: Promise<string>;
let ejsAsyncFunction: AsyncTemplateFunction;
const SimpleCallback = (err: any, html?: string) => {
if (err) {
return null;
}
return html;
};
result = ejs.render(template);
result = ejs.render(template, data);
result = ejs.render(template, data, options);
result = ejs.renderFile(fileName, SimpleCallback);
result = ejs.renderFile(fileName, data, SimpleCallback);
result = ejs.renderFile(fileName, data, options, SimpleCallback);