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
Show file tree
Hide file tree
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
Next Next commit
Support some-name-element.js -> <app-some-name>
  • Loading branch information
codergeek121 committed Dec 3, 2024
commit 8a3fa4f8ecdf9cb436c1260e6557d23e21b2227c
2 changes: 1 addition & 1 deletion app/assets/javascript/custom_elements-rails.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function eagerDefineCustomElementsFrom(namespace, options = {}) {
const importmap = document.querySelector('script[type="importmap"]')
const { imports } = JSON.parse(importmap.textContent)
const regex = new RegExp(`${namespace}\/(.*?)_element`)
const regex = new RegExp(`${namespace}\/(.*?)[_-]element`)
Object.entries(imports)
.filter(([name, _]) => name.match(regex) )
.map(([name, importPath]) => [name.match(regex)[1].replace('_', '-'), importPath])
Expand Down
6 changes: 6 additions & 0 deletions test/custom_elements/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ class CustomElements::IntegrationTest < ApplicationSystemTestCase

assert_text "connectedCallback(): foo_bar_element.js"
end

test "some-name-element.js connects" do
visit elements_path

assert_text "connectedCallback(): some-name-element.js"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default class extends HTMLElement {
constructor() {
super()
}

connectedCallback() {
this.textContent = "connectedCallback(): some-name-element.js"
}
}
1 change: 1 addition & 0 deletions test/dummy/app/views/elements/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

<app-hello></app-hello>
<app-foo-bar></app-foo-bar>
<app-some-name></app-some-name>