How to use the compileFile function from swig

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

12
13
14
15
16
17
18
19
20
21
22
23
var macros = require('./lib/macros');


// Precompile templates
var JST = {
  index: swig.compileFile(__dirname + '/templates/index.swig'),
  appcache: swig.compileFile(__dirname + '/templates/appcache.swig'),
};


// Set bootup time as the cache busting hash for the app cache manifest
var bootupTime = Date.now();
fork icon61
star icon126
watch icon0

82
83
84
85
86
87
88
89
90
91

if (this.view) {
    if (!config.STATIC.CACHE_HTML) {
        swig.invalidateCache();
    }
    data = swig.compileFile(this.view.index)(this.view.vars);

    var dontCompress = (config.STATIC.COMPRESS_HTML_EXCEPTION.indexOf(this.PATH) >= 0) || (this.PATH == "" && config.STATIC.COMPRESS_HTML_EXCEPTION.indexOf("/") >= 0);

    if (config.STATIC.COMPRESS_HTML && !dontCompress) {
fork icon4
star icon11
watch icon8

493
494
495
496
497
498
499
500
501
502

function renderPage(req, res, content, template) {
    // eslint-disable-next-line
    let requestPathname = template || req._parsedUrl.pathname;
    try {
        const tpl = swig.compileFile(templatePath + requestPathname);
        res.send(tpl(Object.assign({
            now: Math.round((new Date()).getTime() / 1000),
            cookies: req.cookies,
            signedCookies: req.signedCookies,
fork icon3
star icon7
watch icon4

+ 62 other calls in file

148
149
150
151
152
153
154
155
156
157
    }
    var result = yield request('http://www.yst.com.cn/pc/security/landing/goods/'+products.join(','));
    console.log('http://182.254.222.64/pc/security/landing/goods/'+products.join(','));
    page[i] = result.body;
}
var compile = swig.compileFile(tmplPath);
var data;
if(typeof page[i] === 'string'){
    data = JSON.parse(page[i]);
}else{
fork icon2
star icon3
watch icon0

64
65
66
67
68
69
70
71
72
73
config.configureSwig(swig);
config.configureSwig(markedSwig);

glob.sync(config.templates, {cwd: config.cwd}).forEach(function(file) {
  var absfile = path.resolve(config.cwd, file);
  templates[file] = swig.compileFile(absfile);
});

return through(function(tree, enc, done) {
  if (!(tree instanceof Node)) { this.push(tree); return done(); }
fork icon1
star icon2
watch icon3

195
196
197
198
199
200
201
202
203
204
 * @param {Array}  data
 * @param {String} destination
 * @param {Object} options
 */
generate: function (data, destination, options) {
  var template = swig.compileFile(__dirname + '/../templates/docs.html.swig');

  options.data = data;
  
  return exports.file.create(destination, template(options));
fork icon62
star icon0
watch icon2

86
87
88
89
90
91
92
93
94
95
    _fs.lsfile(this.options.tplRoot, (name, file) => {
        logger.log('debug', {
            data: [file],
            message: 'complie template %s'
        });
        this.templates[file] = swig.compileFile(file, {autoescape: !1});
    });
}

/**
fork icon4
star icon25
watch icon3

3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
* //    }
* tpl({ tacos: 'Tacos!!!!' });
* // => Tacos!!!!
*
* @example
* swig.compileFile('/myfile.txt', { varControls: ['<%=', '=%>'], tagControls: ['<%', '%>']});
* // => will compile 'myfile.txt' using the var and tag controls as specified.
*
* @param  {string} pathname  File location.
* @param  {SwigOpts} [options={}] Swig options object.
fork icon0
star icon1
watch icon0

+ 3 other calls in file

994
995
996
997
998
999
1000
1001
1002
    "-" +
    insurence_want.getFullYear();
}

//  total_data.personData[0].birthday = total_data.personData[0].birthday;
const detailsEmailTemplate = swig.compileFile("details_email.twig");
const html1 = detailsEmailTemplate(total_data);

fs.writeFileSync("./detailsEmailTemplate123.html", html1);
fork icon0
star icon0
watch icon1

+ 780 other calls in file

954
955
956
957
958
959
960
961
962
Object.assign(total_data, {agentEmail});
Object.assign(total_data, {agentPhone});
Object.assign(total_data, {agentSubject});

total_data.applicant_email_content = total_data.applicant_email_content.split("<br>").join("\n");
const thankyouTemplate = swig.compileFile('thankyou.twig');
const html2 = thankyouTemplate(total_data);

let additional_email = total_data.agent['additional_email'].trim() != "" ? total_data.agent['additional_email'].replace("|",",") : "";
fork icon0
star icon0
watch icon1

+ 769 other calls in file

210
211
212
213
214
215
216
217
218
219
let token1 = encrypt(userData.data._id + parseInt(text));
let expiry = new Date();
expiry.setMinutes(expiry.getMinutes() + 30);
password_resets.save({email: req.body.email, reset_token: token1, expiry: expiry}).then((pwdResetData) => {
    if (pwdResetData["status"] == 1) {
        let tpl_swig = swig.compileFile('public/mail_page/index.html');
        let link = '<a href="' + env.adminUrl + 'reset-password/' + token1 + '">' + env.adminUrl + 'reset-password/' + token1 + '</a>';
        let content = templateData.content;
        let subject = templateData.subject;
        content = content.replace('@email@', userData.data.email);
fork icon0
star icon0
watch icon1