How to use swig - 10 common examples

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 flockonus / gartsb / proofs / boiler / app.js View on Github external
var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , swig = require('./config/consolidate-swig').swig
  , redis = require('redis')
  , C 



var app = express();

if ('development' == app.get('env')) {
	C = console.log
	app.set('config', JSON.parse( require('fs').readFileSync('./config/development.json', 'utf8') ) )
	require('swig').init({ cache: false, allowErrors: true, filters: {} })
	console.log('configuring DEV')
}

if ('production' == app.get('env')) {
	C = function(){}
  app.set('config', JSON.parse( require('fs').readFileSync('./config/production.json', 'utf8') ) )
  require('swig').init({ cache: true, allowErrors: false, filters: {} })
	console.log('configuring PROD')
}



app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.engine('html', swig);
	app.set('view engine', 'html');
github bigcompany / resources / swig / index.js View on Github external
swig.method('configure', function (options){
  var _swig = require('swig');
      _swig.init(options);
});
github bigcompany / resources / view / lib / engines / swig / index.js View on Github external
exports.init = function (options) {
  var swig = require('swig');
  swig.init(options);
};
github emre / swarm-host / swarm-host / app.js View on Github external
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path')
  , stat = require('./stat')
  , config = require('./config')
  , swig = require('./swigger').swig

var app = express();
var enable_debug = true;

require('swig').init({ cache: true, allowErrors: false, filters: {} })

app.set('host', config.APP_HOST);
app.set('port', config.APP_PORT);
app.set('views', __dirname + '/views');

app.engine('html', swig);
app.set('view engine', 'html');
app.set('view options', { layout: false });

app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
github lepture / nico / lib / engines / swig.js View on Github external
function init() {
  if (isInitSwig) return;
  store = getEnv();

  swig.init({
    autoescape: false,
    cache: false,
    allowErrors: true,
    encoding: option.get('encoding'),
    filters: store.filters,
    root: store.roots,
    tzOffset: option.get('tzOffset', 0)
  });

  isInitSwig = true;
}
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);
};

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