Skip to content

Commit

Permalink
Merge pull request #29 from bertdeblock/fix-generating-nested-documents
Browse files Browse the repository at this point in the history
Fix generating nested documents
  • Loading branch information
bertdeblock authored Apr 17, 2024
2 parents 9fd63d8 + 6cf4479 commit 0ce95f3
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 14 deletions.
8 changes: 4 additions & 4 deletions documents/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ root: "."
output: "**/*"
---

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

```gjs
<template>{{"{{"}}yield{{"}}"}}</template>
```

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

```gjs
import Component from "@glimmer/component";
Expand All @@ -22,7 +22,7 @@ export default class {{inputs.name.pascal}} extends Component {
```

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

```gts
import type { TOC } from '@ember/component/template-only';
Expand All @@ -41,7 +41,7 @@ export default {{inputs.name.pascal}};
```

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

```gts
import Component from "@glimmer/component";
Expand Down
8 changes: 4 additions & 4 deletions documents/helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root: "."
output: "**/*"
---

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

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

```

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

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

```

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

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

```

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

```ts
import Helper from "@ember/component/helper";
Expand Down
8 changes: 4 additions & 4 deletions documents/modifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root: "."
output: "**/*"
---

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

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

```

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

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

```

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

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

```

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

```ts
import Modifier from "ember-modifier";
Expand Down
4 changes: 2 additions & 2 deletions documents/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root: "."
output: "**/*"
---

# {{inputs.name.kebab}}.{{inputs.typescript ? "ts" : "js"}}
# {{inputs.name.path}}.{{inputs.typescript ? "ts" : "js"}}

```ts
import Service from "@ember/service";
Expand All @@ -13,7 +13,7 @@ export default class {{inputs.name.pascal}} extends Service {}
{{if inputs.typescript}}
declare module "@ember/service" {
interface Registry {
"{{inputs.name.kebab}}": {{inputs.name.pascal}};
"{{inputs.name.path}}": {{inputs.name.pascal}};
}
}
{{end}}
Expand Down
4 changes: 4 additions & 0 deletions src/generate-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export async function generateDocument(
camel: camelCase(entityName),
kebab: kebabCase(entityName),
pascal: pascalCase(entityName),
path: entityName
.split("/")
.map((part) => kebabCase(part))
.join("/"),
raw: entityName,
},
signature: pascalCase(entityName) + "Signature",
Expand Down
5 changes: 5 additions & 0 deletions test/__snapshots__/generate-component.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default class Foo extends Component<FooSignature> {
"
`;
exports[`generates a nested template-only \`.gjs\` component 1`] = `
"<template>{{yield}}</template>
"
`;
exports[`generates a template-only \`.gjs\` component 1`] = `
"<template>{{yield}}</template>
"
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/generate-helper.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ export default helper<FooSignature>(function foo(positional, named) {
});
"
`;
exports[`generates a nested function-based \`.js\` helper 1`] = `
"import { helper } from "@ember/component/helper";
export default helper(function fooBar(positional, named) {
return positional;
});
"
`;
7 changes: 7 additions & 0 deletions test/__snapshots__/generate-modifier.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ export interface FooSignature {
export default modifier<FooSignature>(function foo(element, positional, named) {});
"
`;
exports[`generates a nested function-based \`.js\` modifier 1`] = `
"import { modifier } from "ember-modifier";
export default modifier(function fooBar(element, positional, named) {});
"
`;
7 changes: 7 additions & 0 deletions test/__snapshots__/generate-service.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ declare module "@ember/service" {
}
"
`;

exports[`generates a nested \`.js\` service 1`] = `
"import Service from "@ember/service";
export default class FooBar extends Service {}
"
`;
13 changes: 13 additions & 0 deletions test/generate-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ it("generates a template-only `.gts` component at a custom path", async (ctx) =>

ctx.expect(content).toMatchSnapshot();
});

it("generates a nested template-only `.gjs` component", async (ctx) => {
cwd = await copyBlueprint("v2-addon");

await generateComponent("foo/bar", { cwd });

const content = await readFile(
join(cwd, "src/components/foo/bar.gjs"),
"utf-8",
);

ctx.expect(content).toMatchSnapshot();
});
10 changes: 10 additions & 0 deletions test/generate-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ it("generates a function-based `.ts` helper at a custom path", async (ctx) => {

ctx.expect(content).toMatchSnapshot();
});

it("generates a nested function-based `.js` helper", async (ctx) => {
cwd = await copyBlueprint("v2-addon");

await generateHelper("foo/bar", { cwd });

const content = await readFile(join(cwd, "src/helpers/foo/bar.js"), "utf-8");

ctx.expect(content).toMatchSnapshot();
});
13 changes: 13 additions & 0 deletions test/generate-modifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ it("generates a function-based `.ts` modifier at a custom path", async (ctx) =>

ctx.expect(content).toMatchSnapshot();
});

it("generates a nested function-based `.js` modifier", async (ctx) => {
cwd = await copyBlueprint("v2-addon");

await generateModifier("foo/bar", { cwd });

const content = await readFile(
join(cwd, "src/modifiers/foo/bar.js"),
"utf-8",
);

ctx.expect(content).toMatchSnapshot();
});
10 changes: 10 additions & 0 deletions test/generate-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ it("generates a `.ts` service at a custom path", async (ctx) => {

ctx.expect(content).toMatchSnapshot();
});

it("generates a nested `.js` service", async (ctx) => {
cwd = await copyBlueprint("v2-addon");

await generateService("foo/bar", { cwd });

const content = await readFile(join(cwd, "src/services/foo/bar.js"), "utf-8");

ctx.expect(content).toMatchSnapshot();
});

0 comments on commit 0ce95f3

Please sign in to comment.