本文整理汇总了TypeScript中handlebars.compile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compile函数的具体用法?TypeScript compile怎么用?TypeScript compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: populateTemplate
private populateTemplate(mailData: Mailer): Promise<Mailer> {
let deferred = Q.defer();
mailData.message = Handlebars.compile(mailData.template.html)(mailData.templateData);
mailData.template.subject = Handlebars.compile(mailData.template.subject)(mailData.templateData);
deferred.resolve(mailData);
return deferred.promise;
}
示例2: getTemplateFunction
getTemplateFunction() {
// Template compilation
// --------------------
// This demo uses Handlebars templates to render views.
// The template is loaded with Require.JS and stored as string on
// the view prototype. On rendering, it is compiled on the
// client-side. The compiled template function replaces the string
// on the view prototype.
//
// In the end you might want to precompile the templates to JavaScript
// functions on the server-side and just load the JavaScript code.
// Several precompilers create a global JST hash which stores the
// template functions. You can get the function by the template name:
//
// templateFunc = JST[@templateName];
let template = this.template;
let templateFunction: Function;
if (typeof template === 'string') {
// Compile the template string to a function and save it
// on the prototype. This is a workaround since an instance
// shouldn't change its prototype normally.
templateFunction = Handlebars.compile(template);
this.template = templateFunction;
} else if (typeof template === 'function') {
templateFunction = template;
}
return templateFunction;
}
示例3: exportTexturePoolViaHandlebarsTemplate
function exportTexturePoolViaHandlebarsTemplate(
folderRootTo: string,
templateFolderAndFile: string,
data: any,
) {
let text = fs.readFileSync(templateFolderAndFile, 'utf8');
if (text && text.length > 0) {
text = text.replace(/\r/g, '');
const lines = text.split('\n');
if (lines.length > 1 && lines[0]) {
const resultFile = path.resolve(folderRootTo, lines[0]);
text = lines.slice(1).join('\n');
console.log(`${templateFolderAndFile} => ${resultFile}`);
const template = handlebars.compile(text);
if (template) {
fs.ensureDirSync(path.dirname(resultFile));
fs.writeFileSync(resultFile, template(data));
} else {
console.log('template error in ' + resultFile);
}
}
}
}
示例4:
Marionette.TemplateCache.prototype.compileTemplate = (rawTemplate: any): any => {
if (_.isFunction(rawTemplate)) {
return rawTemplate;
} else {
return Handlebars.compile(rawTemplate);
}
};
示例5: _compileTemplate
private _compileTemplate(templatePath: string, data: Object) {
const templateFileName = path.join(process.cwd(), templatePath);
const templateFile = fs.readFileSync(templateFileName, 'UTF-8');
const templateFunc: Function = handlebars.compile(templateFile);
return templateFunc(data);
}
示例6: getFilesFrom
.then((data) => {
const [file, pack, meta] = data;
const connectionTypes = ['mainnet', 'testnet'];
if (!param.scripts) {
const sourceFiles = getFilesFrom(join(__dirname, '../src'), '.js', function (name, path) {
return !name.includes('.spec') && !path.includes('/test/');
});
param.scripts = meta.vendors.map((i) => join(__dirname, '..', i)).concat(sourceFiles);
param.scripts.push(join(__dirname, '../loginDaemon.js'));
}
if (!param.styles) {
param.styles = meta.stylesheets.map((i) => join(__dirname, '..', i)).concat(getFilesFrom(join(__dirname, '../src'), '.less'));
}
const networks = connectionTypes.reduce((result, item) => {
result[item] = meta.configurations[item];
return result;
}, Object.create(null));
return compile(file)({
pack: pack,
domain: meta.domain,
build: {
type: 'web'
},
network: networks[param.connection]
});
})
示例7: function
handler: function(request, reply) {
let paths = getPaths(server, baseUri, filter);
let source = fs.readFileSync(__dirname + '/sitemap.xml.hbs', 'utf8');
let template = handlebars.compile(source);
reply(template({paths: paths}))
.type('application/xml');
},
示例8: subHandle
function subHandle(fullPath: string, args: any) {
wd = path.dirname(fullPath);
let tmpl = fs.readFileSync(fullPath, 'utf8');
var template = hbs.compile(tmpl.toString());
var result = template(args);
return result;
}
示例9: loadTemplate
export function loadTemplate(name: string): Template {
const template = handlebars.compile(
fs.readFileSync(__dirname + '/../templates/' + name + '.hbs', 'utf-8')
);
return template;
}
示例10: function
tmpl: function(resolver, templateString, refObj, wire) {
var template = handlebars.compile(templateString);
// get the entire wire context
wire.createChild({}).
// render the template with the context
then(template).
// resolve with the rendered template
then(resolver.resolve).
catch(resolver.reject);
}