Skip to content

Commit 6b188e7

Browse files
committed
Support foo_bar -> <app-foo-bar>
1 parent e392d99 commit 6b188e7

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
@@ -4,7 +4,7 @@ export function eagerDefineCustomElementsFrom(namespace, options = {}) {
44
const regex = new RegExp(`${namespace}\/(.*?)_element`)
55
Object.entries(imports)
66
.filter(([name, _]) => name.match(regex) )
7-
.map(([name, importPath]) => [name.match(regex)[1], importPath])
7+
.map(([name, importPath]) => [name.match(regex)[1].replace('_', '-'), importPath])
88
.forEach(([name, importPath]) => {
99
import(importPath)
1010
.then((module) => {

test/custom_elements/integration_test.rb

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

77
assert_text "connectedCallback(): hello_element.js"
88
end
9+
10+
test "foo_bar_element.js connects" do
11+
visit elements_path
12+
13+
assert_text "connectedCallback(): foo_bar_element.js"
14+
end
915
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(): foo_bar_element.js"
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<h1>Elements#show</h1>
22

33
<app-hello></app-hello>
4+
<app-foo-bar></app-foo-bar>

0 commit comments

Comments
 (0)