本文整理汇总了TypeScript中lodash.template类的典型用法代码示例。如果您正苦于以下问题:TypeScript template类的具体用法?TypeScript template怎么用?TypeScript template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了template类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: minify
return es.map(function(file: any, callback: (err: any, htmlMinifierfile: any) => void) {
var template = '$templateCache.put("<%= url %>","<%= contents %>");';
var url;
file.path = path.normalize(file.path);
if(typeof options.path === 'function') {
url = path.join(options.path(file.path, file.base));
} else {
url = path.join(file.path);
url = url.replace(file.base, '');
};
if (process.platform === 'win32') {
url = url.replace(/\\/g, '/');
}
let contents = file.contents.toString();
if(options.htmlMinifier) {
contents = minify(contents, options.htmlMinifier);
}
contents = require('js-string-escape')(contents);
file.contents = Buffer.from(lodashTemplate(template)({
url: url,
contents: contents,
file: file
}), 'utf8');
callback(null, file);
});
示例2: create
private async create(url: string, size: string, options: Options): Promise<Screenshot> {
const basename = path.isAbsolute(url) ? path.basename(url) : url;
let hash = parseUrl(url).hash || '';
// Strip empty hash fragments: `#` `#/` `#!/`
if (/^#!?\/?$/.test(hash)) {
hash = '';
}
const [width, height] = size.split('x');
const filenameTemplate = template(`${options.filename}.${options.format}`);
const now = Date.now();
let filename = filenameTemplate({
crop: options.crop ? '-cropped' : '',
date: dateFns.format(now, 'YYYY-MM-DD'),
time: dateFns.format(now, 'HH-mm-ss'),
size,
width,
height,
url: `${filenamifyUrl(basename)}${filenamify(hash)}`
});
if (options.incrementalName) {
filename = unusedFilename.sync(filename);
}
// TODO: Type this using the `capture-website` types
const finalOptions: any = {
width: Number(width),
height: Number(height),
delay: options.delay,
timeout: options.timeout,
fullPage: !options.crop,
styles: options.css && [options.css],
scripts: options.script && [options.script],
cookies: options.cookies, // TODO: Support string cookies in capture-website
element: options.selector,
hideElements: options.hide,
scaleFactor: options.scale === undefined ? 1 : options.scale,
type: options.format === 'jpg' ? 'jpeg' : 'png',
userAgent: options.userAgent,
headers: options.headers
};
if (options.username && options.password) {
finalOptions.authentication = {
username: options.username,
password: options.password
};
}
const screenshot = await captureWebsite.buffer(url, finalOptions) as any;
screenshot.filename = filename;
return screenshot;
}
示例3: template
Object.keys(obj).forEach((objKey) => {
if (typeof obj[objKey] === 'object' && obj !== null) {
template(obj[objKey]);
} else if (typeof obj[objKey] === 'string') {
obj[objKey] = _template(obj[objKey])(templateObj); // eslint-disable-line
if (obj[objKey].startsWith('require:')) {
obj[objKey] = require(path.resolve(dir, obj[objKey].substr(8))); // eslint-disable-line
}
}
});
示例4: createDocumentFootnotes
export function createDocumentFootnotes(settings: Settings): RawFootnote[] {
const { anchorParentSelector, buttonTemplate, numberResetSelector } = settings
const offset = parseInt(getLastFootnoteId(), 10) + 1
return findFootnoteLinks(settings)
.map(findFootnoteBody(settings))
.filter(isDefined)
.map(hideOriginalFootnote)
.map(templateData(anchorParentSelector, offset))
.map(numberResetSelector ? resetNumbers(numberResetSelector) : i => i)
.map(addButton(template(buttonTemplate)))
}
示例5: template
const runCommand = (
command: string,
options: Required<Options>,
file: Vinyl | null
): Promise<void> => {
const context = { file, ...options.templateData }
command = template(command)(context)
if (options.verbose) {
fancyLog(`${PLUGIN_NAME}:`, chalk.cyan(command))
}
const child = spawn(command, {
env: options.env,
cwd: template(options.cwd)(context),
shell: options.shell,
stdio: options.quiet ? 'ignore' : 'inherit'
})
return new Promise((resolve, reject) => {
child.on('exit', code => {
if (code === 0 || options.ignoreErrors) {
return resolve()
}
const context = {
command,
file,
error: { code },
...options.templateData
}
const message = template(options.errorMessage)(context)
reject(new PluginError(PLUGIN_NAME, message))
})
})
}
示例6: insertPopover
function insertPopover(
button: HTMLElement,
contentTemplate: string,
data: TemplateData
) {
const render = template(contentTemplate)
button.insertAdjacentHTML('afterend', render(data))
const popover = button.nextElementSibling as HTMLElement
const content = findPopoverContent(popover)
popover.setAttribute(FOOTNOTE_MAX_HEIGHT, `${getMaxHeight(content)}`)
popover.style.maxWidth = `${document.body.clientWidth}px`
bindContentScrollHandler(content)
return popover
}
示例7: resolve
child.on('exit', code => {
if (code === 0 || options.ignoreErrors) {
return resolve()
}
const context = {
command,
file,
error: { code },
...options.templateData
}
const message = template(options.errorMessage)(context)
reject(new PluginError(PLUGIN_NAME, message))
})
示例8: require
result += placeholders[i]
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
// add the last literal
result += literals[literals.length - 1];
return result;
}
var lotmpl = require( 'lodash.template' );
var emailTmp = lotmpl( fs.readFileSync( "book-sample-request.pt.html", "utf8" ) );
function escapeFormField( field: string ): string {
return field
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
function sendMail( template, info, cb ) {
var auth = config.subscribe.auth;
// setup e-mail data with unicode symbols
var mailOptions = {