本文整理汇总了TypeScript中mustache.render函数的典型用法代码示例。如果您正苦于以下问题:TypeScript render函数的具体用法?TypeScript render怎么用?TypeScript render使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Buffer
(issue: any, updateImpedimentsFileComplete: Function) => {
var input = new Buffer(impediments.content, "base64").toString("utf8");
var definition= this.parseImpediments(input);
var data: any = definition.issues.filter((x: any) => { return x.number == requestBody.number });
if (data.length > 0) {
data = data[0];
} else {
data = issue;
issue.impediments = [];
definition.issues.push(issue);
}
data.impediments.push({
date: moment().format(configuration.dateFormat),
comment: requestBody.body
});
self.logger.debug(definition);
var newContent = mustache.render(template, definition);
self.logger.debug(newContent);
requestBody.message = "Updated impediments";
requestBody.sha = impediments.sha;
requestBody.content = new Buffer(newContent, 'utf8').toString("base64");
self.logInfo([user, repository, number], "Uploading new impediments file");
self.getGitHubClient().repos.updateFile(requestBody, updateImpedimentsFileComplete);
}
示例2: replaceBetween
function replaceBetween(readmeContents: string, section: string, settings: IGulpSettings): string {
const fs = require("fs");
const os = require("os");
const starter = `<!-- {{${section}}} -->`;
const ender = `<!-- {{/${section}}} -->`;
const start = readmeContents.indexOf(starter) + starter.length;
const end = readmeContents.indexOf(ender);
const addingWeb: boolean = !!settings.packageSchema.shenanigans.web;
return [
readmeContents.substring(0, start),
mustache.render(
fs.readFileSync(`./node_modules/gulp-shenanigans/src/setup/readme/${section}.md`).toString().trim(),
{
...settings,
buildCommands: addingWeb
? ["gulp setup", "gulp"]
: ["gulp"],
extra: addingWeb
? "After setting up and building locally, open `src/index.html` to launch."
: ""
}),
readmeContents.substring(end)
].join(os.EOL);
}
示例3: it
it("should work with v_display", () => {
const v = { sn: "bar", givenName: "bar2" } as v;
const v_ = v_display(v, { sn: { oneOf: [ { const: "bar", title: "BAR"} ] } })
const r = mustache.render("Foo {{v_display.sn}} {{v_display.givenName}}", { v_display: v_ });
assert.equal(r, "Foo BAR bar2");
});
示例4: getNestedProperty
mongo.find(collection, JSON.parse(query), (error, data) => {
if (error) {
console.error('query failed');
return;
} else {
for (let i=0; i<data.length; i++) {
let email = getNestedProperty(data[i], email_fields),
name = getNestedProperty(data[i], name_fields);
let request = {
from: from_email,
to: email,
subject: subject,
text: content,
html: Mustache.render(html, {name: name})
};
mailer.messages().send(request, function(error, body) {
if (error) {
console.error(error);
} else {
console.log(body);
}
});
} /* END FOR */
}
}); /* END MONGO FIND */
示例5: function
fs.readFile(__dirname + '/../templates/email.mst', 'utf-8', (error, template) => {
if (error) {
console.error(error);
} else {
tmp_files.push(tmpobj);
let rendered = Mustache.render(template, {email: tmpobj.name});
$('.content').html(rendered);
storage.get('queries', function(error, queries) {
if (error) {
console.error(error);
} else {
let hound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: (q) => { return q.name; },
local: queries
});
$('input[name="query"]').typeahead({
hint: true,
minLength: 0,
highlight: true
}, {
name: 'queries',
display: 'name',
source: hound
});
}
});
}
});
示例6: generate
export function generate(viewModel?:IDataStore, config?:ReporterConfig):void {
var opts = {encoding: 'utf8'};
if (viewModel == null && config == null) {
config = new ReporterConfig();
var strData:string = fs.readFileSync(config.viewDataPath, opts);
viewModel = JSON.parse(strData);
console.log('----> Using default config & data to test report: \n', config);
}
// First lets load up all the templates
var headerStr = fs.readFileSync(config.headerTemplatePath, opts);
var indexStr = fs.readFileSync(config.indexTemplatePath, opts);
var suiteStr = fs.readFileSync(config.suiteTemplatePath, opts);
var titleStr = fs.readFileSync(config.titleTemplatePath, opts);
var summaryStr = fs.readFileSync(config.summaryTemplatePath, opts);
var latestStr = fs.readFileSync(config.latestTemplatePath, opts);
// Lets convert the scss into CSS
var stylesStr = sass.renderSync({
file : config.stylesPath,
outputStyle: 'expanded',
indentWidth: 4
}).css.toString();
// Now lets build up the templates to pass
var partials = {header: headerStr, title: titleStr, suite: suiteStr, summary: summaryStr};
// Now the model
_.extend(viewModel, {
styles: stylesStr,
title : config.reportName,
env : process.env
});
// Render with mustache
var reportResult = mustache.render(indexStr, viewModel, partials);
var latestResult = mustache.render(latestStr, {latestReportName: config.latestReportName});
// Write out the report
if (!fs.existsSync(config.reportDir)) {
fs.mkdirSync(config.reportDir);
}
if (config.reportDynamicPath) fs.writeFileSync(config.reportDynamicPath, reportResult, opts);
fs.writeFileSync(config.reportStaticPath, reportResult, opts);
fs.writeFileSync(config.reportDir + '/latest.html', latestResult, opts);
}
示例7: renderTemplate
export function renderTemplate(template: string, context: any): string {
let i = 0
while (i < MAX_NESTING_LEVEL && containsTemplate(template)) {
template = Mustache.render(template, context)
i++
}
return template
}
示例8: catch
const result = _.mapValues(template, (t) => {
try {
return Mustache.render(t, data);
} catch (e) {
log.error('Could not apply data to template', e);
error = e;
}
});
示例9: function
storage.get('templates', function(error, templates) {
if (error) {
console.error(error);
} else {
let rendered = Mustache.render(template, {templates: templates});
$('.content').html(rendered);
}
});