Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where PascalCase for strings with numbers was incorrect #151

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
order: 1
---

# Demo of DocfyLink component

[Link from a demo](../docfy-output.md)

```hbs template
<div data-test-id="demo-1">
This is my Demo:

<span class='hyphenated-demo'>Assertable DOM node</span>
<DocfyLink @to={{this.url}}>My Link</DocfyLink>
</div>
<div data-test-id="demo-1-js-data">{{this.url}}</div>
```

```js component
import Component from '@glimmer/component';

export default class MyDemo extends Component {
url = '/docs/ember/';
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
category: ember
subcategory: components
---

# Docfy With Hyphenated Number 2

Testing doc pages with numbers in their name and how that corresponds with
automatic component registration.
3 changes: 3 additions & 0 deletions packages/ember/src/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export function generateDemoComponentName(
.replace(/(\w)(\w*)/g, function (_, g1, g2) {
return `${g1.toUpperCase()}${g2.toLowerCase()}`;
})
.replace(/-(\d+)/g, function (_, g1) {
return `_${g1}`;
})
.replace(/-/g, '');

if (seenNames.has(dashCase)) {
Expand Down
12 changes: 12 additions & 0 deletions packages/ember/tests/acceptance/extracted-demos-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ module('Acceptance | extracted demos', function (hooks) {

assert.strictEqual(demosAll?.length, 2);
});

test('it correctly resolves demo components with hyphenated numbers', async function (assert) {
await visit('/docs/ember/components/docfy-with-hyphenated-number-2');

// Since this page has a hyphenated number in it, demo components must be transformed with
// preceding underscores like this:
// <DocfyDemoPackagesEmberComponentsDocfyWithHyphenatedNumber_2Demo1/>

assert
.dom('.docfy-demo__example .hyphenated-demo')
.hasText('Assertable DOM node');
});
});
2 changes: 1 addition & 1 deletion packages/ember/tests/fastboot/docs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module('FastBoot | docs', function (hooks) {
assert
.dom('[data-test-id="docs-nav"]')
.hasText(
'Welcome to Docfy Introduction Installation Overview @docfy/core Overview Helpers genereateFlatOutput genereateNestedOutput @docfy/ember Working with Ember Installation Components Docfy Link Component Docfy Output Component Plugins Manual Demo Insertion'
'Welcome to Docfy Introduction Installation Overview @docfy/core Overview Helpers genereateFlatOutput genereateNestedOutput @docfy/ember Working with Ember Installation Components Docfy Link Component Docfy Output Component Docfy With Hyphenated Number 2 Plugins Manual Demo Insertion'
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
assert
.dom('[data-test-id="flat-urls"]')
.hasText(
'/docs/ /docs/introduction /docs/installation /docs/overview /docs/core/overview /docs/core/helpers/genereate-flat-output /docs/core/helpers/genereate-nested-output /docs/ember/ /docs/ember/installation /docs/ember/components/docfy-link /docs/ember/components/docfy-output /docs/ember/plugins/manual-demo-insertion'
'/docs/ /docs/introduction /docs/installation /docs/overview /docs/core/overview /docs/core/helpers/genereate-flat-output /docs/core/helpers/genereate-nested-output /docs/ember/ /docs/ember/installation /docs/ember/components/docfy-link /docs/ember/components/docfy-output /docs/ember/components/docfy-with-hyphenated-number-2 /docs/ember/plugins/manual-demo-insertion'
);
});

Expand All @@ -69,11 +69,11 @@

test('it returns the page fromCurrentURL', async function (assert) {
const router = this.owner.lookup('router:main');
// @ts-ignore

Check warning on line 72 in packages/ember/tests/integration/components/docfy-output-test.ts

View workflow job for this annotation

GitHub Actions / Tests

Do not use "@ts-ignore" because it alters compilation errors
router.setupRouter();

const routerService = this.owner.lookup('service:router');
// @ts-ignore

Check warning on line 76 in packages/ember/tests/integration/components/docfy-output-test.ts

View workflow job for this annotation

GitHub Actions / Tests

Do not use "@ts-ignore" because it alters compilation errors
sinon.stub(routerService, 'currentURL').get(() => '/docs/installation');
this.set('fromCurrentURL', true);
await render(template);
Expand Down
2 changes: 2 additions & 0 deletions packages/ember/tests/unit/demo-component-generation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module('Unit | Demo component generation', function (hooks) {
// dummy/docs/packages/ember/components/docfy-link-demo/{demo-file}.md
has('packages-ember-components-docfy-link-demo1');
has('packages-ember-components-docfy-link-demo2');
// dummy/docs/packages/ember/components/docfy-with-hyphenated-number-2/{demo-file}.md
has('packages-ember-components-docfy-with-hyphenated-number-2-demo1');
// where do these come from?
has('preview-ember');
has('preview-ember1');
Expand Down
5 changes: 4 additions & 1 deletion packages/ember/tests/unit/services/docfy-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
test('it returns the page by current url', function (assert) {
const service = this.owner.lookup('service:docfy') as DocfyService;
const routerService = this.owner.lookup('service:router');
// @ts-ignore

Check warning on line 38 in packages/ember/tests/unit/services/docfy-test.ts

View workflow job for this annotation

GitHub Actions / Tests

Do not use "@ts-ignore" because it alters compilation errors
sinon.stub(routerService, 'currentURL').get(() => '/docs/installation');

assert.equal(service.currentPage?.title, 'Installation');
Expand Down Expand Up @@ -104,7 +104,7 @@
test('when current url is the first item', async function (assert) {
const service = this.owner.lookup('service:docfy') as DocfyService;
const routerService = this.owner.lookup('service:router');
// @ts-ignore

Check warning on line 107 in packages/ember/tests/unit/services/docfy-test.ts

View workflow job for this annotation

GitHub Actions / Tests

Do not use "@ts-ignore" because it alters compilation errors
sinon.stub(routerService, 'currentURL').get(() => '/docs/');

assert.equal(service.previousPage()?.title, undefined);
Expand All @@ -119,7 +119,10 @@
.stub(routerService, 'currentURL')
.get(() => '/docs/ember/plugins/manual-demo-insertion');

assert.equal(service.previousPage()?.title, 'Docfy Output Component');
assert.equal(
service.previousPage()?.title,
'Docfy With Hyphenated Number 2'
);
assert.equal(service.nextPage()?.title, undefined);
});

Expand Down
Loading