From 559c0a3d9f0b89201020403b2badf9eca52d9fe5 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 11 Jun 2015 13:37:26 -0800 Subject: [PATCH] Global injection --- app/initializers/global-variables.js | 19 +++++++++++++++ app/pods/application/adapter.js | 9 ++++--- app/pods/application/template.hbs | 4 +-- app/pods/components/genus-name/component.js | 5 ++-- app/pods/components/site-name/template.hbs | 1 + app/pods/user/adapter.js | 5 ++-- public/img/logo.png | Bin 1465 -> 0 bytes .../initializers/global-variables-test.js | 23 ++++++++++++++++++ .../components/site-name/component-test.js | 19 +++++++++++++++ 9 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 app/initializers/global-variables.js create mode 100644 app/pods/components/site-name/template.hbs delete mode 100755 public/img/logo.png create mode 100644 tests/unit/initializers/global-variables-test.js create mode 100644 tests/unit/pods/components/site-name/component-test.js diff --git a/app/initializers/global-variables.js b/app/initializers/global-variables.js new file mode 100644 index 0000000..c16d17e --- /dev/null +++ b/app/initializers/global-variables.js @@ -0,0 +1,19 @@ +import Ember from 'ember'; +import config from '../config/environment'; + +var globals = Ember.Object.extend({ + genus: config.genus, + apiURL: config.apiURL, +}); + +export function initialize(container, application) { + application.register('global:variables', globals, {singleton: true}); + application.inject('controller', 'globals', 'global:variables'); + application.inject('component', 'globals', 'global:variables'); + application.inject('adapter', 'globals', 'global:variables'); +} + +export default { + name: 'global-variables', + initialize: initialize +}; diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js index 2037ee8..e979dec 100644 --- a/app/pods/application/adapter.js +++ b/app/pods/application/adapter.js @@ -1,10 +1,13 @@ import DS from 'ember-data'; import Ember from 'ember'; -import config from '../../config/environment'; export default DS.RESTAdapter.extend({ - namespace: 'api/' + config.genus, - host: config.apiURL, + namespace: function() { + return 'api/' + this.get('globals.genus'); + }.property(), + host: function() { + return this.get('globals.apiURL'); + }.property(), coalesceFindRequests: true, ajaxError: function(jqXHR) { // http://stackoverflow.com/a/24027443 diff --git a/app/pods/application/template.hbs b/app/pods/application/template.hbs index 3d14835..486ad74 100644 --- a/app/pods/application/template.hbs +++ b/app/pods/application/template.hbs @@ -1,6 +1,6 @@
{{#link-to 'index' class='logo'}} - + {{site-name}} {{/link-to}} {{#if session.isAuthenticated}}