|
1 | | -# Very WIP Prettier Support for Ember template tags |
| 1 | +# prettier-plugin-ember-template-tag |
2 | 2 |
|
3 | | -## Try it out |
| 3 | +[](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/actions/workflows/ci.yml) |
| 4 | +[](https://www.npmjs.com/package/prettier-plugin-ember-template-tag) |
| 5 | +[](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/blob/main/LICENSE.md) |
4 | 6 |
|
5 | | -1. Edit `example.gjs` or `example.gts` to make the ugliest component file you can think of. |
6 | | -1. Run `pnpm run example > temp.gjs` or `pnpm run example-ts > temp.gts` |
| 7 | +A [Prettier](https://prettier.io/) plugin for formatting [Ember template tags](https://rfcs.emberjs.com/id/0779-first-class-component-templates/). |
7 | 8 |
|
8 | | -## Prior art and useful links |
| 9 | +## Usage |
9 | 10 |
|
10 | | -https://prettier.io/docs/en/plugins.html#developing-plugins |
| 11 | +1. Install: |
11 | 12 |
|
12 | | -https://medium.com/@fvictorio/how-to-write-a-plugin-for-prettier-a0d98c845e70 |
| 13 | + NPM: |
13 | 14 |
|
14 | | -https://github.com/ember-template-imports/ember-template-imports/blob/master/src/preprocess-embedded-templates.ts#L180 |
| 15 | + ```bash |
| 16 | + npm install --save-dev prettier prettier-plugin-ember-template-tag |
| 17 | + ``` |
15 | 18 |
|
16 | | -https://github.com/ember-template-imports/ember-template-imports/blob/master/src/parse-templates.ts |
| 19 | + Yarn: |
17 | 20 |
|
18 | | -https://github.com/glimmerjs/glimmer-experimental/tree/master/packages/%40glimmerx/prettier-plugin-component-templates |
| 21 | + ```bash |
| 22 | + yarn add --save-dev prettier prettier-plugin-ember-template-tag |
| 23 | + ``` |
19 | 24 |
|
20 | | -https://github.com/ember-template-lint/ember-template-lint/pull/2483/files |
| 25 | + PNPM: |
21 | 26 |
|
22 | | -https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAtgBwgJxgAgGEItoECAzHE-AcgAEBzAGw3ThwHpJSpzaA3AB0oI-PgDaAfSkBxADIBJALLKAogCUpAFTXKACvICCugBQADEWPwAeABYBGAHzj8ACTjNmEfAHVczAAm+A7unt5+AcEOHl4+-jhBIbERCUkx4fFRyZmRidEpWfk5cXnphWXR4jacjk4i5gA0+MD4AM4wOKhgMMoQgXBI+J0ArnD4AL4AlAC6VlCQUB346CPMMKisfPgAvJIyCirqWroGxmaWolDVda4VacEATGGlD-iP99kfuW-fr1+fYp-VIAn5faq1ZwNZqtDpdHp9AZDUbjaZzK6cABUmLEmPwRmucAAHgBDLDMcayABSAGV8BRNuNoPgAO52bp2VnjMAk644EbXGB2cb6HBwGAbDj03D4al0zDMEaMVBQAB0uM4ImJ2Dw+AGFBJawIYGYJLabXwygAnsReORrMT4FBAhbbdg+LAWtZpHIlKpNDo9IYTGoLNYbs47mDigBmF4g2OApIxpPBFPR5Op-Dp-6JjNpiF1axNFrtTrdXr9QbDfmo2bzcRskkEPbmeDk5vjVjwHAk5jDOzN-CoC1QCAEEnDOAd+CXBuuBecTj4ABWI2Wk9Y-Z47FgIgmIEaIAgmA20DayFAJJw1BZ+mvCAvKD7LJJVovR4ARr2wABrcU0mScDyCqcDIAazBtHAX4-v+MA0pgJJgCqjDICiR7Tp+cCBAMgTyLyjAjCSjBwAAYrg6DNhsUCoc+IwwBAh4gHYMDoMwvjsvAbSIWAcA0o+qAbAAboJVrIOA5pMSqUF4KKxGUeBfZQUeK5tESNIoRSACKIzjmBSAQcpICITgMniZ+JJYcwTGYF0sC+KggRCsgAAcAAMR62RAUG+L2mDibZcAyUJYFHgAjrp8CiieT4gGaAC0fDYdhTFihFqBinJjAKQZSnQSAUHoKgaG1kebSaXAOl6YpkH5TAlkOU5djII8R6dCSmwobaOUgEFACsTHrnA2iWU+hn5UJYyKM65A0mAXSngSgQ0jAVoUjVUETBMQA |
| 27 | + ```bash |
| 28 | + pnpm add --save-dev prettier prettier-plugin-ember-template-tag |
| 29 | + ``` |
23 | 30 |
|
24 | | -https://github.com/prettier/prettier/blob/main/commands.md |
| 31 | +1. Configure with [prettierrc](https://prettier.io/docs/en/configuration.html): |
25 | 32 |
|
26 | | -## Tests |
| 33 | + ```js |
| 34 | + // .prettierrc.js |
| 35 | + module.exports = { |
| 36 | + // ... |
| 37 | + plugins: ['prettier-plugin-ember-template-tag'], |
| 38 | + }; |
| 39 | + ``` |
27 | 40 |
|
28 | | -`pnpm test` |
| 41 | +1. Run `npm prettier --write .` |
29 | 42 |
|
30 | | -## TODOs and known issues |
| 43 | +## Ignoring code |
31 | 44 |
|
32 | | -- [ ] Fix HAX |
33 | | -- [ ] Add tests |
34 | | -- [ ] Verify quotes configuration works properly |
| 45 | +Because gts/gjs files include both JavaScript and Glimmer template code, you'll need to use the appropriate prettier-ignore comment for the code you are ignoring: |
| 46 | + |
| 47 | +```js |
| 48 | +export default class MyComponent extends Component { |
| 49 | + // prettier-ignore |
| 50 | + cells = matrix( |
| 51 | + 1, 0, 0, |
| 52 | + 0, 1, 0, |
| 53 | + 0, 0, 1 |
| 54 | + ) |
| 55 | + |
| 56 | + <template> |
| 57 | + {{! prettier-ignore }} |
| 58 | + {{#each cells as |cell|}}{{cell.contents}}{{/each}} |
| 59 | + </template> |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +To ignore the entire template, use a JavaScript `//prettier-ignore` comment before the opening `<template>` tag: |
| 64 | + |
| 65 | +```js |
| 66 | +export default class MyComponent extends Component { |
| 67 | + // prettier-ignore |
| 68 | + <template> |
| 69 | + This whole template is ignored |
| 70 | + <MyUglyComponent "shall" be="preserved"> |
| 71 | + <ThisPart |
| 72 | + is = "also preserved as is" |
| 73 | + /> |
| 74 | + </MyUglyComponent> |
| 75 | + </template> |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +## Bugs |
| 80 | + |
| 81 | +If there are errors, please file a bug report so that they can be fixed. |
| 82 | + |
| 83 | +TODO: Process |
| 84 | + |
| 85 | +## Opinions |
| 86 | + |
| 87 | +TODO: link to RFC |
| 88 | + |
| 89 | +<!-- TODO: ### Configuration |
| 90 | +
|
| 91 | +These configuration options are available in addition to [Prettier's standard |
| 92 | +config for JavaScript files](https://prettier.io/docs/en/configuration.html). |
| 93 | +
|
| 94 | +| Name | Default | Description | |
| 95 | +| --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ | |
| 96 | +| `templatePrintWidth` | `80` | [Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags | |
| 97 | +| `templateSingleQuote` | `false` | Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags | --> |
| 98 | + |
| 99 | +<!-- ## Editor integration |
| 100 | +
|
| 101 | +### VScode |
| 102 | +
|
| 103 | +TODO --> |
0 commit comments