本文整理汇总了TypeScript中ejs.render函数的典型用法代码示例。如果您正苦于以下问题:TypeScript render函数的具体用法?TypeScript render怎么用?TypeScript render使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: initProjectFile
function initProjectFile() {
// generator app.json
const appJsonObject = Object.assign({
name: _.camelCase(require(path.join(process.cwd(), 'package.json')).name)
}, rnConfig.appJson)
// generator .${tempPath}/package.json TODO JSON.parse 这种写法可能会有隐患
const pkgTempObj = JSON.parse(
ejs.render(pkgTmpl, {
projectName: _.camelCase(projectConfig.projectName),
version: Util.getPkgVersion()
}
).replace(/(\r\n|\n|\r|\s+)/gm, '')
)
const dependencies = require(path.join(process.cwd(), 'package.json')).dependencies
pkgTempObj.dependencies = Object.assign({}, pkgTempObj.dependencies, dependencies)
const indexJsStr = `
import {AppRegistry} from 'react-native';
import App from './${entryBaseName}';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);`
fs.writeFileSync(path.join(tempDir, 'index.js'), indexJsStr)
Util.printLog(processTypeEnum.GENERATE, 'index.js', path.join(tempPath, 'index.js'))
fs.writeFileSync(path.join(tempDir, 'app.json'), JSON.stringify(appJsonObject, null, 2))
Util.printLog(processTypeEnum.GENERATE, 'app.json', path.join(tempPath, 'app.json'))
fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify(pkgTempObj, null, 2))
Util.printLog(processTypeEnum.GENERATE, 'package.json', path.join(tempPath, 'package.json'))
}
示例2: run
public static async run(context, callback, errorcallback) {
var page = context.page;
if (!context.page) {
page = new Page(context);
context.page = page;
}
//attach a new parser instance to the page
page.parser = new Parser(context);
debug('runner run');
await page.run();
debug('run');
page.fileContent = ejs.render(page.fileContent, page);
page.fileContent = decodeURI(page.fileContent);
// try {
page.parser.buildTree(page);
// page.parser.parsePlaceHolders(page, function () {
let childrenResult = await Runner.runChildren(context, page.controls);
var result = Renderer.render(page);
page.fileContent = result;
if (page.masterpage) {
let masterResult = await page.masterpage.run();
page.parser.buildTree(page.masterpage);
childrenResult = await Runner.runChildren(context, page.masterpage.controls);
masterResult = await Renderer.render(page.masterpage);
page.masterpage.fileContent = ejs.render(page.masterpage.fileContent, page.masterpage);
page.parser = new Parser(context);
page.parser.parsePlaceHolders(page.masterpage);
}
return page.fileContent;
}
示例3: compile
export async function compile(cwd: string, config: IConfig): Promise<IUploadEntity[]> {
const sourceRootPath = join(cwd, config.in || "")
const targetPath = config.out || "./build"
if (!sourceRootPath || !targetPath) throw new Error("Incorrect configuration")
const indexList: any[] = []
const filesToUpload: any[] = []
const test = ignore((await readFile(join(sourceRootPath, ".blogignore"), "utf-8")))
let template
try {
template = await readFile(join(sourceRootPath, "index.ejs"), "utf-8")
} catch (error) {
console.log("Using default template...")
}
console.log("Collecting files to upload...")
await traverse(
sourceRootPath,
targetPath,
writeFiles.bind(null, indexList, test, add, template),
)
const posts = indexList
.filter(({ published, private: priv }) => published && !priv)
const md: string = posts
.map(({ permalink, title }: IPost) => `- [${title}](${permalink})`)
.join("\n")
const blog = remarkable.render(md)
const html = ejs.render(template || defaultTemplate, { blog, frontmatter: null })
add("md", md, join(targetPath, "index.md"))
add("html", html, join(targetPath, "index.html"))
add("json", JSON.stringify(posts), join(targetPath, "index.json"))
console.log("Done Collecting Files")
return filesToUpload
function add(type: string, content: any, path: string): void {
if (content && content.data) {
filesToUpload.push({ content: content.data, metadata: content.info, path, type })
} else {
filesToUpload.push({ content, path, type })
}
}
}
示例4: require
compiler.plugin('emit', (compilation, done) => {
const header = require(path.join(root, 'resource', this.translator + '.json'))
header.lastUpdated = (new Date).toISOString().replace('T', ' ').replace(/\..*/, '')
const preferences = require(path.join(root, 'gen/preferences.json'))
const asset = this.translator + '.js'
compilation.assets[asset] = new ConcatSource(
ejs.render(
fs.readFileSync(path.join(__dirname, 'translator-header.ejs'), 'utf8'),
{preferences, header, version}
),
compilation.assets[asset]
)
done()
})
示例5: stringify
compiler.hooks.emit.tap('TranslatorHeaderPlugin', compilation => {
const asset = this.translator + '.js'
const header = JSON.parse(JSON.stringify(translators.byName[this.translator]))
const headerCode = ejs.render(
fs.readFileSync(path.join(__dirname, 'translator-header.ejs'), 'utf8'),
{preferences, header, version}
)
delete header.description
header.configOptions = header.configOptions || {}
// header.configOptions.hash = crypto.createHash('md5').update(headerCode + compilation.assets[asset].source()).digest('hex')
// header.configOptions.hash = [crypto.createHash('md5').update(headerCode).digest('hex')].concat(compilation.chunks.map(chunk => chunk.hash)).join('-')
header.configOptions.hash = [headerCode, compilation.assets[asset].source()].map(hash).join('-')
// because Zotero doesn't allow headers that have a object at the last key, so put lastUpdated at the end as a safeguard
const header_order = [
'translatorID',
'translatorType',
'label',
'creator',
'target',
'minVersion',
'maxVersion',
'priority',
'inRepository',
'configOptions',
'displayOptions',
'exportCharset',
'exportNotes',
'exportFileData',
'useJournalAbbreviation',
]
const json_header = stringify(header, {
space: 2,
cmp: (a, b) => {
// lastUpdated always at the end
if (a.key === 'lastUpdated') return 1
if (b.key === 'lastUpdated') return -1
a.pos = (header_order.indexOf(a.key) + 1) || header_order.length + 1
b.pos = (header_order.indexOf(b.key) + 1) || header_order.length + 1
if (a.pos !== b.pos) return a.pos - b.pos
return a.key.localeCompare(b.key) // can only happen if they're both not in the order
},
}) + '\n\n'
compilation.assets[asset] = new ConcatSource(json_header + headerCode, compilation.assets[asset])
})
示例6: createMarkdownOutput
export async function createMarkdownOutput(
text: string,
template?: string,
): Promise<[ IPost | null, string, string ]> {
const parsed = /(?:^---\n)([\s\S]*)(?:---\n)(([\s\S])*)/gm.exec(text) || []
const hasFrontmatter = parsed.length
const md = (hasFrontmatter ? parsed[2] : text)
.replace(/\.jpeg/g, ".large.jpeg")
.replace(/\.jpg/g, ".large.jpg")
.replace(/\.png/g, ".large.png")
.replace(/\]\(\.\.\//g, "](../../")
const blog = remarkable.render(md)
if (!hasFrontmatter) {
const html = ejs.render(template || defaultTemplate, { blog, frontmatter: null })
return [ null, md, html ]
}
const frontmatter = load(parsed[1])
const html = ejs.render(template || defaultTemplate, { blog, frontmatter })
return [ frontmatter, md, html ]
}
示例7: runScript
public static async runScript(control) {
if (control.type.script !== undefined && control.type.script.init !== undefined) {
var controlContext = { attributes: control.attributes, data: control.data, control: control };
debug("run script");
controlContext = await control.type.script.init(control.context, controlContext);
control.renderResult = ejs.render(control.type.template, controlContext);
return;
}
else {
return;
}
//control.renderResult = ejs.render(control.type.template, control.type.script.model);
}
示例8: decodeURIComponent
app.get("/allocpage/:site", (req, res) => {
res.set('Content-Type', 'text/html');
res.send(ejs.render(getAllocPageTemplate(), { site: decodeURIComponent(req.params.site)}));
});
示例9: renderTemplate
/**
* Returns a string template with the specified template values filled in.
* Any blank lines are removed from the resulting string.
*
* @param template The template to render.
* @param data An object whose keys are used to identify the text in the
* template to replace with the value of the object's key.
* @return The template supplied with the supplied data filled in.
*/
function renderTemplate(template: string, data?: ejs.Data): string {
return ejs.render(template, data).replace(/^\s*\n/gm, '');
}
示例10: view
protected view(templateFile: string, data: any): string {
let template = fs.readFileSync(`dist/views/${templateFile}.ejs`).toString();
return ejs.render(template, data, {
filename: `dist/views/${templateFile}.ejs`
});
}