當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript pug.compileFile函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。