From 23e342f5bfeffb64d13595abc111cc7cb0223a76 Mon Sep 17 00:00:00 2001 From: kbparagua Date: Thu, 3 Mar 2016 23:11:24 +0800 Subject: [PATCH] Remove Paloma.Router js --- test_app/spec/integration/advanced_spec.rb | 2 +- .../javascripts/controller_factory_spec.js | 7 +-- test_app/spec/javascripts/router_spec.js | 52 ------------------- .../javascripts/paloma/controller_factory.js | 30 ++--------- vendor/assets/javascripts/paloma/index.js | 3 +- vendor/assets/javascripts/paloma/paloma.js | 3 +- vendor/assets/javascripts/paloma/router.js | 27 ---------- 7 files changed, 10 insertions(+), 114 deletions(-) delete mode 100644 test_app/spec/javascripts/router_spec.js delete mode 100644 vendor/assets/javascripts/paloma/router.js diff --git a/test_app/spec/integration/advanced_spec.rb b/test_app/spec/integration/advanced_spec.rb index c0d7cee..0dd7b8b 100644 --- a/test_app/spec/integration/advanced_spec.rb +++ b/test_app/spec/integration/advanced_spec.rb @@ -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( diff --git a/test_app/spec/javascripts/controller_factory_spec.js b/test_app/spec/javascripts/controller_factory_spec.js index 8b0c552..344bf2c 100644 --- a/test_app/spec/javascripts/controller_factory_spec.js +++ b/test_app/spec/javascripts/controller_factory_spec.js @@ -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(){ diff --git a/test_app/spec/javascripts/router_spec.js b/test_app/spec/javascripts/router_spec.js deleted file mode 100644 index b61b11c..0000000 --- a/test_app/spec/javascripts/router_spec.js +++ /dev/null @@ -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']); - }); - }); - - }); - -}); diff --git a/vendor/assets/javascripts/paloma/controller_factory.js b/vendor/assets/javascripts/paloma/controller_factory.js index 3e19622..cbed81f 100644 --- a/vendor/assets/javascripts/paloma/controller_factory.js +++ b/vendor/assets/javascripts/paloma/controller_factory.js @@ -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(){ diff --git a/vendor/assets/javascripts/paloma/index.js b/vendor/assets/javascripts/paloma/index.js index 8ccdeb3..6e9bc23 100644 --- a/vendor/assets/javascripts/paloma/index.js +++ b/vendor/assets/javascripts/paloma/index.js @@ -1,6 +1,5 @@ //= require ./init.js -//= require ./router.js //= require ./controller.js //= require ./controller_factory.js //= require ./engine.js -//= require ./paloma.js \ No newline at end of file +//= require ./paloma.js diff --git a/vendor/assets/javascripts/paloma/paloma.js b/vendor/assets/javascripts/paloma/paloma.js index da83e5e..c4516e4 100644 --- a/vendor/assets/javascripts/paloma/paloma.js +++ b/vendor/assets/javascripts/paloma/paloma.js @@ -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. diff --git a/vendor/assets/javascripts/paloma/router.js b/vendor/assets/javascripts/paloma/router.js deleted file mode 100644 index d6a3096..0000000 --- a/vendor/assets/javascripts/paloma/router.js +++ /dev/null @@ -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 - }; - } - -}; - -