Skip to content

Commit

Permalink
version 1.1.86
Browse files Browse the repository at this point in the history
  • Loading branch information
dgofman committed Dec 21, 2015
1 parent 3312476 commit e1f2ee7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions examples/account/libs/custom-reqmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var indigo = require(__appDir + '/indigo');
module.exports = function(appconf) {
var reqmodel = indigo.libs('reqmodel')(appconf);

return function(req, contextPath, next) {
reqmodel(req, contextPath, function() {
return function(contextPath, req, res, next) {
reqmodel(contextPath, req, res, function() {
req.model.baseStaticUrl = '/static';
req.model.imageBaseUrl = contextPath + req.model.baseStaticUrl + '/images';
next();
Expand Down
4 changes: 2 additions & 2 deletions indigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var indigo =

//http://localhost:8585/indigo/account/en/templates/login
app.use('/indigo/:routerPath/:locale/templates/:pageId', function(req, res) {
reqModel(req, null, function() {
reqModel(null, req, res, function() {
locales.init(req, req.params.locale);

var url = '/' + req.session.locale + '/templates/' + req.params.routerPath + '/' + req.params.pageId + '.html',
Expand Down Expand Up @@ -320,7 +320,7 @@ var indigo =
};

if (!req.model) {
req.model = reqModel(req, null, next);
req.model = reqModel(null, req, res, next);
} else {
next();
}
Expand Down
2 changes: 1 addition & 1 deletion libs/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var errorHandler = function() {
var self = this;
app.use(function(req, res, next) {
if (!req.headers.referer) {
indigo.reqModel(req, null, function() {
indigo.reqModel(null, req, res, function() {
self.render({statusCode: 404}, req, res, next);
});
} else {
Expand Down
6 changes: 3 additions & 3 deletions libs/reqmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
* module.exports = function(appconf) {
* var reqmodel = indigo.libs('reqmodel')(appconf);
*
* return function(req, contextPath, next) {
* reqmodel(req, contextPath, function() {
* return function(contextPath, req, res, next) {
* reqmodel(contextPath, req, res, function() {
* req.model.newModelKey = 'newModelValue';
* next();
* });
Expand All @@ -68,7 +68,7 @@ function reqmodel(appconf) {
env = env || 'dev';
minify = env === 'dev' ? '' : '.min';

return function(req, contextPath, next) {
return function(contextPath, req, res, next) {
req.model = {
req: req,
environment: env,
Expand Down
2 changes: 1 addition & 1 deletion libs/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var routers =
.all(function(req, res, next) {
debug(req.method, req.url, req.originalUrl);
req.moduleWebDir = router.moduleWebDir;
reqModel(req, conf.base, next);
reqModel(conf.base, req, res, next);
})[method](callback);
};
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indigojs",
"version": "1.1.85",
"version": "1.1.86",
"description": "IndigoJS is an open source, JavaScript/NodeJS localization framework",
"main": "indigo.js",
"scripts": {
Expand Down
43 changes: 21 additions & 22 deletions test/unittest/indigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,29 @@ describe('UnitTests Indigo APIs', function () {
});

it('should test RU locale', function (done) {
var req = {
baseUrl: '/indigojs',
params: {
countryCode: 'ru'
var locales = null,
req = {
baseUrl: '/indigojs',
params: {
countryCode: 'ru'
},
session: {},
headers: {
'accept-language': acceptLanguage
}
},
session: {},
headers: {
'accept-language': acceptLanguage
}
};
require(__appDir + '/libs/reqmodel')(indigo.appconf)(req, null, function() {
var locales = null,
res = {
render: function(url, model) {
assert.equal(model.contextPath, '/indigojs');
assert.equal(model.locality.locale, 'ru');
assert.equal(model.locality.langugage, 'ru');
assert.equal(locales.account.greeting, 'Здравствуйте');
done();
}
};

res = {
render: function(url, model) {
assert.equal(model.contextPath, '/indigojs');
assert.equal(model.locality.locale, 'ru');
assert.equal(model.locality.langugage, 'ru');
assert.equal(locales.account.greeting, 'Здравствуйте');
done();
}
};

require(__appDir + '/libs/reqmodel')(indigo.appconf)(null, req, res, function() {
locales = indigo.getLocale(req, 'countryCode'); //req.params.countryCode

indigo.render(req, res, '/login', locales);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/unittest/libs/reqmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('libs/reqmodel', function () {

it('should assign to default dev environment', function (done) {
var req = {baseUrl: '/indigojs'};
reqmodel(appconf)(req, null, function() {
reqmodel(appconf)(null, req, null, function() {
assert.equal(req.model.contextPath, '/indigojs');
assert.equal(req.model.environment, 'dev');
assert.equal(req.model.minify, '');
Expand All @@ -23,7 +23,7 @@ describe('libs/reqmodel', function () {
it('should verify environment is dev', function (done) {
appconf.environment = 'dev';
var req = {baseUrl: '/indigojs'};
reqmodel(appconf)(req, '/newBaseURL', function() {
reqmodel(appconf)('/newBaseURL', req, null, function() {
assert.equal(req.model.contextPath, '/newBaseURL');
assert.equal(req.model.environment, 'dev');
assert.equal(req.model.minify, '');
Expand All @@ -36,7 +36,7 @@ describe('libs/reqmodel', function () {
it('should verify environment is prod', function (done) {
appconf.environment = 'prod';
var req = {baseUrl: '/indigojs'};
reqmodel(appconf)(req, null, function() {
reqmodel(appconf)(null, req, null, function() {
assert.equal(req.model.environment, 'prod');
assert.equal(req.model.minify, '.min');
assert.equal(req.model.extCSS, '.min.css');
Expand All @@ -50,7 +50,7 @@ describe('libs/reqmodel', function () {
env = process.env.NODE_ENV;
appconf.environment = 'dev';
process.env.NODE_ENV = 'production';
reqmodel(appconf)(req, null, function() {
reqmodel(appconf)(null, req, null, function() {
assert.equal(req.model.environment, 'prod');
assert.equal(req.model.minify, '.min');
assert.equal(req.model.extCSS, '.min.css');
Expand Down

0 comments on commit e1f2ee7

Please sign in to comment.