本文整理汇总了TypeScript中pug.compileFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compileFile函数的具体用法?TypeScript compileFile怎么用?TypeScript compileFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compileFile函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: generateHomewidgetTimeline
/**
* @param tlsource 'home' or 'mentions'
*/
export default function generateHomewidgetTimeline(me: User, locale: any, tlsource: string): Promise<string> {
const compiler: (locals?: any) => string = pug.compileFile(
`${__dirname}/views/home-widgets/timeline.pug`, {
cache: true
});
return new Promise<string>((resolve, reject) => {
switch (tlsource) {
case 'home':
requestApi('posts/timeline', { 'limit': 10 }, me.id).then((tl: Post[]) => {
resolve(compile(tl));
}, reject);
break;
case 'mentions':
requestApi('posts/mentions/show', { 'limit': 10 }, me.id).then((tl: Post[]) => {
resolve(compile(tl));
}, reject);
break;
default:
break;
}
function compile(tl: any): string {
return compiler({
posts: tl,
me: me,
userSettings: me._settings,
locale: locale,
config: config.publicConfig
});
}
});
}
开发者ID:sagume,项目名称:Misskey-Web,代码行数:37,代码来源:generate-homewidget-timeline.ts
示例2: walkDirectoryForRoutes
function walkDirectoryForRoutes(directory = views, r: Route[] = []) {
const dir = readdirSync(directory, { withFileTypes: true });
const files = dir.filter(x => x.isFile());
for (const { name: filepath } of files) {
const file = join(directory, basename(filepath));
const url = normalize(file)
.replace(views, '')
.replace(/\\/g, '/')
.replace(/[.]pug$/, '');
r.push({
url,
template: compileFile(file),
title: url
.replace(/^\//, '')
.split('/')
.map(x =>
x
.split('-')
.map(y => `${y.charAt(0).toUpperCase()}${y.substring(1)}`)
.join(' '),
)
.join(' - '),
});
}
for (const { name: subdirectory } of dir.filter(x => x.isDirectory())) {
walkDirectoryForRoutes(join(directory, subdirectory), r);
}
return r;
}
开发者ID:ledge23,项目名称:completely-fictional,代码行数:33,代码来源:server.ts
示例3: compile
export function compile(templateName: string) {
if (! cache.has(templateName)) {
const filename = path.join(templateDir, templateName);
cache.set(templateName, pug.compileFile(filename));
}
return cache.get(templateName)!;
}
开发者ID:AlekSi,项目名称:vscode-spell-checker,代码行数:7,代码来源:pugHelper.ts
示例4: wrapHtml
export function wrapHtml(templateFile, pkg, logger: Logger = gutil) {
const packageJson = JSON.stringify(createPackageJson(pkg));
const template = compileFile(templateFile);
return through.obj(function(file: GulpFile, enc, callback) {
if (file.html) {
const html = template({
title: createTitle(file.meta || null),
content: file.html,
meta: deflate(file.meta),
pkg: `window.pkg=${packageJson}`
});
file.contents = new Buffer(html, enc);
logger.log('Added html content to Vinyl', file.path);
}
callback(null, file);
});
}
开发者ID:valotas,项目名称:valotas.com,代码行数:17,代码来源:wrapHtml.ts
示例5: generateWidget
function generateWidget(widget: string): Promise<string> {
if (widget === undefined || widget === null) {
return Promise.resolve(null);
}
switch (widget) {
case 'timeline':
return generateHomewidgetTimeline(me, locale, tlsource);
default:
const compiler: (locals?: any) => string = pug.compileFile(
`${__dirname}/views/home-widgets/${widget}.pug`, {
cache: true
});
return Promise.resolve(compiler({
me: me,
userSettings: me._settings,
config: config.publicConfig,
locale: locale
}));
}
}
开发者ID:sagume,项目名称:Misskey-Web,代码行数:22,代码来源:generate-homewidgets.ts
示例6: while
};
const re = /<img src="[\w-\/]+\.(jpe?g|png)"/;
const encodeHtmlImages = (html: string) => {
while (re.test(html)) {
html = html.replace(re, s => {
const loc = s.substring(10, s.length - 1);
const path = join(pub, loc);
const b64 = readFileSync(path, 'base64');
return `<img src="data:image/${extname(path).substring(1)};base64,${b64}"`;
});
}
return html;
};
const index = encodeHtmlImages(compileFile(join(views, 'index.pug'))({ title: 'Home' }));
const sitemap = encodeHtmlImages(compileFile(join(__dirname, 'sitemap.pug'))({ routes, title: 'Sitemap' }));
app
.get('/', (_, res, __) => res.send(index))
.get('/sitemap', (_, res, __) => res.send(sitemap));
for (const { url, template, title } of routes) {
const html = encodeHtmlImages(template({ title, url, poetry, largeRoundEyes }));
app.get(url, (_, res) => res.send(html));
}
app
.use(compression())
.use(express.static(pub))
.use(((err, req, res, __) => {
开发者ID:ledge23,项目名称:completely-fictional,代码行数:31,代码来源:server.ts
示例7: compileTemplate
let source = `p #{ name } 's Pug source code!`;
let path = "foo.pug";
let compileTemplate: pug.compileTemplate;
let template: string;
let clientFunctionString: pug.ClientFunctionString;
let str: string;
{
/// pug.compile(source, ?options) https://pugjs.org/api/reference.html#pugcompilesource-options
compileTemplate = pug.compile(source);
template = compileTemplate();
}
{
/// pug.compileFile(path, ?options) https://pugjs.org/api/reference.html#pugcompilefilepath-options
compileTemplate = pug.compileFile(path);
template = compileTemplate();
}
{
/// pug.compileClient(source, ?options) https://pugjs.org/api/reference.html#pugcompileclientsource-options
clientFunctionString = pug.compileClient(path);
str = pug.compileClient(path);
}
{
/// pug.compileClientWithDependenciesTracked(source, ?options) https://pugjs.org/api/reference.html#pugcompileclientwithdependenciestrackedsource-options
let obj = pug.compileClientWithDependenciesTracked(source);
clientFunctionString = obj.body;
str = obj.body;
let strArray: string[] = obj.dependencies;
开发者ID:rchaser53,项目名称:DefinitelyTyped,代码行数:31,代码来源:pug-tests.ts
示例8: Log
import * as nodemailer from 'nodemailer'
import { Log } from '../utils/log'
import * as pug from 'pug'
import * as path from 'path'
const log = new Log('service/email')
const replyTemplate = pug.compileFile(path.resolve(__dirname, '../views/templates/reply-email.pug'))
export interface IAddress {
/**
* 收件人邮箱,多个使用 , 号分隔
*/
to: string
/**
* 邮件 title
*/
subject: string
/**
* 数据
*/
data: {
/**
* 用户昵称
*/
nickname: string
/**
* 文章标题
*/
开发者ID:linkFly6,项目名称:Said,代码行数:30,代码来源:email-service.ts
示例9: compile
compile(){
return jade.compileFile(this.options.filePath, this.options)
}
开发者ID:AckerApple,项目名称:ack-node,代码行数:3,代码来源:templating.ts
注:本文中的pug.compileFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论