Permalink
Browse files

Integrate express-map and update npm dependencies

  • Loading branch information...
1 parent 1fab1b6 commit 140f55e7492543d875fd8bca9142bb6bd77c2af9 @ericf committed Aug 18, 2013
Showing with 19 additions and 25 deletions.
  1. +15 −22 app.js
  2. +2 −1 package.json
  3. +1 −1 shared/js/helpers.js
  4. +1 −1 views/layouts/main.handlebars
View
37 app.js
@@ -1,5 +1,6 @@
var express = require('express'),
- state = require('express-state'),
+ expmap = require('express-map'),
+ expstate = require('express-state'),
expyui = require('express-yui'),
Locator = require('locator'),
LocatorHandlebars = require('locator-handlebars'),
@@ -11,6 +12,10 @@ var express = require('express'),
app = express();
+expstate.extend(app);
+expmap.extend(app);
+expyui.extend(app);
+
app.set('name', config.name);
app.set('env', config.env);
app.set('port', config.port);
@@ -70,39 +75,27 @@ if (isDevelopment) {
// -- Routes -------------------------------------------------------------------
-routes = require('./routes');
-exposedRoutes = {};
-
-function exposeRoute(name) {
- var args = [].slice.call(arguments, 1),
- routes, route;
-
- app.get.apply(app, args);
-
- routes = app.routes.get;
- route = routes[routes.length -1];
+routes = require('./routes');
- exposedRoutes[name] = {
- path : route.path,
- keys : route.keys,
- regex: route.regexp
- };
+function mapRoute(name, path, callbacks) {
+ app.get(path, callbacks);
+ app.map(path, name);
}
-exposeRoute('index', '/', routes.index);
+mapRoute('index', '/', routes.index);
-exposeRoute('places', '/places/:id/', [
+mapRoute('places', '/places/:id/', [
routes.places.load,
routes.places.render
]);
-exposeRoute('photos', '/photos/:id/', [
+mapRoute('photos', '/photos/:id/', [
routes.photos.load,
routes.photos.render
]);
-PNM.ROUTES = exposedRoutes;
-app.expose(exposedRoutes, 'ROUTES');
+PNM.ROUTES = {routes: app.getRouteMap()};
+app.exposeRoutes('ROUTES');
// -- Locator and plugins ------------------------------------------------------
View
@@ -13,8 +13,9 @@
"dependencies": {
"express" : "3.3.x",
+ "express-map" : "latest",
"express-slash" : "latest",
- "express-state" : "latest",
+ "express-state" : "1.x",
"express-yui" : "latest",
"locator" : "latest",
"locator-handlebars" : "latest",
View
@@ -6,7 +6,7 @@ Y.namespace('PNM').Helpers = {
pathTo: function (routeName, context) {
context || (context = this);
- var route = PNM.ROUTES[routeName],
+ var route = PNM.ROUTES.routes[routeName],
path, keys;
if (!route) { return ''; }
@@ -46,7 +46,7 @@
// Setup routes.
Y.Array.each(app.namedRoutes, function (route, i) {
- var routeConfig = routeConfigs[route.name];
+ var routeConfig = routeConfigs.routes[route.name];
if (routeConfig) {
app.route(routeConfig.path, route.callbacks);
app.get('routes')[i].name = route.name;

0 comments on commit 140f55e

Please sign in to comment.