Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Modified the request, controller and action methods
  • Loading branch information
fk1blow committed Jun 1, 2011
1 parent ec25f11 commit b66f9b6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
1 change: 1 addition & 0 deletions lib/Config.js
Expand Up @@ -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
}

Expand Down
13 changes: 6 additions & 7 deletions lib/Controller/BaseController.js
@@ -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: {
Expand Down
82 changes: 49 additions & 33 deletions lib/Controller/Validator.js
@@ -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.