1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00
This commit is contained in:
kbparagua 2013-10-12 18:18:08 +08:00
parent 55b98fed77
commit eb4a34210a
5 changed files with 68 additions and 69 deletions

View file

@ -18,11 +18,9 @@
for (var i = 0, len = requests.length; i < len; i++){
var request = requests[i];
Paloma.engine.requests.push({
resource: request['resource'],
action: request['action'],
params: request['params']
});
Paloma.engine.request(request['resource'],
request['action'],
request['params']);
}

View file

@ -15,8 +15,6 @@
//= require paloma
//= require_tree .
Paloma.config.ignoreMissingController = false;
var router = Paloma.router;
router.resource('RailsUser', {controller: 'User'});

View file

@ -0,0 +1,61 @@
(function(Paloma){
var Engine = function(config){
this.router = config.router;
this.factory = config.factory;
this.restart();
};
Engine.prototype.start = function(){
for (var i = 0, n = this.requests.length; i < n; i++){
var request = this.requests[i];
console.log('Processing request with params:');
console.log(request.params);
var controllerName = this.router.controllerFor(request.resource),
action = request.action,
redirect = this.router.redirectFor(request.resource, action);
if (redirect){
controllerName = redirect['controller'];
action = redirect['action'];
}
console.log('mapping <' + request.resource + '> to controller <' + controllerName + '>');
console.log('mapping action <' + request.action + '> to controller action <' + action + '>');
var Controller = this.factory.get(controllerName);
if (!Controller){
return console.warn('Paloma: undefined controller -> ' + controllerName);
}
var controller = new Controller(request.params);
if (!controller[action]){
return console.warn('Paloma: undefined action <' + action +
'> for <' + controllerName + '> controller');
}
controller[action]();
}
};
Engine.prototype.restart = function(){
this.requests = [];
};
Engine.prototype.request = function(resource, action, params){
this.requests.push({resource: resource,
action: action,
params: params});
};
Paloma.Engine = Engine;
})(window.Paloma);

View file

@ -2,4 +2,5 @@
//= require ./router.js
//= require ./controller.js
//= require ./controller_builder.js
//= require ./engine.js
//= require ./paloma.js

View file

@ -1,76 +1,17 @@
(function(Paloma){
Paloma.config = {};
// Defaults
Paloma.config.ignoreMissingController = true;
Paloma.router = new Paloma.Router({namespace: '/', action: '#'});
//
//
// Controller Interface.
//
//
Paloma._controllerFactory = new Paloma.ControllerFactory(Paloma.router);
Paloma.controller = function(name){
return Paloma._controllerFactory.get(name) ||
Paloma._controllerFactory.make(name);
};
Paloma.engine = new Paloma.Engine({router: Paloma.router,
factory: Paloma._controllerFactory});
//
//
// Request Interface.
//
//
Paloma.engine = {requests: []};
Paloma.engine.start = function(){
var requests = Paloma.engine.requests;
for (var i = 0, n = requests.length; i < n; i++){
var request = requests[i];
console.log('Processing request with params:');
console.log(request.params);
var controllerName = router.controllerFor(request.resource),
action = request.action,
redirect = router.redirectFor(request.resource, action);
if (redirect){
controllerName = redirect['controller'];
action = redirect['action'];
}
console.log('mapping <' + request.resource + '> to controller <' + controllerName + '>');
console.log('mapping action <' + request.action + '> to controller action <' + action + '>');
var Controller = Paloma._controllerFactory.get(controllerName);
if (!Controller){
return console.warn('Paloma: undefined controller -> ' + controllerName);
}
var controller = new Controller(request.params);
if (!controller[action]){
return console.warn('Paloma: undefined action <' + action +
'> for <' + controllerName + '> controller');
}
controller[action]();
}
};
})(window.Paloma);