Skip to content

Commit

Permalink
feat: removed auto component namespaceing
Browse files Browse the repository at this point in the history
  • Loading branch information
webark committed Dec 18, 2021
1 parent 1d4e982 commit 15951b7
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/colocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
return {
baseName: registry.app.name,
getCssExtentions: registry.extensionsForType.bind(registry, 'css'),
forceMoveColocatedStyles: this.isAddon() || false,
forceMoveColocatedStyles: this.isAddon(),
};
},

Expand Down
1 change: 1 addition & 0 deletions packages/namespace/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

module.exports = {
singleQuote: true,

};
Empty file removed packages/namespace/addon/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import addRouteStyleNamespace from 'ember-cli-styles-namespace/utils/add-route-style-namespace';
import addComponentStyleNamespace from 'ember-cli-styles-namespace/utils/add-component-style-namespace';
import processStyleType from 'ember-cli-styles-namespace/utils/process-style-type';

export function initialize(appInstance) {
processStyleType(appInstance);

let router = appInstance.lookup('service:router');
router.on('routeDidChange', function ({ to }) {
if (likeRouteInfo(to)) {
Expand All @@ -20,8 +22,6 @@ export function initialize(appInstance) {
}
}
});

addComponentStyleNamespace(appInstance);
}

function nestedRouteNames({ name, parent }, routeNames = []) {
Expand Down
Empty file removed packages/namespace/app/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion packages/namespace/lib/style-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class StyleInfo extends Walker {
}

fileContents(styleNamespace) {
return `export default { styleNamespace: "${styleNamespace}" }`;
return `export const styleNamespace = "${styleNamespace}"`;
}

fullStylePath(stylePath) {
Expand Down
28 changes: 28 additions & 0 deletions packages/namespace/tests/acceptance/with-component-file-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';

import styleForSetup from 'dummy/tests/setup/style-for';

module('Acceptance | with component file', function (hooks) {
setupApplicationTest(hooks);
styleForSetup(hooks);

test('should be able import styleNamespace in a glimmer component', async function (assert) {
await visit('/with-component-file');

assert.strictEqual(
this.styleFor(`h3:first-of-type`).color,
'rgb(255, 0, 1)'
);
});

test('should be able import styleNamespace in a classic component', async function (assert) {
await visit('/with-component-file');

assert.strictEqual(
this.styleFor(`h3:last-of-type`).color,
'rgb(255, 0, 1)'
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h3> Hello There </h3>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable ember/require-tagless-components */
/* eslint-disable ember/no-classic-classes */
/* eslint-disable ember/no-classic-components */

import Component from '@ember/component';
import { styleNamespace } from './generic.scss';

export default Component.extend({
styleNamespace: styleNamespace,
classNameBindings: ['styleNamespace'],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h3 {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="{{style-namespace runClass=this.styleNamespace}}">
<h3> Hello There </h3>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@glimmer/component';
import { styleNamespace } from './generic.scss';

export default class WithComponentFileGlimmer extends Component {
styleNamespace = styleNamespace;
}
2 changes: 2 additions & 0 deletions packages/namespace/tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ Router.map(function () {
this.route('handled');
});

this.route('with-component-file');

this.route('aborted-state');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<WithComponentFile::glimmer></WithComponentFile::glimmer>
<WithComponentFile::classic></WithComponentFile::classic>

0 comments on commit 15951b7

Please sign in to comment.