Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'swig' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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;
});
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');
swig.method('configure', function (options){
var _swig = require('swig');
_swig.init(options);
});
exports.init = function (options) {
var swig = require('swig');
swig.init(options);
};
exports.init = function (options) {
swig.init(options);
};
/**
* 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')));
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;
}
function(name,file){
this.emit('debug',{
data:[file],
message:'complie template %s'
});
this._templates[file] = swig.compileFile(file,{autoescape:!1});
}
.bind(this)
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);
};