Skip to content

Commit b5cb84d

Browse files
Windviskategengler
authored andcommitted
Add a new --route-authoring-format argument to the route generator
This allows users to generate .gjs/.gts templates instead of .hbs templates. (cherry picked from commit d38d1a7)
1 parent 03cf322 commit b5cb84d

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<% if (addTitle) {%>import { pageTitle } from 'ember-page-title';
2+
3+
<%}%><template>
4+
<% if (addTitle) {%>{{pageTitle "<%= routeName %>"}}
5+
<%}%>{{outlet}}
6+
</template>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { TOC } from '@ember/component/template-only';
2+
<% if (addTitle) {%>import { pageTitle } from 'ember-page-title';<%}%>
3+
4+
interface <%= routeName %>Signature {
5+
Args: {
6+
model: unknown;
7+
controller: unknown;
8+
};
9+
}
10+
11+
<template>
12+
<% if (addTitle) {%>{{pageTitle "<%= routeName %>"}}
13+
<%}%>{{outlet}}
14+
</template> satisfies TOC<<%= routeName %>Signature>;

blueprints/route/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module.exports = {
2929
name: 'reset-namespace',
3030
type: Boolean,
3131
},
32+
{
33+
name: 'route-authoring-format',
34+
type: ['loose', 'strict'],
35+
default: 'loose',
36+
aliases: [{ loose: 'loose' }, { strict: 'strict' }],
37+
},
3238
],
3339

3440
init() {
@@ -80,6 +86,23 @@ module.exports = {
8086
};
8187
},
8288

89+
files() {
90+
let files = this._super.files.apply(this, arguments);
91+
92+
if (this.options.routeAuthoringFormat === 'strict') {
93+
const strictFilesToRemove =
94+
this.options.isTypeScriptProject || this.options.typescript ? '.gjs' : '.gts';
95+
files = files.filter(
96+
(file) =>
97+
!(file.endsWith('.js') || file.endsWith('.hbs') || file.endsWith(strictFilesToRemove))
98+
);
99+
} else {
100+
files = files.filter((file) => !(file.endsWith('.gjs') || file.endsWith('.gts')));
101+
}
102+
103+
return files;
104+
},
105+
83106
locals: function (options) {
84107
let moduleName = options.entity.name;
85108
let rawRouteName = moduleName.split('/').pop();

node-tests/blueprints/route-test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,77 @@ describe('Blueprint: route', function () {
149149
});
150150
});
151151

152+
it('route foo --route-authoring-format strict', function () {
153+
return emberGenerateDestroy(
154+
['route', 'foo', '--route-authoring-format', 'strict'],
155+
(_file) => {
156+
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));
157+
158+
expect(_file('app/templates/foo.gjs')).to.equal(
159+
fixture('route/strict-route-template.gjs')
160+
);
161+
expect(_file('app/templates/foo.hbs')).to.not.exist;
162+
163+
expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));
164+
165+
expect(file('app/router.js')).to.contain("this.route('foo')");
166+
}
167+
);
168+
});
169+
170+
it('route foo --strict', function () {
171+
return emberGenerateDestroy(['route', 'foo', '--strict'], (_file) => {
172+
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));
173+
174+
expect(_file('app/templates/foo.gjs')).to.equal(fixture('route/strict-route-template.gjs'));
175+
expect(_file('app/templates/foo.hbs')).to.not.exist;
176+
177+
expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));
178+
179+
expect(file('app/router.js')).to.contain("this.route('foo')");
180+
});
181+
});
182+
183+
it('route foo --strict --typescript', function () {
184+
return emberGenerateDestroy(['route', 'foo', '--strict', '--typescript'], (_file) => {
185+
expect(_file('app/routes/foo.ts')).to.equal(fixture('route/route.js'));
186+
187+
expect(_file('app/templates/foo.gts')).to.equal(fixture('route/strict-route-template.gts'));
188+
expect(_file('app/templates/foo.hbs')).to.not.exist;
189+
190+
expect(_file('tests/unit/routes/foo-test.ts')).to.equal(fixture('route-test/app.js'));
191+
192+
expect(file('app/router.js')).to.contain("this.route('foo')");
193+
});
194+
});
195+
196+
it('route foo --route-authoring-format loose', function () {
197+
return emberGenerateDestroy(
198+
['route', 'foo', '--route-authoring-format', 'loose'],
199+
(_file) => {
200+
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));
201+
202+
expect(_file('app/templates/foo.hbs')).to.equal('{{page-title "Foo"}}\n{{outlet}}');
203+
204+
expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));
205+
206+
expect(file('app/router.js')).to.contain("this.route('foo')");
207+
}
208+
);
209+
});
210+
211+
it('route foo --loose', function () {
212+
return emberGenerateDestroy(['route', 'foo', '--loose'], (_file) => {
213+
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));
214+
215+
expect(_file('app/templates/foo.hbs')).to.equal('{{page-title "Foo"}}\n{{outlet}}');
216+
217+
expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));
218+
219+
expect(file('app/router.js')).to.contain("this.route('foo')");
220+
});
221+
});
222+
152223
it('route foo --pod', function () {
153224
return emberGenerateDestroy(['route', 'foo', '--pod'], (_file) => {
154225
expect(_file('app/foo.js/route.js')).to.not.exist;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { pageTitle } from 'ember-page-title';
2+
3+
<template>
4+
{{pageTitle "Foo"}}
5+
{{outlet}}
6+
</template>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { TOC } from '@ember/component/template-only';
2+
import { pageTitle } from 'ember-page-title';
3+
4+
interface FooSignature {
5+
Args: {
6+
model: unknown;
7+
controller: unknown;
8+
};
9+
}
10+
11+
<template>
12+
{{pageTitle "Foo"}}
13+
{{outlet}}
14+
</template> satisfies TOC<FooSignature>;

0 commit comments

Comments
 (0)