Permalink
Browse files

Modified the request, controller and action methods

  • Loading branch information...
1 parent ec25f11 commit b66f9b6f4a74df56a3fbe73c9bfb3e1d09536799 @fk1blow committed Jun 1, 2011
Showing with 56 additions and 40 deletions.
  1. +1 −0 lib/Config.js
  2. +6 −7 lib/Controller/BaseController.js
  3. +49 −33 lib/Controller/Validator.js
View
@@ -10,6 +10,7 @@ var paths = {
'models': APP_PATH + '/models',
'vendors': ROOT_PATH + '/vendor',
'config': ROOT_PATH + '/config',
+ 'public': ROOT_PATH + '/public',
'error_template': '' // If the path is not defined, the default one will be set
}
@@ -1,16 +1,15 @@
-var ActionRouter = require('./ActionRouter');
-var View = require('../View/View');
+var ActiveRouter = require('../Router/ActiveRouter'),
+ View = require('../View/View'),
+ Request = require('../Http/Request');
var BaseController = Klass({
attributes: {
- url: function() { return ActionRouter.getUrl() },
+ controller_name: function() { return ActiveRouter.getControllerName() },
- params: function() { return ActionRouter.getParams() },
+ action_name: function() { return ActiveRouter.getActionName() },
- controller_name: function() { return ActionRouter.getControllerName() },
-
- action_name: function() { return ActionRouter.getActionName() }
+ request: function() { return Request.Factory() }
},
methods: {
@@ -1,42 +1,58 @@
-var Validator = Klass({
- statics: {
- rules: {
- 'controller_name': /[a-z]+/,
- 'controller_object': /^[A-Z]{1}[a-zA-Z]+/,
- 'action_name': /[a-z]+/
- },
-
- controllerObject: function(val) {
- return this.rules.controller_object.test(val);
- },
-
- controllerName: function(val) {
- return this.rules.controller_name.test(val);
- },
-
- actionName: function(val) {
- return this.rules.action_name.test(val);
- }
+var Validator = {
+ rules: {
+ 'controller_name': /[a-z]+/,
+ 'controller_object': /^[A-Z]{1}[a-zA-Z]+/,
+ 'action_name': /[a-z]+/
+ },
+
+ controllerObject: function(val) {
+ return this.rules.controller_object.test(val);
+ },
+
+ controllerName: function(val) {
+ return this.rules.controller_name.test(val);
+ },
+
+ actionName: function(val) {
+ return this.rules.action_name.test(val);
}
-});
+};
-var ControllerValidator = Klass({
- statics: {
+var ControllerValidator = {
aliases: {
- 'c_n': 'controllerName',
- 'c_o': 'controllerObject',
- 'a_n': 'actionName'
- },
-
- validate: function(what, on) {
- var m = this.aliases[what];
- if(m) {
- return Validator[m].call(Validator, on);
- }
+ 'c_n': 'controllerName',
+ 'c_o': 'controllerObject',
+ 'a_n': 'actionName'
+ },
+
+ validate: function(what, on) {
+ var m = this.aliases[what];
+ if(m) {
+ return Validator[m].call(Validator, on);
}
}
-});
+};
module.exports = ControllerValidator;
+
+
+
+/*
+ _validateNames: function() {
+ var cn_valid = Validator.validate('c_n', this.controller.default_name);
+ var co_valid = Validator.validate('c_o', this.controller.object_name);
+ var an_valid = Validator.validate('a_n', this.controller.action);
+
+ if(!cn_valid) {
+ throw new Error('Invalid controller route name:: ' + this.controller.default_name);
+ }
+ if(!co_valid) {
+ throw new Error('Invalid controller object name:: ' + this.controller.object_name);
+ }
+ if(!an_valid) {
+ throw new Error('Invalid action name:: ' + this.controller.action);
+ }
+ },
+*/

0 comments on commit b66f9b6

Please sign in to comment.