本文整理汇总了TypeScript中lodash.template函数的典型用法代码示例。如果您正苦于以下问题:TypeScript template函数的具体用法?TypeScript template怎么用?TypeScript template使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了template函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Buffer
.spread( (content: string, outerContent : string) => {
try {
log.info('Compile composite view %s in %s',templateFilename,layoutFilename);
var innerContent = new Buffer( _.template(content)(viewData), 'utf-8' );
var fullContent = new Buffer( _.template(outerContent)( { page: innerContent, name: viewData.Name, data: viewData.data }), 'utf-8');
laterAct.resolve( new relaxjs.Embodiment( 'text/html', 200, fullContent ));
}
catch( err ) {
log.error( err );
laterAct.reject( emitCompileViewError(content,err, templateFilename +' in '+ layoutFilename) );
}
})
示例2: createPlatformTests
function createPlatformTests() {
let platforms = [
'android',
'ios',
'windows'
];
let testTemplate = template(readFileSync(`${SCRIPTS_ROOT}/${E2E_NAME}/e2e.template.js`).toString());
return obj(function (file, enc, next) {
let self = this;
let relativePath = dirname(file.path.replace(/^.*?src(\/|\\)components(\/|\\)/, ''));
relativePath = relativePath.replace('/test/', '/');
let contents = file.contents.toString();
platforms.forEach(function (platform) {
let platformContents = testTemplate({
contents: contents,
buildConfig: buildConfig,
relativePath: relativePath,
platform: platform
});
self.push(new VinylFile({
base: file.base,
contents: new Buffer(platformContents),
path: file.path.replace(/e2e.js$/, platform + '.e2e.js')
}));
});
next();
});
}
示例3: _generateAndSave
private _generateAndSave(filePath: string): void {
let splitted = filePath.split(path.sep);
let part = splitted.filter(p => {
return splitted.indexOf(p) > splitted.indexOf(this.model);
}).join('/');
let to;
if (this.model !== 'project') {
to = path.join('src', 'app', `${this.model}s`,
this.name, path.basename(part).replace(/name/, this.name));
} else {
to = part;
}
try {
if (!dir.isDir(filePath)) {
let contents = fse.readFileSync(filePath, 'utf8');
let template = _.template(contents, { variable: 'data' });
fse.outputFileSync(to, template(this.data), 'utf8');
console.log(` ${chalk.green('create')} ${to}`);
} else {
if (!helper.existsSync(to)) {
fse.mkdirsSync(to);
}
}
} catch (e) {
throw new Error(e);
}
}
示例4: makeCollapsible
export function makeCollapsible(document: Document,
kind: string,
headingId: string,
collapseId: string,
additional: AdditionalClasses = {}):
Collapsible {
let additionalGroupClasses = additional.group;
let additionalPanelClasses = additional.panel;
let additionalToggleClasses = additional.toggle;
additionalPanelClasses =
additionalPanelClasses !== undefined ? ` ${additionalPanelClasses}` : "";
additionalGroupClasses =
additionalGroupClasses !== undefined ? ` ${additionalGroupClasses}` : "";
additionalToggleClasses =
additionalToggleClasses !== undefined ? ` ${additionalToggleClasses}` : "";
const el = domutil.htmlToElements(
_.template(collapsibleTemplate)({
kind: kind,
group_classes: additionalGroupClasses,
panel_classes: additionalPanelClasses,
toggle_classes: additionalToggleClasses,
heading_id: headingId,
collapse_id: collapseId,
}), document)[0] as HTMLElement;
return {
group: el,
heading: el.getElementsByTagName("a")[0],
content: el.getElementsByClassName("panel-body")[0] as HTMLElement,
};
}
示例5: function
sails.router.bind(route, function (req: any, res: any, next: Function) {
let protocol: any = _.startsWith(swagger.host, 'http') ? '' : 'http://';
let targetUrlTemplate: any = protocol + swagger.host + ( swagger.basePath || '' ) + path;
let templateFn: any = _.template(targetUrlTemplate, {
interpolate: /{([\s\S]+?)}/g
});
let params: any = req.allParams();
let targetUrl: any = templateFn(params);
let headers: any = req.headers;
_.unset(headers, 'cookie');
_.unset(headers, 'host');
_.unset(headers, 'user-agent');
_.unset(headers, 'referer');
let reqOut: any = {
url: targetUrl,
method: vertex,
body: ( req.body || null ),
qs: req.transport != 'socket.io' ? req.query : req.body,
json: true,
headers: headers
};
let $request: any = sails.$request(req.session) || request;
$request(reqOut, function (err: Error, message: any, body: any): void {
console.log('*************************');
console.log('' + vertex + ' ' + targetUrl);
console.log('-------------------------');
console.dir(headers);
console.log('=========================');
console.dir(body);
if (params && body && !params.id && !_.isArray(body)) {
body.id = body.id || uuid.v4();
body = [body];
}
else if (_.isArray(body)) {
_.each(body, function (item: any) {
item.id = item.id || uuid.v4();
});
}
if (!err) {
res
.status(message.statusCode)
.send(body);
}
else {
res.serverError(err);
}
})
})
示例6: map
const criteriaValues = map(criteria, (rawValue, key) => {
let value = rawValue
if (typeof rawValue === 'string') {
value = template(rawValue)(userContext)
if (/^\d+$/.test(value)) value = Number.parseInt(value)
}
return [key, value]
})
示例7: it
it("can make a new instance", async () => {
const story = new StoryModel();
const message = new MessageModel();
message.name = "TESTMESSAGE";
message.text = "This is the text of our message";
message.story = story._id;
message.compiledSource = _.template(message.text).source;
message.messagesLoaded = [];
await message.validate();
});
示例8: exec
wrap<void>(function* (
dfpath: string,
tag: string,
config: BuildConfig,
opts: BuildOptions) {
const cmd = opts.useCache ?
`docker build -f ${relative(process.cwd(), dfpath)} -t ${tag} .` :
`docker build -f ${relative(process.cwd(), dfpath)} -t ${tag} --no-cache .`;
yield exec(cmd);
if (config.afterEach && !opts.skipAfterEach) {
yield exec(template(config.afterEach)({ tag }));
}
});
示例9: it
it('should assign unique labels', function () {
scope.data = {text: null};
var template = _.template('<formfield type="<%= type %>" label="thelabel" model="data" model-var="text"></formfield>');
var field, input, label;
_.each(_.range(5), function (item, index) {
field = template({type: index > 2 ? 'number' : 'text'});
kaanna(field);
input = element.find('input');
label = element.find('label');
$timeout.flush();
expect(input.length).toBe(1);
expect(label.length).toBe(1);
expect(input.attr('id')).toBe('thelabel-' + index);
expect(label.attr('for')).toBe('thelabel-' + index);
});
});