Skip to content

Commit 379832d

Browse files
committed
Add a new --route-authoring-format argument to the route generator
This allows users to generate .gjs/.gts templates instead of .hbs templates.
1 parent e50c80e commit 379832d

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-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>

blueprints/route/index.js

Lines changed: 15 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,15 @@ module.exports = {
8086
};
8187
},
8288

89+
files() {
90+
const files = this._super.files.apply(this, arguments);
91+
const extensionToRemove = this.options.routeAuthoringFormat === 'strict' ? '.hbs' : '.gts';
92+
93+
return files.filter((file) => {
94+
return !file.endsWith(extensionToRemove);
95+
});
96+
},
97+
8398
locals: function (options) {
8499
let moduleName = options.entity.name;
85100
let rawRouteName = moduleName.split('/').pop();

node-tests/blueprints/route-test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,64 @@ 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/default.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/default.js'));
178+
179+
expect(file('app/router.js')).to.contain("this.route('foo')");
180+
});
181+
});
182+
183+
it('route foo --route-authoring-format loose', function () {
184+
return emberGenerateDestroy(
185+
['route', 'foo', '--route-authoring-format', 'loose'],
186+
(_file) => {
187+
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));
188+
189+
expect(_file('app/templates/foo.hbs')).to.equal('{{page-title "Foo"}}\n{{outlet}}');
190+
191+
expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/default.js'));
192+
193+
expect(file('app/router.js')).to.contain("this.route('foo')");
194+
}
195+
);
196+
});
197+
198+
it('route foo --loose', function () {
199+
return emberGenerateDestroy(['route', 'foo', '--loose'], (_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/default.js'));
205+
206+
expect(file('app/router.js')).to.contain("this.route('foo')");
207+
});
208+
});
209+
152210
it('route foo --pod', function () {
153211
return emberGenerateDestroy(['route', 'foo', '--pod'], (_file) => {
154212
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>

0 commit comments

Comments
 (0)