Skip to content
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

Support variants with dots in their names #1585

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 5

## main

* Support variants with dots in their names.

*Javi Martín*

## 2.77.0

* Support variants with dashes in their names.
Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def templates
pieces = File.basename(path).split(".")
memo << {
path: path,
variant: pieces.second.split("+").second&.to_sym,
variant: pieces[1..-2].join(".").split("+").second&.to_sym,
handler: pieces.last
}
end
Expand Down Expand Up @@ -254,7 +254,7 @@ def call_method_name(variant)
end

def normalized_variant_name(variant)
variant.to_s.gsub("-", "__")
variant.to_s.gsub("-", "__").gsub(".", "___")
end

def should_compile_superclass?
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Mini Watch
Mini Watch with dash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mini Watch with dot
10 changes: 9 additions & 1 deletion test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@ def test_renders_component_with_variant_containing_a_dash
with_variant :"mini-watch" do
render_inline(VariantsComponent.new)

assert_text("Mini Watch")
assert_text("Mini Watch with dash")
end
end

def test_renders_component_with_variant_containing_a_dot
with_variant :"mini.watch" do
render_inline(VariantsComponent.new)

assert_text("Mini Watch with dot")
end
end

Expand Down