本文整理匯總了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)
}