How to use the swig.compileFile function in swig

To help you get started, we’ve selected a few swig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github x-orpheus / nei-toolkit / lib / nei / node.js View on Github external
let files = _fs.lsfile(this.config.outputRoot, (fileName, file) => {
            logger.log('debug', {
                message: `compile template ${file}`
            });
            // 有些文件如果有乱码,会导致编译异常
            try {
                templates[file] = swig.compileFile(file, {autoescape: false});
                // 如果 tokens.length === 1, 则说明没有需要替换的内容, 返回 false 以过滤掉该文件
                return templates[file].tokens.length !== 1;
            } catch (err) {
                logger.log('error', {
                    message: `compile template error: ${err}`
                });
            }
            return false;
        });
github genify / toolkit2 / lib / nei / builder.js View on Github external
function(name,file){
            this.emit('debug',{
                data:[file],
                message:'complie template %s'
            });
            this._templates[file] = swig.compileFile(file,{autoescape:!1});
        }
        .bind(this)
github lepture / nico / lib / engines / swig.js View on Github external
exports.render = function(template, data) {
  init();
  if (!/\.html$/.test(template)) {
    template = template + '.html';
  }
  var tpl = swig.compileFile(template);

  data = _.defaults(data, store.globals);
  return tpl.render(data);
};
github BenBBear / Zeta / modules / service / more_service.js View on Github external
var render = function(fpath, json) {
    var tpl = cache[fpath];
    if (tpl === undefined) {
        var lfpath = public + fpath;
        tpl = swig.compileFile(lfpath);
        cache[fpath] = tpl;
    }
    return tpl(json);
};
render.text = function(string, json) {
github BenBBear / Zeta / modules / route / scope.js View on Github external
fs.stat(path, function(err, stat) {
            if (err)
                self.status(500).end('Server Internal Error: ' + JSON.stringify(err));
            else {
                cacheTime[file] = stat.mtime;
                cacheRender[file] = swig.compileFile(path);
                self.end(cacheRender[file](json));
            }
        });
    }
github BenBBear / Zeta / modules / service / template.js View on Github external
var render = function(fpath, json) {
    var tpl;
    fpath = root + fpath;
    if (tpl !== undefined) {
        tpl = cache[fpath];
    } else {
        tpl = swig.compileFile(fs.readFileSync(fpath));
        cache[fpath] = tpl;
    }
    return tpl(json);
};
github google / WebFundamentals / src / static / third_party / material-design-lite / gulpfile.js View on Github external
return through.obj(function(file, enc, cb) {
    var data = {
      site: site,
      page: file.page,
      content: file.contents.toString()
    };

    var templateFile = path.join(
        __dirname, 'docs', '_templates', file.page.layout + '.html');
    var tpl = swig.compileFile(templateFile, {cache: false});
    file.contents = new Buffer(tpl(data), 'utf8');
    this.push(file);
    cb();
  });
}
github mjibson / moggio / node_modules / material-design-lite / gulpfile.js View on Github external
return through.obj(function(file, enc, cb) {
    var data = {
      site: site,
      page: file.page,
      content: file.contents.toString()
    };

    var templateFile = path.join(
        __dirname, 'docs', '_templates', file.page.layout + '.html');
    var tpl = swig.compileFile(templateFile, {cache: false});
    file.contents = new Buffer(tpl(data), 'utf8');
    this.push(file);
    cb();
  });
}
github rioki / www.rioki.org / gulpfile.js View on Github external
function applyTemplate(templateFile) {
    var tpl = swig.compileFile(path.join(__dirname, templateFile));

    return through.obj(function (file, enc, cb) {
        var data = {
            site: site,
            page: file.page,
            content: file.contents.toString()
        };
        file.contents = new Buffer(tpl(data), 'utf8');
        this.push(file);
        cb();
    });
}
github zohooo / jekyde / builder / converter / swig.js View on Github external
module.exports = function(layout, data){
    var template = swig.compileFile('../layout/' + layout + '.html');
    return template.render(data);
};

swig

A simple, powerful, and extendable templating engine for node.js and browsers, similar to Django, Jinja2, and Twig.

MIT
Latest version published 10 years ago

Package Health Score

52 / 100
Full package analysis