Skip to content

Commit

Permalink
removing redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
kethinov committed Oct 5, 2014
1 parent a80bdeb commit 29bc55b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "page.js-express-mapper.js",
"description": "Plugin for page.js which directly imitates the Express API.",
"author": "Eric Newport <[email protected]>",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/kethinov/page.js-express-mapper.js",
"license": "Creative Commons Attribution 4.0 International License",
"main": "page.js-express-mapper.js",
Expand Down
85 changes: 41 additions & 44 deletions page.js-express-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,54 @@
var app,
res;

if ('undefined' != typeof window) {
// renderMethod param
if (params.renderMethod && typeof params.renderMethod == 'function') {

// renderMethod param
if (params.renderMethod && typeof params.renderMethod == 'function') {
res = {
render: params.renderMethod, // template, model
redirect: function(route) {
page(route);
}
};

res = {
render: params.renderMethod, // template, model
redirect: function(route) {
page(route);
}
// overload page.js route prototype
page.Route.prototype.middleware = function(fn) {
var self = this;
return function(ctx, next) {
if (self.match(ctx.path, ctx.params)) return fn(ctx, res, next);
next();
};
};
}

// overload page.js route prototype
page.Route.prototype.middleware = function(fn) {
var self = this;
return function(ctx, next) {
if (self.match(ctx.path, ctx.params)) return fn(ctx, res, next);
next();
};
};
}

// customRouter param
if (params.customRouter) {
app = params.customRouter;
}
else {
app = {
route: function(route) {
return {
get: function(callback) {
page(route, callback);
},
post: function(callback) {
page(route, callback);
},
all: function(callback) {
page(route, callback);
}
// customRouter param
if (params.customRouter) {
app = params.customRouter;
}
else {
app = {
route: function(route) {
return {
get: function(callback) {
page(route, callback);
},
post: function(callback) {
page(route, callback);
},
all: function(callback) {
page(route, callback);
}
}
};
}
}
};
}

// expressAppName param
if (params.expressAppName && typeof params.expressAppName == 'string') {
window[params.expressAppName] = app;
}
else {
window.app = app;
}
// expressAppName param
if (params.expressAppName && typeof params.expressAppName == 'string') {
window[params.expressAppName] = app;
}
else {
window.app = app;
}
}

Expand Down

0 comments on commit 29bc55b

Please sign in to comment.