Skip to content

Commit 0ce95f3

Browse files
authored
Merge pull request #29 from bertdeblock/fix-generating-nested-documents
Fix generating nested documents
2 parents 9fd63d8 + 6cf4479 commit 0ce95f3

13 files changed

+92
-14
lines changed

Diff for: documents/component.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ root: "."
44
output: "**/*"
55
---
66

7-
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.gjs
7+
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.path}}.gjs
88

99
```gjs
1010
<template>{{"{{"}}yield{{"}}"}}</template>
1111
1212
```
1313

14-
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.gjs
14+
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.path}}.gjs
1515

1616
```gjs
1717
import Component from "@glimmer/component";
@@ -22,7 +22,7 @@ export default class {{inputs.name.pascal}} extends Component {
2222
2323
```
2424

25-
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.gts
25+
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.path}}.gts
2626

2727
```gts
2828
import type { TOC } from '@ember/component/template-only';
@@ -41,7 +41,7 @@ export default {{inputs.name.pascal}};
4141
4242
```
4343

44-
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.gts
44+
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.path}}.gts
4545

4646
```gts
4747
import Component from "@glimmer/component";

Diff for: documents/helper.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root: "."
44
output: "**/*"
55
---
66

7-
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.js
7+
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.path}}.js
88

99
```js
1010
import { helper } from "@ember/component/helper";
@@ -15,7 +15,7 @@ export default helper(function {{inputs.name.camel}}(positional, named) {
1515

1616
```
1717

18-
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.js
18+
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.path}}.js
1919

2020
```js
2121
import Helper from "@ember/component/helper";
@@ -28,7 +28,7 @@ export default class {{inputs.name.pascal}} extends Helper {
2828

2929
```
3030

31-
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.ts
31+
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.path}}.ts
3232

3333
```ts
3434
import { helper } from "@ember/component/helper";
@@ -51,7 +51,7 @@ export default helper<{{inputs.signature}}>(function {{inputs.name.camel}}(posit
5151

5252
```
5353

54-
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.ts
54+
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.path}}.ts
5555

5656
```ts
5757
import Helper from "@ember/component/helper";

Diff for: documents/modifier.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root: "."
44
output: "**/*"
55
---
66

7-
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.kebab}}.js
7+
# {{inputs.typescript ? "!" : (inputs.classBased ? "!" : "")}}{{inputs.name.path}}.js
88

99
```js
1010
import { modifier } from "ember-modifier";
@@ -13,7 +13,7 @@ export default modifier(function {{inputs.name.camel}}(element, positional, name
1313

1414
```
1515

16-
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.kebab}}.js
16+
# {{inputs.typescript ? "!" : (inputs.classBased ? "" : "!")}}{{inputs.name.path}}.js
1717

1818
```js
1919
import Modifier from "ember-modifier";
@@ -24,7 +24,7 @@ export default class {{inputs.name.pascal}} extends Modifier {
2424

2525
```
2626

27-
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.kebab}}.ts
27+
# {{inputs.typescript ? (inputs.classBased ? "!" : "") : "!"}}{{inputs.name.path}}.ts
2828

2929
```ts
3030
import { modifier } from "ember-modifier";
@@ -41,7 +41,7 @@ export default modifier<{{inputs.signature}}>(function {{inputs.name.camel}}(ele
4141

4242
```
4343

44-
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.kebab}}.ts
44+
# {{inputs.typescript ? (inputs.classBased ? "" : "!") : "!"}}{{inputs.name.path}}.ts
4545

4646
```ts
4747
import Modifier from "ember-modifier";

Diff for: documents/service.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root: "."
44
output: "**/*"
55
---
66

7-
# {{inputs.name.kebab}}.{{inputs.typescript ? "ts" : "js"}}
7+
# {{inputs.name.path}}.{{inputs.typescript ? "ts" : "js"}}
88

99
```ts
1010
import Service from "@ember/service";
@@ -13,7 +13,7 @@ export default class {{inputs.name.pascal}} extends Service {}
1313
{{if inputs.typescript}}
1414
declare module "@ember/service" {
1515
interface Registry {
16-
"{{inputs.name.kebab}}": {{inputs.name.pascal}};
16+
"{{inputs.name.path}}": {{inputs.name.pascal}};
1717
}
1818
}
1919
{{end}}

Diff for: src/generate-document.ts

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export async function generateDocument(
3838
camel: camelCase(entityName),
3939
kebab: kebabCase(entityName),
4040
pascal: pascalCase(entityName),
41+
path: entityName
42+
.split("/")
43+
.map((part) => kebabCase(part))
44+
.join("/"),
4145
raw: entityName,
4246
},
4347
signature: pascalCase(entityName) + "Signature",

Diff for: test/__snapshots__/generate-component.test.ts.snap

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export default class Foo extends Component<FooSignature> {
2828
"
2929
`;
3030
31+
exports[`generates a nested template-only \`.gjs\` component 1`] = `
32+
"<template>{{yield}}</template>
33+
"
34+
`;
35+
3136
exports[`generates a template-only \`.gjs\` component 1`] = `
3237
"<template>{{yield}}</template>
3338
"

Diff for: test/__snapshots__/generate-helper.test.ts.snap

+9
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,12 @@ export default helper<FooSignature>(function foo(positional, named) {
9393
});
9494
"
9595
`;
96+
97+
exports[`generates a nested function-based \`.js\` helper 1`] = `
98+
"import { helper } from "@ember/component/helper";
99+
100+
export default helper(function fooBar(positional, named) {
101+
return positional;
102+
});
103+
"
104+
`;

Diff for: test/__snapshots__/generate-modifier.test.ts.snap

+7
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@ export interface FooSignature {
7373
export default modifier<FooSignature>(function foo(element, positional, named) {});
7474
"
7575
`;
76+
77+
exports[`generates a nested function-based \`.js\` modifier 1`] = `
78+
"import { modifier } from "ember-modifier";
79+
80+
export default modifier(function fooBar(element, positional, named) {});
81+
"
82+
`;

Diff for: test/__snapshots__/generate-service.test.ts.snap

+7
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ declare module "@ember/service" {
3939
}
4040
"
4141
`;
42+
43+
exports[`generates a nested \`.js\` service 1`] = `
44+
"import Service from "@ember/service";
45+
46+
export default class FooBar extends Service {}
47+
"
48+
`;

Diff for: test/generate-component.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ it("generates a template-only `.gts` component at a custom path", async (ctx) =>
7272

7373
ctx.expect(content).toMatchSnapshot();
7474
});
75+
76+
it("generates a nested template-only `.gjs` component", async (ctx) => {
77+
cwd = await copyBlueprint("v2-addon");
78+
79+
await generateComponent("foo/bar", { cwd });
80+
81+
const content = await readFile(
82+
join(cwd, "src/components/foo/bar.gjs"),
83+
"utf-8",
84+
);
85+
86+
ctx.expect(content).toMatchSnapshot();
87+
});

Diff for: test/generate-helper.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ it("generates a function-based `.ts` helper at a custom path", async (ctx) => {
7272

7373
ctx.expect(content).toMatchSnapshot();
7474
});
75+
76+
it("generates a nested function-based `.js` helper", async (ctx) => {
77+
cwd = await copyBlueprint("v2-addon");
78+
79+
await generateHelper("foo/bar", { cwd });
80+
81+
const content = await readFile(join(cwd, "src/helpers/foo/bar.js"), "utf-8");
82+
83+
ctx.expect(content).toMatchSnapshot();
84+
});

Diff for: test/generate-modifier.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ it("generates a function-based `.ts` modifier at a custom path", async (ctx) =>
7272

7373
ctx.expect(content).toMatchSnapshot();
7474
});
75+
76+
it("generates a nested function-based `.js` modifier", async (ctx) => {
77+
cwd = await copyBlueprint("v2-addon");
78+
79+
await generateModifier("foo/bar", { cwd });
80+
81+
const content = await readFile(
82+
join(cwd, "src/modifiers/foo/bar.js"),
83+
"utf-8",
84+
);
85+
86+
ctx.expect(content).toMatchSnapshot();
87+
});

Diff for: test/generate-service.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ it("generates a `.ts` service at a custom path", async (ctx) => {
4848

4949
ctx.expect(content).toMatchSnapshot();
5050
});
51+
52+
it("generates a nested `.js` service", async (ctx) => {
53+
cwd = await copyBlueprint("v2-addon");
54+
55+
await generateService("foo/bar", { cwd });
56+
57+
const content = await readFile(join(cwd, "src/services/foo/bar.js"), "utf-8");
58+
59+
ctx.expect(content).toMatchSnapshot();
60+
});

0 commit comments

Comments
 (0)