本文整理匯總了TypeScript中jade.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 = jade.compileFile(
`${__dirname}/views/home-widgets/timeline.jade`, {
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: compiler
client.fetch(url.href).then((result: any) => {
if (result.error !== undefined && result.error !== null) {
return res.sendStatus(500);
}
const $: any = result.$;
const text: string = $('#mw-content-text > p:first-of-type').text();
// Favicon
const icon: string = URL.resolve(url.href, $('link[rel="shortcut icon"]').attr('href'));
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/summary.jade`);
const viewer = compiler({
url: url,
title,
icon,
description: text,
image: 'https://ja.wikipedia.org/static/images/project-logos/enwiki.png',
siteName: 'Wikipedia'
});
res.send(viewer);
}, (err: any) => {
示例3: request
request(getUrl, (error, response, body) => {
if (!error && response.statusCode === 200) {
const info = JSON.parse(body);
const state = info.deleted ? '削除済み' : null;
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/nicovideo.jade`);
const viewer = compiler({
url: url,
site: site,
icon: icon,
title: info.title,
description: info.description,
image: wrapMisskeyProxy(info.image),
category: info.category,
view: info.view,
time: info.time,
myList: info.my_list,
comment: info.comment,
state: state,
user: info.user_nickname
});
return res.send(viewer);
} else {
res.sendStatus(204);
}
});
示例4: analyzeYoutube
function analyzeYoutube(req: express.Request, res: express.Response, url: URL.Url): void {
function getVideoId(): string {
switch (url.hostname) {
case 'www.youtube.com':
case 'youtube.com':
return url.query.v;
case 'youtu.be':
return url.pathname;
default:
return null;
}
}
const videoId = getVideoId();
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/youtube.jade`);
const player: string = compiler({
videoId
});
res.send(player);
}
示例5: showImage
function showImage(res: express.Response, src: string, href: string): void {
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/image.jade`);
const image: string = compiler({
src,
href
});
res.send(image);
}
示例6: 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 = jade.compileFile(
`${__dirname}/views/home-widgets/${widget}.jade`, {
cache: true
});
return Promise.resolve(compiler({
me: me,
userSettings: me._settings,
config: config.publicConfig,
locale: locale
}));
}
}
示例7:
filePath => jade.compileFile(`./src/${filePath}`)
示例8: or
client.fetch(url.href).then((result: any) => {
if (result.error !== undefined && result.error !== null) {
return res.sendStatus(204);
}
const contentType: string = result.response.headers['content-type'];
// HTMLじゃなかった場合は中止
if (contentType.indexOf('text/html') === -1) {
return res.sendStatus(204);
}
const $: any = result.$;
let title = or(
$('meta[property="misskey:title"]').attr('content'),
$('meta[property="og:title"]').attr('content'),
$('meta[property="twitter:title"]').attr('content'),
$('title').text());
if (title === null) {
return res.sendStatus(204);
}
title = clip(entities.decode(title), 100);
const lang: string = $('html').attr('lang');
const type = or(
$('meta[property="misskey:type"]').attr('content'),
$('meta[property="og:type"]').attr('content'));
let image = or(
$('meta[property="misskey:image"]').attr('content'),
$('meta[property="og:image"]').attr('content'),
$('meta[property="twitter:image"]').attr('content'),
$('link[rel="image_src"]').attr('href'),
$('link[rel="apple-touch-icon"]').attr('href'),
$('link[rel="apple-touch-icon image_src"]').attr('href'));
image = image !== null ? wrapMisskeyProxy(URL.resolve(url.href, image)) : null;
let description = or(
$('meta[property="misskey:summary"]').attr('content'),
$('meta[property="og:description"]').attr('content'),
$('meta[property="twitter:description"]').attr('content'),
$('meta[name="description"]').attr('content'));
description = description !== null
? clip(entities.decode(description), 300)
: null;
if (title === description) {
description = null;
}
let siteName = or(
$('meta[property="misskey:site-name"]').attr('content'),
$('meta[property="og:site_name"]').attr('content'),
$('meta[name="application-name"]').attr('content'));
siteName = siteName !== null ? entities.decode(siteName) : null;
let icon = or(
$('meta[property="misskey:site-icon"]').attr('content'),
$('link[rel="shortcut icon"]').attr('href'),
$('link[rel="icon"]').attr('href'),
'/favicon.ico');
icon = icon !== null ? wrapMisskeyProxy(URL.resolve(url.href, icon)) : null;
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/summary.jade`);
// コンパイル
const viewer: string = compiler({
url: url,
title: title,
icon: icon,
lang: lang,
description: description,
type: type,
image: image,
siteName: siteName
});
res.send(viewer);
}, (err: any) => {
示例9:
import * as jade from 'jade';
jade.compile("b")();
jade.compileFile("foo.jade", {})();
jade.compileClient("a")({ a: 1 });
jade.compileClientWithDependenciesTracked("test").body();
jade.render("h1", {});
jade.renderFile("foo.jade");