本文整理汇总了TypeScript中handlebars.registerHelper函数的典型用法代码示例。如果您正苦于以下问题:TypeScript registerHelper函数的具体用法?TypeScript registerHelper怎么用?TypeScript registerHelper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerHelper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
/**
* Create a new MarkdownTheme instance.
*
* @param renderer The renderer this theme is attached to.
* @param basePath The base path of this theme.
*/
constructor(renderer: td.output.Renderer, basePath: string) {
super(renderer, basePath);
renderer.removePlugin('assets'); // markdown doesn't need assets
renderer.removePlugin('javascriptIndex'); // markdown doesn't need search.js
renderer.removePlugin('prettyPrint'); // new lines and spaces have meaning in markdown, don't omit them automatically!
Handlebars.registerHelper('newLine', () => '\n');
}
示例2: GetBuildIdIndex
private GetBuildIdIndex(jenkinsJobDetails: JenkinsJobDetails, startBuildId: number, endBuildId: number): Q.Promise<any> {
let defer = Q.defer<any>();
let buildUrl: string = `${jenkinsJobDetails.multiBranchPipelineUrlInfix}/api/json?tree=allBuilds[number]`;
let startIndex: number = -1;
let endIndex: number = -1;
console.log(tl.loc("FindBuildIndex"));
handlebars.registerHelper('BuildIndex', function(buildId, index, options) {
if (buildId == startBuildId) {
startIndex = index;
} else if (buildId == endBuildId) {
endIndex = index;
}
return options.fn(this);
});
let source: string = '{{#each allBuilds}}{{#BuildIndex this.number @index}}{{/BuildIndex}}{{/each}}';
let downloadHelper: JenkinsRestClient = new JenkinsRestClient();
downloadHelper.DownloadJsonContent(buildUrl, source, null).then(() => {
console.log(tl.loc("FoundBuildIndex", startIndex, endIndex));
if (startIndex === -1 || endIndex === -1) {
tl.debug(`cannot find valid startIndex ${startIndex} or endIndex ${endIndex}`);
defer.reject(tl.loc("CannotFindBuilds"));
}
else {
defer.resolve({startIndex: startIndex, endIndex: endIndex});
}
}, (error) => {
defer.reject(error);
});
return defer.promise;
}
示例3: generateServiceDefinitions
generateServiceDefinitions(api: meta.ServiceInfo) {
var moduleTemplate = this.fetchTemplate("module")
this.cleanShapes(api.descriptor);
handlebars.registerHelper("camelCase", function(name: string) {
return name.charAt(0).toLowerCase() + name.substring(1)
})
return moduleTemplate(api)
}
示例4: registerHandlebarHelpers
private registerHandlebarHelpers() {
Handlebars.registerHelper({
crmdata: (pbiType: string, group: PbiService.GroupModel = null, dashboard: PbiService.DashboardModel = null, opt: any) => {
// Note: Need to take get this and arguments using eval as the TS compiler override their values in this callback and thus can't be referenced directly.
// tslint:disable:no-eval
let that = eval("this");
let args = eval("arguments");
// tslint:enable:no-eval
return this.getCrmDataQueryForItem(
pbiType,
that,
(args.length > 2 ? group : null), // Handlebars append opt at the end - thus num args vary
(args.length > 3 ? dashboard : null) // Handlebars append opt at the end - thus num args vary
);
},
previewquery: (pbiType: string, group: PbiService.GroupModel = null, dashboard: PbiService.DashboardModel = null, opt: any) => {
// Note: Need to take get this and arguments using eval as the TS compiler override their values in this callback and thus can't be referenced directly.
// tslint:disable:no-eval
let that = eval("this");
let args = eval("arguments");
// tslint:enable:no-eval
let crmData = this.getCrmDataQueryForItem(
pbiType,
that,
(args.length > 2 ? group : null), // Handlebars append opt at the end - thus num args vary
(args.length > 3 ? dashboard : null) // Handlebars append opt at the end - thus num args vary
);
if (pbiType.toLowerCase() === "report") {
crmData += "&customFn=PbiPreviewLogVisualsFn";
}
return `data=${encodeURIComponent(crmData)}`;
}
});
}
示例5:
_.each(helpers, (val, key) => {
Handlebars.registerHelper(key, val);
});
示例6: function
//import Handlebars = require('handlebars');
import * as Handlebars from 'handlebars';
const context = {
author: { firstName: 'Alan', lastName: 'Johnson' },
body: 'I Love Handlebars',
comments: [{
author: { firstName: 'Yehuda', lastName: 'Katz' },
body: 'Me too!'
}]
};
Handlebars.registerHelper('fullName', (person: typeof context.author) => {
return person.firstName + ' ' + person.lastName;
});
Handlebars.registerHelper('agree_button', function() {
return new Handlebars.SafeString(
'<button>I agree. I ' + this.emotion + ' ' + this.name + '</button>'
);
});
const source1 = '<p>Hello, my name is {{name}}. I am from {{hometown}}. I have ' +
'{{kids.length}} kids:</p>' +
'<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>';
const template1 = Handlebars.compile(source1);
template1({ name: "Alan", hometown: "Somewhere, TX", kids: [{name: "Jimmy", age: 12}, {name: "Sally", age: 4}]});
Handlebars.registerHelper('link_to', (context: typeof post) => {
return '<a href="' + context.url + '">' + context.body + '</a>';
});
示例7: function
* Usage:
*
* {{include 'filename.tpl.md' context=obj noeval=true}}
*
* Includes another file. You can optionally pass a context named parameter to change the context.
* The file will receive the data from the context as variables.
*
* The noeval argument will disable evaluation of the file as a handlebars template - it will be
* included verbatim.
*
*/
hbs.registerHelper('include', function(this: any, file, opts: hbs.HelperOptions) {
let ctx = null == opts.hash['context'] ? this : opts.hash['context'];
let noeval = null != opts.hash['noeval'];
let target = path.resolve(wd, file);
let oldwd = wd;
wd = path.dirname(target);
let res = noeval ? fs.readFileSync(target) : subHandle(target, ctx);
wd = oldwd;
return res;
});
/**
* ## filetree
*
* Usage:
*
* {{filetree relativePath padding}}
*
* * relativePath - the path of the directory relative to current file
* * padding - how much to pad each item in the tree except the first one
*
示例8: function
///<reference path="../typings/globals/handlebars/index.d.ts" />
import * as Handlebars from "handlebars";
Handlebars.registerHelper(
'selectOptions',
function(options: Array<any>|{[k:string]:any}, selected:any, dflt:{v:any, k:string}){
let r: string;
let i: any;
let f: (k:string, v:any, s:boolean) => string;
f = (k,v,s) => '<option value="'+k+'"'+(s?' selected':'')+'>'+v+'</option>';
r = dflt ? f(dflt.k,dflt.v,false) : '';
if (options instanceof Array) {
let l: number = options.length;
for (i=0; i<l; i++){r += f(i,options[i],i===selected);}
} else {
for (i in options) {r += f(i,options[i],i===selected);}
}
return r;
}
);
Handlebars.registerHelper(
'radioOptions',
function(name:string, options:any[]|{[k:string]:any}, selected:any){
let r: string;
let i: any;
let f: (n:string, k:string, v:any, s:boolean) => string;
f = (n,k,v,s) => '<label><input type="radio" name="'+n+'" value="'+k+'"'+(s?' checked':'')+' /> '+v+'</label>';
r = '';
if (options instanceof Array) {
let l: number = options.length;
示例9: function
"use strict";
import * as Handlebars from 'handlebars';
import * as path from 'path';
import * as url from 'url';
import * as btoa from 'btoa';
import * as atob from 'atob';
import * as pretty from 'pretty';
import {IRenderer, IRendererOptions} from './Renderer';
import {Component} from './Component';
Handlebars.registerHelper("pp", function(object:{}){
return new Handlebars.SafeString(JSON.stringify(object));
});
Handlebars.registerHelper("beautified", function(object:{}){
return pretty(object);
});
Handlebars.registerHelper("eq", function(a: {}, b: {}){
return a === b;
});
Handlebars.registerHelper("rellink", function(link, options){
var absoluteLinkPath = link;
var uri = url.parse(link);
var options = options.data.root, cwd, root;
if (uri.host !== null) {
// we have an URL here, not a path, so just return it
示例10: function
import * as Handlebars from "handlebars";
import * as request from 'request';
import * as util from 'util';
import { readFile, writeFile } from "./lib/utility/fs";
import { execSync } from "child_process";
Handlebars.registerHelper('bash', function (command: string) {
return execSync(command).toString().replace(/\[\d{1,2}m/gi, '')
})
async function fromGithub (endpoint: string) {
return util.promisify(request)({
method: 'GET',
url: 'https://api.github.com/' + endpoint,
json: true,
headers: { 'User-Agent': 'README generator' }
}).then(response => response.body)
}
Promise
.all([
readFile('./README.handlebars', 'utf8'),
fromGithub('repos/2fd/graphdoc'),
fromGithub('repos/2fd/graphdoc/contributors').then(contributors => contributors.filter(c => c.login !== '2fd') ),
])
.then(([template, project, contributors]) => {
return writeFile('README.md', Handlebars.compile(template)({project, contributors}))
})
示例11: isChecked
exportedDataWindow: Handlebars.compile($('#tmpl-exporteddatawindow').html()),
credentialTable: Handlebars.compile($('#tmpl-credentialtable').html()),
credentialTableRow: Handlebars.compile($('#tmpl-credentialtablerow').html()),
validationMessage: Handlebars.compile($('#tmpl-validationmessage').html()),
modalHeader: Handlebars.compile($('#tmpl-modalheader').html()),
modalBody: Handlebars.compile($('#tmpl-modalbody').html()),
modalFooter: Handlebars.compile($('#tmpl-modalfooter').html()),
copyLink: Handlebars.compile($('#tmpl-copylink').html())
};
Handlebars.registerPartial('credentialtablerow', templates.credentialTableRow);
Handlebars.registerPartial('copylink', templates.copyLink);
Handlebars.registerHelper('breaklines', (text: string) => {
const escapedText = Handlebars.Utils.escapeExpression(text);
return new Handlebars.SafeString(escapedText.replace(/(\r\n|\n|\r)/gm, '<br />'));
});
Handlebars.registerHelper('truncate', (text: string, size: number) => {
const escapedText = Handlebars.Utils.escapeExpression(truncate(text, size));
return new Handlebars.SafeString(escapedText);
});
let currentSession: any = null;
// Pure functions
export function isChecked(el: JQuery) {
return (el[0] as HTMLInputElement).checked;
}
示例12: constructor
constructor(renderer: Renderer, basePath) {
super(renderer, basePath);
Handlebars.registerHelper('getConfigData', this.getConfigData);
}
示例13: registerHelpers_
export function registerHelpers_() {
handlebars.registerHelper('date', date => {
return getDuration(date)
})
handlebars.registerHelper('compareLink', function() {
const { github_host, user, repo, pullHeadSHA, currentSHA } = this.options
return `${github_host}${user}/${repo}/compare/${pullHeadSHA}...${currentSHA}`
})
handlebars.registerHelper('forwardedLink', function() {
const { github_host, fwd, repo, forwardedPull } = this.options
return `${github_host}${fwd}/${repo}/pull/${forwardedPull}`
})
handlebars.registerHelper('link', function() {
const { github_host, user, repo, number } = this.options
return `${github_host}${user}/${repo}/pull/${number}`
})
handlebars.registerHelper('submittedLink', function() {
const { github_host, submit, repo, submittedPull } = this.options
return `${github_host}${submit}/${repo}/pull/${submittedPull}`
})
handlebars.registerHelper('issueLink', function() {
const { github_host, user, repo, number } = this.options
return `${github_host}${user}/${repo}/issues/${number}`
})
handlebars.registerHelper('gistLink', function() {
const { github_gist_host, loggedUser, id } = this.options
return `${github_gist_host}${loggedUser}/${id}`
})
handlebars.registerHelper('repoLink', function() {
const { github_gist_host, user, repo } = this.options
return `${github_gist_host}${user}/${repo}`
})
handlebars.registerHelper('wordwrap', (text, padding, stripNewLines) => {
let gutter = ''
if (stripNewLines !== false) {
text = text.replace(/[\r\n\s\t]+/g, ' ')
}
text = wrap(text).split('\n')
if (padding > 0) {
gutter = ' '.repeat(padding)
}
return text.join(`\n${gutter}`)
})
}
示例14: registerHelper
export function registerHelper(name, callback) {
handlebars.registerHelper(name, callback)
}
示例15: function
import Handlebars from "handlebars";
import { ABIDefinition } from "web3/eth/abi";
Handlebars.registerHelper("capitalize", (word: string) => {
return word.charAt(0).toUpperCase() + word.slice(1);
});
Handlebars.registerHelper("lowercase", (word: string) => {
return word.toLowerCase();
});
Handlebars.registerHelper("ifview", function(stateMutability: string, options: Handlebars.HelperOptions) {
const isView = stateMutability === "view" || stateMutability === "pure" || stateMutability === "constant";
if (isView) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper("ifstring", function(value: string, options: Handlebars.HelperOptions) {
if (value === "string") {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper("ifeq", function(elem: string, value: string, options: Handlebars.HelperOptions) {
if (elem === value) {
return options.fn(this);
}
return options.inverse(this);