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-template option to the route generator #20835

Open
wants to merge 4 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>
15 changes: 15 additions & 0 deletions blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module.exports = {
name: 'reset-namespace',
type: Boolean,
},
{
name: 'strict-template',
Copy link
Contributor Author

@Windvis Windvis Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best name for the option. Suggestions?

The component version is called --strict. We could use the same setup here, but in that case it will no longer be possible to only use strict templates for components but not routes by adding the option to the ember-cli config file. Both would then be strict by default. Not sure if we want these to be separate or not.

type: Boolean,
default: false,
},
],

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

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

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

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

locals: function (options) {
let moduleName = options.entity.name;
let rawRouteName = moduleName.split('/').pop();
Expand Down
25 changes: 25 additions & 0 deletions node-tests/blueprints/route-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const fixture = require('../helpers/fixture');
const setupTestEnvironment = require('../helpers/setup-test-environment');
const enableOctane = setupTestEnvironment.enableOctane;

// TODO: move to a fixture
const routeTemplateWithPageTitle = `\
import { pageTitle } from 'ember-page-title';

<template>
{{pageTitle "Foo"}}
{{outlet}}
</template>
`;

describe('Blueprint: route', function () {
setupTestHooks(this);

Expand Down Expand Up @@ -167,6 +177,21 @@ describe('Blueprint: route', function () {
});
});

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

expect(_file('app/templates/foo.gjs')).to.equal(routeTemplateWithPageTitle);
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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 Expand Up @@ -396,7 +396,7 @@
},
"packageManager": "pnpm@8.10.0",
"volta": {
"node": "16.20.0",
"node": "18.20.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 16 support was already dropped (#20716) so this simply updates the volta config to match that.

Without this the content-tag package doesn't work correctly (Webassembly related errors).

"pnpm": "8.10.0"
}
}
Loading
Loading