Skip to content

Support more filenames + folders #10

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

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Add docs
  • Loading branch information
codergeek121 committed Dec 3, 2024
commit 6342f8e28efc31a91a824f85c7a8187e863ddac8
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,33 @@ custom_elements/hello_element.js // will register <app-hello> automatically

Your `*_element.js` files have to `export default` custom elements for this to work properly.

> [!WARNING]
> Only single word elements are supported currently. See https://github.com/codergeek121/custom_elements-rails/issues/1
### Naming Convention for Custom Elements

When defining custom elements from files, their filenames are used to generate the element names automatically. The following rules and examples clarify how file paths are converted to custom element names:

#### Usage

Register all files in the `custom_elements` folder as custom elements using a prefix (e.g., `app`):

```js
eagerDefineCustomElementsFrom("custom_elements", { prefix: "app" });
```

#### Conversion Rules

- Filenames are transformed into kebab-case (lowercase with hyphens).
- Words are separated by underscores (`_`) or hyphens (`-`) in the filename.
- The folder structure is reflected in the name using double hyphens (`--`) to separate folder names from the file name.
- A prefix (e.g., `app`) is added to the beginning of each custom element name.

#### Examples

| Filepath | Generated Custom Element Name |
|-------------------------------------|--------------------------------|
| `custom_elements/demo_element.js` | `<app-demo>` |
| `custom_elements/demo-element.js` | `<app-demo>` |
| `custom_elements/foo_bar_element.js`| `<app-foo-bar>` |
| `custom_elements/folder/foo_bar_element.js` | `<app-folder--foo-bar>` |

## Add a custom element with the built-in generator

Expand Down
Loading