Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
/* deps: mocha swig */
var assert = require('assert');
var should = require('should');
var async = require('async');
var matter = require('parser-front-matter');
var consolidate = require('consolidate');
var handlebars = require('engine-handlebars');
var lodash = consolidate.lodash;
var swig = consolidate.swig;
var App = require('..');
var app;
describe('sync helpers', function () {
beforeEach(function () {
app = new App();
app.engine('tmpl', require('engine-lodash'));
app.create('page');
})
it('should register a helper:', function () {
app.helper('a', function () {});
app.helper('b', function () {});
app._.helpers.sync.should.have.property('a');
app._.helpers.sync.should.have.property('b');
app.configure(function(){
app.set('port', process.env.PORT || settings.port);
app.set('views', __dirname + '/views');
console.log(__dirname);
app.engine('.html', cons.swig);
app.set('view engine', 'html');
swig.init({
root: __dirname + '/views',
allowError: true
});
// 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(express.cookieParser(settings.cookieSecret));
app.use(express.session({
secret: settings.sessionSecret,
store: new RedisStore
}));
app.use(app.router);
const consolidate = require('consolidate');
/*
//ejs调用
app.engine('ejs', consolidate.ejs);
app.set('views','views');
app.set('view engine', 'ejs');
*/
//jade
/* app.engine('jade', consolidate.jade); //第一个参数为模板文件 后缀
app.set('views','views');
app.set('view engine', 'jade'); */
//swig
app.engine('swig', consolidate.swig); //以 swig结尾的模板,其实swig是以html结尾的
app.set('views','views');
app.set('view engine', 'swig');
app.get('/',(req,res)=>{
res.render('index',{title:'Strive',arr:['apple','banana','orange','tomato']});
});
app.use(express.static('www'));
let server = app.listen(3000, function () {
let host = server.address().address;
let port = server.address().port;
console.log('服务器起启动 在 http://%s%s', host, port);
});
},
secret: self.config.cookie_secret,
store: self.sessionStore
}));
// Auth
self.app.use(passport.initialize());
self.app.use(passport.session());
// Templates
swig.init({
cache: !self.config.debug,
root: 'templates',
allowErrors: self.config.debug
});
self.app.engine('.html', cons.swig);
self.app.set('view engine', 'html');
self.app.set('views', 'templates');
// Static
self.app.use('/media', express.static(path.resolve('media')));
// Router
self.app.use(self.app.router);
});
// Load configurations
// Set the node enviornment variable if not set before
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var app = express();
app.set('showStackError', true);
// cache=memory or swig dies in NODE_ENV=production
app.locals.cache = 'memory';
// Prettify HTML
app.locals.pretty = true;
app.set('nextFreeWorkspacePort', 5000);
app.engine('html', consolidate.swig);
// Start the app by listening on
var port = process.env.PORT || 3105;
// all environments
app.set('port', port);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.set('baseUrl', config.BASE_URL);
app.set('runningWorkspaces', {});
//Auth
passport.use(new GithubStrategy({
clientID: config.GITHUB_CLIENT_ID,
clientSecret: config.GITHUB_CLIENT_SECRET,
callbackURL: app.get('baseUrl') + ':' + app.get('port') + '/auth/github/callback'
it('should use the key of a cached template to determine the consolidate engine to use:', function (done) {
template.engine('hbs', consolidate.handlebars);
template.engine('swig', consolidate.swig);
template.engine('tmpl', consolidate.lodash);
template.page('a.hbs', {content: '<title>{{title}}</title>', title: 'Handlebars'});
template.page('b.tmpl', {content: '<title><%= title %></title>', title: 'Lo-Dash'});
template.page('d.swig', {content: '<title>{{title}}</title>', title: 'Swig'});
Object.keys(template.views.pages).forEach(function(name) {
var ext = path.extname(name);
template.render(name, function (err, content) {
if (err) console.log(err);
if (ext === '.hbs') {
content.should.equal('<title>Handlebars</title>');
}
if (ext === '.tmpl') {
var express = require('express');
var engines = require('consolidate');
var swig = require('swig');
var parser = require('../src/parser');
var app = express();
app.engine('html', engines.swig);
app.set('view engine', 'html');
swig.init({
root: __dirname,
allowErrors: true,
cache: false
});
app.set('views', __dirname);
app.set("view options", {layout: false});
app.get('/', function(req, res) {
res.render('server.html');
});
app.get('/redirect', function(req, res) {
var url = parser(req.query.service, req.query);
res.redirect(url);
var app = express();
if (template_engine == 'dust') {
var dust = require('dustjs-linkedin'),
cons = require('consolidate');
app.engine('dust', cons.dust);
} else if (template_engine == 'ejs') {
app.engine('ejs', engine);
} else if (template_engine == 'swig') {
var swig = require('swig'),
cons = require('consolidate');
app.engine('swig', cons.swig);
//app.set('view engine', 'html');
}
app.configure(function() {
if (template_engine == 'swig') {
app.set('view engine', 'swig');
app.set('view options', {
layout: false
});
}
app.set('template_engine', template_engine);
app.set('domain', domain);
app.set('port', process.env.PORT || 8080);
app.set('views', __dirname + '/views');
app.configure(function(){
app.engine('.html', consolidate.swig);
app.set('router', router);
app.set('view engine', 'html');
app.set('views', views);
app.set('port', process.env.PORT || config.port || 3000);
app.use(middleware.errorHandler);
app.use(express.static(path.join(__dirname, 'public')), { maxAge: 600 });
app.use(express.static(storagePath));
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('__SECRET__'));
app.use('/files', express.cookieSession({ secret: secret }));
app.use('/workspaces', express.cookieSession({ secret: secret }));
app.use('/admin', express.cookieSession({ secret: secret }));
app.use(flash());
module.exports.setEngine = (app) => {
app.engine('html', cons.swig);
app.set('view engine', 'html');
app.set('views', path.resolve('modules/users/templates'));
};