How to use the compileFile function from pug

Find comprehensive JavaScript pug.compileFile code examples handpicked from public code repositorys.

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
fork icon31
star icon12
watch icon7

+ 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 代码'
fork icon9
star icon32
watch icon11

+ 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 })
  );

fork icon6
star icon6
watch icon3

+ 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 }]);
fork icon6
star icon6
watch icon4

+ 149 other calls in file

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);
fork icon3
star icon7
watch icon1

+ 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
  }
fork icon1
star icon6
watch icon4

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');
fork icon1
star icon0
watch icon2

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'});
fork icon0
star icon2
watch icon2

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');

fork icon0
star icon0
watch icon1

+ 119 other calls in file

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"));
fork icon0
star icon0
watch icon2

+ 18 other calls in file

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();
fork icon0
star icon0
watch icon1

+ 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'));







fork icon0
star icon0
watch icon2

+ 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) {
fork icon0
star icon0
watch icon2

+ 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) {
fork icon0
star icon0
watch icon2

+ 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) {
fork icon0
star icon0
watch icon2

+ 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,
fork icon0
star icon0
watch icon0

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,
fork icon0
star icon0
watch icon0

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) => {
fork icon0
star icon0
watch icon0

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 ',
fork icon0
star icon0
watch icon2