Skip to content

Commit 8a3fa4f

Browse files
committed
Support some-name-element.js -> <app-some-name>
1 parent 6b188e7 commit 8a3fa4f

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

app/assets/javascript/custom_elements-rails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export function eagerDefineCustomElementsFrom(namespace, options = {}) {
22
const importmap = document.querySelector('script[type="importmap"]')
33
const { imports } = JSON.parse(importmap.textContent)
4-
const regex = new RegExp(`${namespace}\/(.*?)_element`)
4+
const regex = new RegExp(`${namespace}\/(.*?)[_-]element`)
55
Object.entries(imports)
66
.filter(([name, _]) => name.match(regex) )
77
.map(([name, importPath]) => [name.match(regex)[1].replace('_', '-'), importPath])

test/custom_elements/integration_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ class CustomElements::IntegrationTest < ApplicationSystemTestCase
1212

1313
assert_text "connectedCallback(): foo_bar_element.js"
1414
end
15+
16+
test "some-name-element.js connects" do
17+
visit elements_path
18+
19+
assert_text "connectedCallback(): some-name-element.js"
20+
end
1521
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default class extends HTMLElement {
2+
constructor() {
3+
super()
4+
}
5+
6+
connectedCallback() {
7+
this.textContent = "connectedCallback(): some-name-element.js"
8+
}
9+
}

test/dummy/app/views/elements/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
<app-hello></app-hello>
44
<app-foo-bar></app-foo-bar>
5+
<app-some-name></app-some-name>

0 commit comments

Comments
 (0)