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

Add a new --strict-route-template option to the route generator #20835

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,6 @@
<% if (addTitle) {%>import { pageTitle } from 'ember-page-title';

<%}%><template>
<% if (addTitle) {%>{{pageTitle "<%= routeName %>"}}
<%}%>{{outlet}}
</template>
16 changes: 16 additions & 0 deletions blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ module.exports = {
name: 'reset-namespace',
type: Boolean,
},
{
name: 'strict-route-template',
type: Boolean,
default: false,
aliases: ['strict'],
},
],

init() {
Expand Down Expand Up @@ -80,6 +86,16 @@ module.exports = {
};
},

files() {
let files = this._super.files.apply(this, arguments);

return files.filter((file) => {
const extensionToRemove = this.options.strictRouteTemplate ? '.hbs' : '.gts';

return !file.endsWith(extensionToRemove);
});
},

locals: function (options) {
let moduleName = options.entity.name;
let rawRouteName = moduleName.split('/').pop();
Expand Down
30 changes: 30 additions & 0 deletions node-tests/blueprints/route-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ describe('Blueprint: route', function () {
});
});

it('route foo --strict-route-template', function () {
return emberGenerateDestroy(['route', 'foo', '--strict-route-template'], (_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.gjs')).to.equal(fixture('route/strict-route-template.gjs'));
expect(_file('app/templates/foo.hbs')).to.not.exist;

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/default.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
}).then(() => {
expect(file('app/router.js')).to.not.contain("this.route('foo')");
});
});

it('route foo --strict', function () {
return emberGenerateDestroy(['route', 'foo', '--strict'], (_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.gjs')).to.equal(fixture('route/strict-route-template.gjs'));
expect(_file('app/templates/foo.hbs')).to.not.exist;

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/default.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
}).then(() => {
expect(file('app/router.js')).to.not.contain("this.route('foo')");
});
});

it('route foo --pod', function () {
return emberGenerateDestroy(['route', 'foo', '--pod'], (_file) => {
expect(_file('app/foo.js/route.js')).to.not.exist;
Expand Down
21 changes: 8 additions & 13 deletions node-tests/blueprints/template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,49 @@ describe('Blueprint: template', function () {
});
});

describe('with usePods', function () {
beforeEach(function () {
setupPodConfig({ usePods: true });
});

describe('with --pod', function () {
it('template foo', function () {
return emberGenerateDestroy(['template', 'foo'], (_file) => {
return emberGenerateDestroy(['template', 'foo', '--pod'], (_file) => {
expect(_file('app/foo/template.hbs')).to.equal('');
});
});

it('template foo.hbs', function () {
return emberGenerateDestroy(['template', 'foo.hbs'], (_file) => {
return emberGenerateDestroy(['template', 'foo.hbs', '--pod'], (_file) => {
expect(_file('app/foo.hbs/template.hbs')).to.not.exist;
expect(_file('app/foo/template.hbs')).to.equal('');
});
});

it('template foo/bar', function () {
return emberGenerateDestroy(['template', 'foo/bar'], (_file) => {
return emberGenerateDestroy(['template', 'foo/bar', '--pod'], (_file) => {
expect(_file('app/foo/bar/template.hbs')).to.equal('');
});
});
});

describe('with usePods + podModulePrefix', function () {
describe('with --pods + podModulePrefix', function () {
beforeEach(function () {
setupPodConfig({
usePods: true,
podModulePrefix: true,
});
});

it('template foo', function () {
return emberGenerateDestroy(['template', 'foo'], (_file) => {
return emberGenerateDestroy(['template', 'foo', '--pod'], (_file) => {
expect(_file('app/pods/foo/template.hbs')).to.equal('');
});
});

it('template foo.hbs', function () {
return emberGenerateDestroy(['template', 'foo.hbs'], (_file) => {
return emberGenerateDestroy(['template', 'foo.hbs', '--pod'], (_file) => {
expect(_file('app/pods/foo.hbs/template.hbs')).to.not.exist;
expect(_file('app/pods/foo/template.hbs')).to.equal('');
});
});

it('template foo/bar', function () {
return emberGenerateDestroy(['template', 'foo/bar'], (_file) => {
return emberGenerateDestroy(['template', 'foo/bar', '--pod'], (_file) => {
expect(_file('app/pods/foo/bar/template.hbs')).to.equal('');
});
});
Expand Down
6 changes: 6 additions & 0 deletions node-tests/fixtures/route/strict-route-template.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { pageTitle } from 'ember-page-title';

<template>
{{pageTitle "Foo"}}
{{outlet}}
</template>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"babel-plugin-ember-template-compilation": "^2.1.1",
"dag-map": "^2.0.2",
"decorator-transforms": "2.0.0",
"ember-cli": "^4.10.0",
"ember-cli": "^6.1.0",
"ember-cli-blueprint-test-helpers": "^0.19.2",
"ember-cli-browserstack": "^2.0.1",
"ember-cli-dependency-checker": "^3.3.1",
Expand Down
Loading