Permalink
Browse files

loading components from /piejs/pie/libs/controller/components/ and /p…

…iejs/app/controllers/components/

Going to work on Auth next!
  • Loading branch information...
1 parent 1175000 commit 2490ca2fd574072129af1a6c1cf059f60a966720 @fakewaffle committed Aug 19, 2011
No changes.
View
@@ -1,10 +1,12 @@
exports.boot = function(callback) {
loadDataSources();
loadModels();
- loadControllers();
loadPieHelpers();
loadAppHelpers();
-
+ loadPieComponents();
+ loadAppComponents();
+ loadControllers();
+
callback();
}
@@ -63,21 +65,21 @@ var loadModels = function() {
}
/**
- * Load the names of the controllers in /piejs/app/controllers into pie.app.controllers
+ * Load the controllers in /piejs/app/controllers into pie.app.controllers
*
* Dispatcher will test whether a called controller is available.
*
* @author Justin Morris
* @created 2011-06-13 16.11.38
*/
var loadControllers = function() {
- var files = pie.fs.readdirSync(pie.paths.app.controllers);
+ var files = pie.fs.readdirSync(pie.paths.app.controllers.path);
files.forEach(function(file) {
if (file.split('.')[1] === 'js') {
var controllerFileName = file.split('.')[0];
var controllerName = Inflector.camelize(controllerFileName);
- var controller = require(pie.paths.app.controllers + controllerFileName);
+ var controller = require(pie.paths.app.controllers.path + controllerFileName);
pie.app.controllers[controllerName] = controller;
}
@@ -90,7 +92,7 @@ var loadControllers = function() {
}
/**
- * Load the names of the helpers for Pie that are located in /piejs/pie/view/helpers/
+ * Load the helpers for Pie that are located in /piejs/pie/view/helpers/
*
* @author Justin Morris
* @created 2011-06-13 16.49.17
@@ -110,7 +112,7 @@ var loadPieHelpers = function() {
}
/**
- * Load the names of the helpers for the App that are located in /piejs/app/views/helpers/
+ * Load the helpers for the App that are located in /piejs/app/views/helpers/
*
* @author Justin Morris
* @created 2011-06-13 16.58.17
@@ -127,4 +129,45 @@ var loadAppHelpers = function() {
pie.app.helpers[helperName] = helper[helperName];
}
});
+}
+
+/**
+ * Load the components for Pie that are located in /piejs/pie/controller/components/
+ *
+ * @author Justin Morris
+ * @created 2011-08-18 22.23.46
+ */
+var loadPieComponents = function() {
+ var files = pie.fs.readdirSync(pie.paths.pie.controller.components);
+
+ files.forEach(function(file) {
+ if (file.split('.')[1] === 'js') {
+ var componentFileName = file.split('.')[0];
+ var componentName = Inflector.camelize(componentFileName);
+ var component = require(pie.paths.pie.controller.components + componentFileName);
+
+ pie.pie.components[componentName] = component[componentName];
+ }
+ });
+
+}
+
+/**
+ * Load the componentName for the App that are located in /piejs/app/controllers/components/
+ *
+ * @author Justin Morris
+ * @created 2011-08-18 22.38.08
+ */
+var loadAppComponents = function() {
+ var files = pie.fs.readdirSync(pie.paths.app.controllers.components);
+
+ files.forEach(function(file) {
+ if (file.split('.')[1] === 'js') {
+ var componentFileName = file.split('.')[0];
+ var componentName = Inflector.camelize(componentFileName);
+ var component = require(pie.paths.app.controllers.components + componentFileName);
+
+ pie.app.components[componentName] = component[componentName];
+ }
+ });
}
View
@@ -117,7 +117,7 @@ var handleAppControllerAction = function(request, response, next) {
}
if (requestedController && requestedAction) {
- var controllerFile = pie.paths.app.controllers + requestedController + '_controller';
+ var controllerFile = pie.paths.app.controllers.path + requestedController + '_controller';
var controller = false;
// Check whether the requested controller exists
No changes.
@@ -10,11 +10,12 @@
* @created 2011-05-17 23.16.13
*/
function Controller(params) {
- var self = this;
- this.name = params.name;
- this[this.name] = pie.app.models[this.name];
- this.webroot = pie.config.app.core.webroot;
- this.requestedHelpers = params.helpers;
+ var self = this;
+ this.name = params.name;
+ this[this.name] = pie.app.models[this.name];
+ this.webroot = pie.config.app.core.webroot;
+ this.requestedHelpers = params.helpers;
+ this.requestedComponents = params.components;
if (typeof this[this.name] !== 'undefined') {
if (typeof this[this.name].belongsTo !== 'undefined' && this[this.name].belongsTo) {
@@ -29,6 +30,24 @@ function Controller(params) {
});
}
}
+
+ if (typeof this.requestedComponents !== 'undefined' && this.requestedComponents) {
+ Object.keys(self.requestedComponents).forEach(function(key) {
+ var requestedComponent = self.requestedComponents[key];
+ var componentFile = Inflector.underscore(requestedComponent) + '.js';
+ var Component = null;
+
+ if (typeof pie.pie.components[requestedComponent] !== 'undefined') {
+ Component = pie.pie.components[requestedComponent];
+ }
+
+ if (typeof pie.app.components[requestedComponent] !== 'undefined') {
+ Component = pie.app.components[requestedComponent];
+ }
+
+ self[requestedComponent] = new Component(self.name);
+ });
+ }
}
/**
@@ -62,8 +81,6 @@ Controller.prototype.set = function(request, response, results, layout) {
var requestedHelper = self.requestedHelpers[key];
var helperFile = Inflector.underscore(requestedHelper) + '.js';
var Helper = null;
- var PieHelper = null;
- var AppHelper = null;
if (typeof pie.pie.helpers[requestedHelper] !== 'undefined') {
Helper = pie.pie.helpers[requestedHelper];
View
@@ -3,7 +3,8 @@ exports.paths = {
'boot' : __piedirname + '/pie/boot.js',
'controller' : {
'path' : __piedirname + '/pie/libs/controller/',
- 'controller' : __piedirname + '/pie/libs/controller/controller.js'
+ 'controller' : __piedirname + '/pie/libs/controller/controller.js',
+ 'components' : __piedirname + '/pie/libs/controller/components/'
},
'datasource' : {
'path' : __piedirname + '/pie/libs/model/datasources/',
@@ -33,7 +34,10 @@ exports.paths = {
'database' : __piedirname + '/app/config/database.js',
'routes' : __piedirname + '/app/config/routes.js'
},
- 'controllers' : __piedirname + '/app/controllers/',
+ 'controllers' : {
+ 'path' : __piedirname + '/app/controllers/',
+ 'components' : __piedirname + '/app/controllers/components/'
+ },
'models' : __piedirname + '/app/models/',
'public' : {
'path' : __piedirname + '/app/public/',

0 comments on commit 2490ca2

Please sign in to comment.