How to use the compileFile function from pug
Find comprehensive JavaScript pug.compileFile code examples handpicked from public code repositorys.
GitHub: pugjs/pug-en
![pugjs profile picture](/pugjs.png?size=40)
88 89 90 91 92 93 94 95 96 97
// Render the function var html = fn(locals); // => '<string>of pug</string>' ``` ### pug.compileFile(path, ?options) Compile a Pug template from a file to a function, which can be rendered multiple times with different locals. ```parameter-list
+ 3 other calls in file
111 112 113 114 115 116 117 118 119 120
```js var pug = require('pug'); // 编译出一个函数 var fn = pug.compileFile('到 Pug 代码文件的路径', options); // 渲染它 var html = fn(locals); // => '从 Pug 生成的 HTML 代码'
+ 3 other calls in file
46 47 48 49 50 51 52 53 54 55
donneesMesures, donneesRisques, referentiel, }) => { const genereAnnexe = async (pugCorps, paramsCorps) => generePdf( pug.compileFile(`src/pdf/modeles/${pugCorps}.pug`)(paramsCorps), pug.compileFile(`src/pdf/modeles/${pugCorps}.entete.pug`)(), pug.compileFile('src/pdf/modeles/annexe.piedpage.pug')({ nomService: donneesDescription.nomService }) );
+ 8 other calls in file
105 106 107 108 109 110 111 112 113 114
} const premierePage = await documentPdf.save({ updateFieldAppearances: false }); const [entete, corps, piedPage] = await Promise.all([ pug.compileFile('src/pdf/modeles/annexeAvis.entete.pug')(), pug.compileFile('src/pdf/modeles/annexeAvis.pug')({ donnees }), pug.compileFile('src/pdf/modeles/annexe.piedpage.pug')({ nomService: donnees.nomService }), ]); const annexeAvis = await generePdfs([{ entete, corps, piedPage }]);
+ 149 other calls in file
GitHub: scheibome/kss-scheibo
399 400 401 402 403 404 405 406 407 408
return fs.readFileAsync(filepath, 'utf8').then(fileContent => { let output = fileContent; const isPugFile = path.extname(filepath) === '.pug'; if (isPugFile) { const pugFn = pug.compileFile(filepath, { pretty: true }); output = pugFn(); } this.Handlebars.registerPartial(name, output);
+ 2 other calls in file
16 17 18 19 20 21 22 23 24 25
exports.compileClient = function (source, options) { return pug.compileClientWithDependenciesTracked(source, options) } exports.compileFile = function (path, options) { const fn = pug.compileFile(path, options) return { fn, dependencies: fn.dependencies }
10 11 12 13 14 15 16 17 18 19
}; exports.compileClient = function (source, options) { return pug.compileClientWithDependenciesTracked(source, options); }; exports.compileFile = function (path, options) { var fn = pug.compileFile(path, options); return {fn: fn, dependencies: fn.dependencies} }; exports.compileFileClient = function (path, options) { var fs = require('fs');
67 68 69 70 71 72 73 74 75 76 77 78
app.set('views', './views') app.set('view engine', 'pug'); const port = process.env.PORT || 3000; const boardfn = pug.compileFile('views/board.pug'); // Render the function const htmlcylinderwhite = boardfn({ boardtype: 'cylinder', colour: 'w'}); const htmlcylinderblack = boardfn({ boardtype: 'cylinder', colour: 'b'}); const htmlsquarewhite = boardfn({ boardtype: 'square', colour: 'w'});
GitHub: freezer333/cmps369-v2
3 4 5 6 7 8 9 10 11 12 13 14
const Framework = require('fwcmps369'); const Database = require('dbcmps369'); const db = new Database(); const guess_t = pug.compileFile('./views/guess.pug'); const complete_t = pug.compileFile('./views/complete.pug'); const history_t = pug.compileFile('./views/history.pug'); const game_t = pug.compileFile('./views/game.pug');
+ 119 other calls in file
GitHub: micromaomao/blog
87 88 89 90 91 92 93 94 95 96
function get_template(fp) { let file_path = path.resolve(__dirname, fp); print_status(`Compile template: ${file_path}`); let fn; try { fn = pug.compileFile(file_path, {pretty: true}); } catch (e) { throw new Error(`Error compiling ${file_path}: ${e.message}`); } let sass_path = path.resolve(__dirname, fp.replace(/\.pug$/, ".sass"));
+ 18 other calls in file
GitHub: freezer333/cmps369-v2
2 3 4 5 6 7 8 9 10 11 12 13
const Framework = require('fwcmps369'); const Database = require('dbcmps369'); const pug = require('pug'); const guess_t = pug.compileFile('./views/guess.pug'); const success_t = pug.compileFile('./views/success.pug'); const history_t = pug.compileFile('./views/history.pug'); const guess_history_t = pug.compileFile('./views/guess_history.pug'); const db = new Database();
+ 119 other calls in file
23 24 25 26 27 28 29 30 31 32 33 34 35
// -- Web: var panelViewTemplate = require('pug-loader!../templates/panelView.pug'); // -- Desktop: //var pug = require('pug'); //var path = require('path'); //var panelViewTemplate = pug.compileFile(path.join(__dirname, '..', 'templates', 'panelView.pug'));
+ 8 other calls in file
6 7 8 9 10 11 12 13 14 15 16 17
// -- Web: var cardDataViewTemplate = require('pug-loader!../templates/cardDataView.pug'); // -- Desktop: //var pug = require('pug'); //var path = require('path'); //var cardDataViewTemplate = pug.compileFile(path.join(__dirname, '..', 'templates', 'cardDataView.pug')); class CardDataView { constructor(data) {
+ 8 other calls in file
5 6 7 8 9 10 11 12 13 14 15 16
// -- Web: var tableDataViewTemplate = require('pug-loader!../templates/tableDataView.pug'); // -- Desktop: //var pug = require('pug'); //var path = require('path'); //var tableDataViewTemplate = pug.compileFile(path.join(__dirname, '..', 'templates', 'tableDataView.pug')); class TableDataView { constructor(data) {
+ 8 other calls in file
7 8 9 10 11 12 13 14 15 16 17 18
// -- Web: var groupedBarChartDataViewTemplate = require('pug-loader!../templates/groupedBarChartDataView.pug'); // -- Desktop: //var pug = require('pug'); //var path = require('path'); //var groupedBarChartDataView = pug.compileFile(path.join(__dirname, '..', 'templates', 'groupedBarChartDataView.pug')); class GroupedBarChartDataView { constructor(data, currentKey) {
+ 5 other calls in file
15 16 17 18 19 20 21 22 23 24 25 26 27 28
const { DateTime } = require('luxon'); const AWS = require('aws-sdk'); const sitemapTemplate = pug.compileFile('views/sitemap.pug'); const fetchDataFromDynamo = async () => { // Stryker disable StringLiteral,ObjectLiteral: This query is correct but won't be tested due to mocking const statement = `SELECT MeetingID,
21 22 23 24 25 26 27 28 29 30 31 32 33
const { DateTime, Duration } = require('luxon'); DateTime.DATETIME_CLEAR = DATETIME_CLEAR; const AWS = require('aws-sdk'); const listMeetingsTemplate = pug.compileFile('views/list-meetings.pug'); const fetchDataFromDynamo = async (numDays) => { // Stryker disable StringLiteral,ObjectLiteral: This query is correct but won't be tested due to mocking const statement = `SELECT MeetingID,
23 24 25 26 27 28 29 30 31 32 33 34 35
DateTime.DATETIME_CLEAR = DATETIME_CLEAR; DateTime.TIME_SIMPLENOZERO = TIME_SIMPLENOZERO; const AWS = require('aws-sdk'); const listParticipantsTemplate = pug.compileFile('views/list-participants.pug'); // Sort the `participant.JoinTimes` and `participant.LeaveTimes` chronologically into a single array of objects with // `[{time:..., state:...}]` where state is incremented if the time at that position is a Join and decremented for a Leave const sortJoinLeaveTimes = (participant, meetingStartTime) => {
GitHub: swdevlin/muse
22 23 24 25 26 27 28 29 30 31 32 33
accessKeyId: process.env.AWS_ACCESS_KEY, secretAccessKey: process.env.AWS_SECRET, }); const docsFolder = '../muse_web/personas/'; const documentationTemplate = pug.compileFile('./template.pug', {}); const QUERIES = [ 'what is ', 'what are ',
pug.compileFile is the most popular function in pug (496 examples)