Skip to content

Commit

Permalink
Merge pull request #173 from alexindigo/master
Browse files Browse the repository at this point in the history
Made paths more consistent between client and server and friendly to RequireJS.
  • Loading branch information
Spike Brehm committed Nov 7, 2013
2 parents db67b73 + 3eb672d commit 69e408f
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ if (!this.window) {
return exports.server = new Server(options);
};

exports.entryPath = process.cwd();
exports.entryPath = process.cwd() + '/';
}
2 changes: 1 addition & 1 deletion server/middleware/initApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = require('underscore');
module.exports = function(appAttributes, options) {
options = options || {};
return function(req, res, next) {
var App = require(rendr.entryPath + '/app/app');
var App = require(rendr.entryPath + 'app/app');

/**
* Pass any data that needs to be accessible by the client
Expand Down
2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Server(options) {
* Tell Express to use our ViewEngine to handle .js, .coffee files.
* This can always be overridden in your app.
*/
this.expressApp.set('views', this.options.viewsPath || (rendr.entryPath + '/app/views'));
this.expressApp.set('views', this.options.viewsPath || (rendr.entryPath + 'app/views'));
this.expressApp.set('view engine', this.options.defaultEngine);
this.expressApp.engine(this.options.defaultEngine, this.viewEngine.render);

Expand Down
3 changes: 2 additions & 1 deletion shared/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Backbone = require('backbone');
Fetcher = require('./fetcher');

if (!global.isServer) {
ClientRouter = require(rendr.entryPath + "/app/router");
// client side only, entryPath is always empty
ClientRouter = require('app/router');
}

function noop() {}
Expand Down
4 changes: 2 additions & 2 deletions shared/base/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ BaseRouter.prototype._initOptions = function(options) {
this.options = options || {};
paths = this.options.paths = this.options.paths || {};
paths.entryPath = paths.entryPath || rendr.entryPath;
paths.routes = paths.routes || paths.entryPath + '/app/routes';
paths.controllerDir = paths.controllerDir || paths.entryPath + '/app/controllers';
paths.routes = paths.routes || paths.entryPath + 'app/routes';
paths.controllerDir = paths.controllerDir || paths.entryPath + 'app/controllers';
};

BaseRouter.prototype.getController = function(controllerName) {
Expand Down
2 changes: 1 addition & 1 deletion shared/base/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ module.exports = BaseView = Backbone.View.extend({
*/

BaseView.getView = function(viewName) {
return require(rendr.entryPath + "/app/views/" + viewName);
return require(rendr.entryPath + "app/views/" + viewName);
};

BaseView.attach = function(app, parentView) {
Expand Down
4 changes: 3 additions & 1 deletion shared/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ if (typeof window !== "undefined" && window !== null) {
};
} else {
global.isServer = true;
global.rendr = require('../index');
// hide it from requirejs since it's server only
var serverOnly_rendrIndex = '../index';
global.rendr = require(serverOnly_rendrIndex);
}
4 changes: 2 additions & 2 deletions shared/modelUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ utils.getCollection = function(path, models, options) {

utils.getModelConstructor = function(path) {
path = utils.underscorize(path);
return classMap[path] || require(rendr.entryPath + "/app/models/" + path);
return classMap[path] || require(rendr.entryPath + "app/models/" + path);
};

utils.getCollectionConstructor = function(path) {
path = utils.underscorize(path);
return classMap[path] || require(rendr.entryPath + "/app/collections/" + path);
return classMap[path] || require(rendr.entryPath + "app/collections/" + path);
};

utils.getConstructor = function(type, path) {
Expand Down
9 changes: 7 additions & 2 deletions shared/syncer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var _ = require('underscore')
};

if (global.isServer) {
var qs = require('qs');
// hide it from requirejs since it's server only
var serverOnly_qs = 'qs';
var qs = require(serverOnly_qs);
}

var syncer = module.exports;
Expand Down Expand Up @@ -164,7 +166,10 @@ syncer.checkFresh = function checkFresh() {
this.app.trigger('checkFresh:start');

// Lame: have to lazy-require to prevent circular dependency.
modelUtils = modelUtils || require('./modelUtils');
// It is circular dep
// hide it from requirejs since it's optional/lazy-loaded
var lazyRequire_modelUtils = './modelUtils';
modelUtils = modelUtils || require(lazyRequire_modelUtils);
url = this.getUrl(null, true);

$.getJSON(url, this.params, function(resp) {
Expand Down
2 changes: 1 addition & 1 deletion test/client/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ clientTestHelper = require('../helpers/client_test');
routerConfig = {
app: new App,
paths: {
entryPath: __dirname + "/../fixtures"
entryPath: __dirname + "/../fixtures/"
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/server/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sinon = require('sinon');

config = {
paths: {
entryPath: __dirname + "/../fixtures"
entryPath: __dirname + "/../fixtures/"
}
};

Expand Down

0 comments on commit 69e408f

Please sign in to comment.