1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Remove Paloma.Router js

This commit is contained in:
kbparagua 2016-03-03 23:11:24 +08:00
parent 0a5f180e8f
commit 23e342f5bf
7 changed files with 10 additions and 114 deletions

View file

@ -10,7 +10,7 @@ feature 'executing Paloma controller', :js => true do
context 'default behavior' do
it 'executes the same namespace/controller/action' do
it 'executes the same namespace/controller#action' do
visit admin_foos_path
expect(

View file

@ -1,11 +1,8 @@
describe('Paloma.ControllerFactory', function(){
var router = new Paloma.Router({namespaceDelimiter: '/'});
describe('#make(name)', function(){
var factory = new Paloma.ControllerFactory(router),
var factory = new Paloma.ControllerFactory(),
Controller;
beforeEach(function(){
@ -27,7 +24,7 @@ describe('Paloma.ControllerFactory', function(){
describe('#get(name)', function(){
var factory = new Paloma.ControllerFactory(router),
var factory = new Paloma.ControllerFactory(),
Controller = factory.make('Foo');
describe('when controller exists', function(){

View file

@ -1,52 +0,0 @@
describe('Paloma.Router', function(){
var delimiter = '/',
router = new Paloma.Router({namespaceDelimiter: delimiter});
describe('#parse(path)', function(){
describe('when path has a namespace', function(){
var result;
beforeEach(function(){
result = router.parse('Foo/Bar/Baz/Controller');
});
it('returns the array of the namespaces', function(){
expect(result.namespaces).toEqual(['Foo', 'Bar', 'Baz']);
});
it('returns the controller', function(){
expect(result.controller).toEqual('Controller');
});
it('returns the controllerPath', function(){
expect(result.controllerPath).toEqual(['Foo', 'Bar', 'Baz', 'Controller']);
});
});
describe('when path has no namespace', function(){
var result;
beforeEach(function(){
result = router.parse('Controller');
});
it('returns an empty array of namespaces', function(){
expect(result.namespaces).toEqual([]);
});
it('returns the controller', function(){
expect(result.controller).toEqual('Controller');
});
it('returns the controllerPath', function(){
expect(result.controllerPath).toEqual(['Controller']);
});
});
});
});

View file

@ -1,36 +1,16 @@
Paloma.ControllerFactory = function(router){
this.instances = {};
this.router = router;
Paloma.ControllerFactory = function(){
this._controllers = {};
};
Paloma.ControllerFactory.prototype = {
make: function(name){
var config = this.router.parse(name),
scope = this.instances;
// Create namespaces.
for (var i = 0, n = config['namespaces'].length; i < n; i++){
var namespace = config['namespaces'][i];
scope[namespace] = scope[namespace] || {};
scope = scope[namespace];
}
return scope[config['controller']] = this._createConstructor();
this._controllers[name] = this._createConstructor();
return this.get(name);
},
get: function(name){
var config = this.router.parse(name),
scope = this.instances;
for (var i = 0, n = config['controllerPath'].length; i < n; i++){
var path = config['controllerPath'][i];
if (scope[path] != null){ scope = scope[path]; }
else { return null; }
}
return scope;
return this._controllers[name] || null;
},
_createConstructor: function(){

View file

@ -1,5 +1,4 @@
//= require ./init.js
//= require ./router.js
//= require ./controller.js
//= require ./controller_factory.js
//= require ./engine.js

View file

@ -1,7 +1,6 @@
(function(Paloma){
Paloma._router = new Paloma.Router({namespaceDelimiter: '/'});
Paloma._controllerFactory = new Paloma.ControllerFactory(Paloma._router);
Paloma._controllerFactory = new Paloma.ControllerFactory();
//
// Declare Paloma controllers using this method.

View file

@ -1,27 +0,0 @@
Paloma.Router = function(options){
options = options || {};
this.namespaceDelimiter = options.namespaceDelimiter;
if (!this.namespaceDelimiter)
throw "Paloma.Router: namespaceDelimiter option is required.";
};
Paloma.Router.prototype = {
parse: function(path){
var parts = path.split(this.namespaceDelimiter),
controller = parts.pop(),
namespaces = parts;
var controllerPath = namespaces.concat([controller]);
return {
controllerPath: controllerPath,
namespaces: namespaces,
controller: controller
};
}
};