Skip to content

Commit

Permalink
feat(extensable identifier): moved the geration of the namespace iden…
Browse files Browse the repository at this point in the history
…tifier and if the class should be added to a mixin for easier exensability
  • Loading branch information
webark committed Feb 23, 2017
1 parent 24d03ef commit e3c627b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
51 changes: 0 additions & 51 deletions addon/initializers/component-styles.js
Original file line number Diff line number Diff line change
@@ -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
};
21 changes: 21 additions & 0 deletions addon/mixins/style-namespacing-extras.js
Original file line number Diff line number Diff line change
@@ -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');
}
}),
});
45 changes: 44 additions & 1 deletion app/initializers/component-styles.js
Original file line number Diff line number Diff line change
@@ -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
};
1 change: 1 addition & 0 deletions app/mixins/style-namespacing-extras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-component-css/mixins/style-namespacing-extras';

0 comments on commit e3c627b

Please # to comment.