Skip to content

Commit d56b1ac

Browse files
committed
improvements
1 parent fc2e44a commit d56b1ac

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44

55
This gem adds a simple way to automatically register custom elements in your `importmap-rails` app. No build step required!
66

7-
- Supports `importmap-rails` v1 and v2.
8-
- Supports `rails` 7.0, 7.1 & 8.0.
7+
## Table of Contents
8+
9+
<details>
10+
<summary>Click to expand</summary>
11+
12+
- [Rails support](#rails-support)
13+
- [Installation](#installation)
14+
- [Generators](#generators)
15+
- [Documentation](#documentation)
16+
- [Contributing](#contributing)
17+
- [License](#license)
18+
19+
</details>
20+
21+
## Rails support
22+
23+
* Supports Rails 7.0, 7.1, 7.2 & 8.0
24+
* Supports `importmap-rails` 1 and 2
925

1026
## Installation
1127

@@ -29,7 +45,7 @@ $ rails custom_elements:install
2945

3046
This will setup and edit add the following files:
3147

32-
```
48+
```graphql
3349
app/javascript
3450
├── application.js
3551
└── custom_elements
@@ -43,13 +59,7 @@ You can generate a new custom element `<app-demo>` with `rails generate custom_e
4359

4460
### How It Works
4561

46-
The `custom_elements-rails` gem uses `eagerDefineCustomElementsFrom` to automatically register [custom elements](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) from the `custom_elements` folder. It reads the importmap from `importmap-rails` and registers elements using `customElements.define(...)`.
47-
48-
For example:
49-
50-
```
51-
custom_elements/hello_element.js // Automatically registers <app-hello>
52-
```
62+
The `custom_elements-rails` gem uses `eagerDefineCustomElementsFrom` to automatically register [custom elements](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) in the `custom_elements` folder. It parses the importmap generated by `importmap-rails` and registers custom elements using the `customElements.define(...)` API.
5363

5464
> [!IMPORTANT]
5565
> Make sure your `*_element.js` files use `export default` to define the custom elements.
@@ -67,7 +77,7 @@ eagerDefineCustomElementsFrom("custom_elements", { prefix: "app" });
6777
```
6878

6979
| Filepath | Generated Custom Element Name |
70-
|-------------------------------------|--------------------------------|
80+
|:-----------------------------------:|:------------------------------:|
7181
| `custom_elements/demo_element.js` | `<app-demo>` |
7282
| `custom_elements/demo-element.js` | `<app-demo>` |
7383
| `custom_elements/foo_bar_element.js`| `<app-foo-bar>` |
@@ -79,7 +89,7 @@ eagerDefineCustomElementsFrom("custom_elements", { prefix: "app" });
7989
- The folder structure is reflected in the name using double hyphens (`--`) to separate folder names from the file name.
8090
- A [configurable prefix](#documentation) is added to the beginning of each custom element name.
8191

82-
## Add a custom element with the built-in generator
92+
## Generators
8393

8494
This gem adds a generator to generate new custom elements with:
8595

@@ -144,7 +154,9 @@ Currently supported optional `options`:
144154

145155
## Contributing
146156

147-
TODO
157+
1. Fork the repository.
158+
2. Create a feature branch.
159+
3. Submit a pull request with a detailed description of changes.
148160

149161
## License
150162

0 commit comments

Comments
 (0)