mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Engine
This commit is contained in:
parent
55b98fed77
commit
eb4a34210a
5 changed files with 68 additions and 69 deletions
|
@ -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']);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
//= require paloma
|
||||
//= require_tree .
|
||||
|
||||
Paloma.config.ignoreMissingController = false;
|
||||
|
||||
var router = Paloma.router;
|
||||
|
||||
router.resource('RailsUser', {controller: 'User'});
|
||||
|
|
61
vendor/assets/javascripts/paloma/engine.js
vendored
Normal file
61
vendor/assets/javascripts/paloma/engine.js
vendored
Normal 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);
|
1
vendor/assets/javascripts/paloma/index.js
vendored
1
vendor/assets/javascripts/paloma/index.js
vendored
|
@ -2,4 +2,5 @@
|
|||
//= require ./router.js
|
||||
//= require ./controller.js
|
||||
//= require ./controller_builder.js
|
||||
//= require ./engine.js
|
||||
//= require ./paloma.js
|
65
vendor/assets/javascripts/paloma/paloma.js
vendored
65
vendor/assets/javascripts/paloma/paloma.js
vendored
|
@ -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);
|
Loading…
Reference in a new issue