本文整理汇总了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
});
}
});
}
示例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;
}
示例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)!;
}
示例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);
});
}
示例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
}));
}
}
示例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, __) => {
示例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;
示例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
/**
* 文章标题
*/
示例9: compile
compile(){
return jade.compileFile(this.options.filePath, this.options)
}