Authored by 周少峰

hbs

... ... @@ -7,26 +7,29 @@
const config = require('./config/common');
global.Promise = require('bluebird');
const yohoLib = require('yoho-node-lib');
// 全局注册library
yohoLib.global(config);
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
// const session = require('cookie-session');
const session = require('yoho-express-session');
const memcached = require('connect-memcached');
const hbs = require('express-handlebars');
const pkg = require('./package.json');
const yohoLib = require('yoho-node-lib');
const app = express();
const MemcachedStore = memcached(session);
// 全局注册library
yohoLib.global(config);
global.middleware = path.resolve('./doraemon/middleware');
global.utils = path.resolve('./utils');
... ... @@ -35,17 +38,17 @@ app.locals.devEnv = app.get('env') === 'development';
app.locals.version = pkg.version;
app.set('subdomain offset', 2);
app.set('view engine', '.hbs');
app.set('views', './doraemon/views');
app.set('view cache', true);
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: './doraemon/views',
partialsDir: './doraemon/views/partial',
layoutsDir: path.join(__dirname, 'doraemon/views'),
partialsDir: path.join(__dirname, 'doraemon/views/partial'),
views: path.join(__dirname, 'doraemon/views'),
helpers: global.yoho.helpers
}));
app.use(global.yoho.middleware());
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -17,12 +16,12 @@ app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,14 +5,12 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
var partials = path.join(__dirname, './views'); // parent view root
app.on('mount', function(parent) {
... ... @@ -20,16 +18,15 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [`${partials}/partial`, `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
// router
app.use(require('./router'));
... ...
... ... @@ -6,27 +6,24 @@
'use strict';
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
var partials = path.join(__dirname, './views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [`${partials}/partial`, `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: Object.assign(require('./helpers/pager'), global.yoho.helpers)
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -17,12 +16,13 @@ app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
'use strict';
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var passport = require('passport');
... ... @@ -20,12 +19,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -5,8 +5,7 @@
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
path = require('path');
var app = express();
... ... @@ -18,12 +17,12 @@ app.on('mount', function(parent) {
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
partialsDir: [path.join(__dirname, 'views/partial')],
views: path.join(__dirname, 'views/action'),
helpers: global.yoho.helpers
}));
... ...
... ... @@ -36,6 +36,7 @@
"captchapng": "0.0.1",
"connect-memcached": "^0.2.0",
"cookie-parser": "^1.4.3",
"cookie-session": "^1.2.0",
"express": "^4.13.1",
"handlebars": "^4.0.5",
"express-handlebars": "^3.0.0",
... ... @@ -62,7 +63,7 @@
"winston": "^2.2.0",
"winston-daily-rotate-file": "^1.1.4",
"yoho-express-session": "^1.14.1",
"yoho-node-lib": "0.1.19"
"yoho-node-lib": "0.1.23"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
... ... @@ -104,6 +105,7 @@
"yoho-handlebars": "^4.0.5",
"yoho-jquery": "^1.12.4",
"yoho-jquery-lazyload": "^1.9.7",
"yoho-jquery-pjax": "0.0.1",
"yoho-jquery-placeholder": "^2.3.1",
"yoho-slider": "0.0.2",
"yoho-jquery-dotdotdot": "0.0.1",
... ...