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

RFC: Short templates in the top-level-of-a-class position #193

Closed
gitKrystan opened this issue Dec 6, 2023 · 6 comments · Fixed by #194
Closed

RFC: Short templates in the top-level-of-a-class position #193

gitKrystan opened this issue Dec 6, 2023 · 6 comments · Fixed by #194

Comments

@gitKrystan
Copy link
Collaborator

Vote by reacting to this issue. Comment with more details below. Do you prefer:

Option A (🚀)

This is what v2.0.0-0 is currently returning.

export default class MyComponent extends Component {
  <template>Hey shorty</template>
}

Option B (👎)

This is what v1 currently returns.

export default class MyComponent extends Component {
  <template>
    Hey shorty
  </template>
}

Caveats

Neither of these solutions address the issue that whitespace matters in html. 🙈 I haven't had any issues reported here about whitespace causing issues so I am choosing to ignore that for now.

@NullVoxPopuli
Copy link
Member

NullVoxPopuli commented Dec 6, 2023

Option A, less text nodes.
Also, very few templates will be one line.

If there is an element in there tho, option b

@IgnaceMaes
Copy link

Relevant RFC looking to address the whitespace difference: emberjs/rfcs#982

As mentioned by @NullVoxPopuli, would this imply a template with a single element would also be on one line as follows?

export default class MyComponent extends Component {
  <template><h1>Hey shorty</h1></template>
}

Or would it then switch to a new line?

export default class MyComponent extends Component {
  <template>
    <h1>Hey shorty</h1>
  </template>
}

Because for that case I also would prefer option b.

@gitKrystan
Copy link
Collaborator Author

As mentioned by @NullVoxPopuli, would this imply a template with a single element would also be on one line as follows?

In the current implementation, yes.

@NullVoxPopuli
Copy link
Member

oh, I'd prefer the link breaks then

@gossi
Copy link

gossi commented Dec 7, 2023

trying v2 right now, which is producing one-liners with html tags is not giving the visual cue for the template I'm trying to find.

the short version is nice for tests though 😇

@gitKrystan
Copy link
Collaborator Author

gitKrystan commented Dec 28, 2023

Update:

I got this working, which is how the JSX formatter works:

One line if there is no tag:

<template>Hey shorty</template>

Multi lines if there is a tag:

<template>
  <h1>Hey shorty</h1>
</template>

Multi lines if there is a block and you wrote the block as multiline:

<template>
  {{#if true}}
    Hey shorty
  {{/if}}
</template>

One line in this case too:

<template>{{if true 'Hey shorty'}}</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants