Skip to content

Commit 8ed68e1

Browse files
committed
Apply code review suggestions
1 parent 803d586 commit 8ed68e1

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

lib/ruby_ui/separator/separator.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,35 @@ module RubyUI
44
class Separator < Base
55
ORIENTATIONS = %i[horizontal vertical].freeze
66

7-
def initialize(as: "div", orientation: :horizontal, decorative: true, **attrs)
7+
def initialize(as: :div, orientation: :horizontal, decorative: true, **attrs)
88
raise ArgumentError, "Invalid orientation: #{orientation}" unless ORIENTATIONS.include?(orientation.to_sym)
99

10-
@as = as
10+
@as = as.to_sym
1111
@orientation = orientation.to_sym
1212
@decorative = decorative
1313
super(**attrs)
1414
end
1515

1616
def view_template(&)
17-
public_send(@as, **attrs, &)
17+
tag(@as, **attrs, &)
1818
end
1919

2020
private
2121

2222
def default_attrs
2323
{
24-
role: (@decorative ? "none" : "separator"),
24+
role: (@decorative ? 'none' : 'separator'),
2525
class: [
26-
"shrink-0 bg-border",
26+
'shrink-0 bg-border',
2727
orientation_classes
28-
],
29-
data: {
30-
orientation: @orientation
31-
}
28+
]
3229
}
3330
end
3431

3532
def orientation_classes
36-
return "h-[1px] w-full" if @orientation == :horizontal
33+
return 'h-[1px] w-full' if @orientation == :horizontal
3734

38-
"h-full w-[1px]"
35+
'h-full w-[1px]'
3936
end
4037
end
4138
end

test/ruby_ui/separator_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "test_helper"
3+
require 'test_helper'
44

55
class RubyUI::SeparatorTest < ComponentTest
66
def test_render
@@ -10,15 +10,15 @@ def test_render
1010

1111
assert_match(/div/, output)
1212
assert_match(/role="none"/, output)
13-
assert_match(/data-orientation="horizontal"/, output)
13+
assert_match(/h-\[1px\]/, output)
1414
end
1515

1616
def test_render_with_vertical_orientation
1717
output = phlex do
1818
RubyUI.Separator(orientation: :vertical)
1919
end
2020

21-
assert_match(/data-orientation="vertical"/, output)
21+
assert_match(/w-\[1px\]/, output)
2222
end
2323

2424
def test_render_with_decorative_false
@@ -31,9 +31,9 @@ def test_render_with_decorative_false
3131

3232
def test_render_with_custom_tag
3333
output = phlex do
34-
RubyUI.Separator(as: "hr")
34+
RubyUI.Separator(as: 'hr')
3535
end
3636

37-
assert_match(/hr/, output)
37+
assert_match(/<hr/, output)
3838
end
3939
end

0 commit comments

Comments
 (0)