From e3c627b1aa9250262ddb07ee66f307ff7212619e Mon Sep 17 00:00:00 2001 From: Mark David Avery Date: Wed, 22 Feb 2017 16:30:31 -0800 Subject: [PATCH] feat(extensable identifier): moved the geration of the namespace identifier and if the class should be added to a mixin for easier exensability --- addon/initializers/component-styles.js | 51 ------------------------ addon/mixins/style-namespacing-extras.js | 21 ++++++++++ app/initializers/component-styles.js | 45 ++++++++++++++++++++- app/mixins/style-namespacing-extras.js | 1 + 4 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 addon/mixins/style-namespacing-extras.js create mode 100644 app/mixins/style-namespacing-extras.js diff --git a/addon/initializers/component-styles.js b/addon/initializers/component-styles.js index 65a03cb..e69de29 100644 --- a/addon/initializers/component-styles.js +++ b/addon/initializers/component-styles.js @@ -1,51 +0,0 @@ -import Ember from 'ember'; -import podNames from 'ember-component-css/pod-names'; - -const { - Component, - ComponentLookup, - computed, - getOwner -} = Ember; - -ComponentLookup.reopen({ - componentFor(name, owner) { - owner = owner.hasRegistration ? owner : getOwner(this); - - if (podNames[name] && !owner.hasRegistration(`component:${name}`)) { - owner.register(`component:${name}`, Component); - } - return this._super(...arguments); - } -}); - -Component.reopen({ - _componentIdentifier: computed({ - get() { - return (this._debugContainerKey || '').replace('component:', ''); - } - }), - - componentCssClassName: computed({ - get() { - return podNames[this.get('_componentIdentifier')] || ''; - } - }), - - init() { - this._super(...arguments); - - let name = this.get('componentCssClassName'); - - if (this.get('tagName') !== '' && name) { - this.classNames = this.classNames.concat(name); - } - } -}); - -export function initialize() {} - -export default { - name: 'component-styles', - initialize -}; diff --git a/addon/mixins/style-namespacing-extras.js b/addon/mixins/style-namespacing-extras.js new file mode 100644 index 0000000..4a83293 --- /dev/null +++ b/addon/mixins/style-namespacing-extras.js @@ -0,0 +1,21 @@ +import Ember from 'ember'; + +const { + Component, + computed, + Mixin, +} = Ember; + +export default Mixin.create({ + _componentIdentifier: computed({ + get() { + return (this._debugContainerKey || '').replace('component:', ''); + } + }), + + _shouldAddNamespacedClassName: computed({ + get() { + return this.get('tagName') !== '' && this.get('componentCssClassName'); + } + }), +}); diff --git a/app/initializers/component-styles.js b/app/initializers/component-styles.js index 5d7697d..edf9ea7 100644 --- a/app/initializers/component-styles.js +++ b/app/initializers/component-styles.js @@ -1 +1,44 @@ -export { default, initialize } from 'ember-component-css/initializers/component-styles'; +import Ember from 'ember'; +import podNames from 'ember-component-css/pod-names'; +import StyleNamespacingExtras from '../mixins/style-namespacing-extras'; + +const { + Component, + ComponentLookup, + computed, + getOwner +} = Ember; + +ComponentLookup.reopen({ + componentFor(name, owner) { + owner = owner.hasRegistration ? owner : getOwner(this); + + if (podNames[name] && !owner.hasRegistration(`component:${name}`)) { + owner.register(`component:${name}`, Component); + } + return this._super(...arguments); + } +}); + +Component.reopen(StyleNamespacingExtras, { + componentCssClassName: computed({ + get() { + return podNames[this.get('_componentIdentifier')] || ''; + } + }), + + init() { + this._super(...arguments); + + if (this.get('_shouldAddNamespacedClassName')) { + this.classNames = this.classNames.concat(this.get('componentCssClassName')); + } + } +}); + +export function initialize() {} + +export default { + name: 'component-styles', + initialize +}; diff --git a/app/mixins/style-namespacing-extras.js b/app/mixins/style-namespacing-extras.js new file mode 100644 index 0000000..cd281d0 --- /dev/null +++ b/app/mixins/style-namespacing-extras.js @@ -0,0 +1 @@ +export { default } from 'ember-component-css/mixins/style-namespacing-extras';