Skip to content

Commit adc05ad

Browse files
committed
simplify
1 parent 7d6c784 commit adc05ad

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/theo-rails/theo.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,9 @@ def process(source)
4747
locals = attributes.empty? ? '' : attributes.map { |k, v| "'#{k}': #{v}" }.join(', ')
4848

4949
component = resolve_view_component(partial)
50+
is_partial = component.nil?
5051

51-
if component.present?
52-
if content
53-
output = "<%= render #{component}.new(#{locals}) do#{yields} %>#{process(content)}<% end %>"
54-
elsif collection
55-
locals = ", #{locals}" unless locals.empty?
56-
output = "<%= render #{component}.with_collection(#{collection}#{locals}) %>"
57-
else
58-
output = "<%= render #{component}.new(#{locals}) %>"
59-
end
60-
else
52+
if is_partial
6153
partial = partial.delete_prefix('_').underscore
6254

6355
partial = "#{path}/#{partial}" if path
@@ -72,6 +64,15 @@ def process(source)
7264
locals = ", locals: {#{locals}}" unless locals.empty?
7365
output = "<%= render partial: '#{partial}'#{collection}#{locals} %>"
7466
end
67+
else
68+
if content
69+
output = "<%= render #{component}.new(#{locals}) do#{yields} %>#{process(content)}<% end %>"
70+
elsif collection
71+
locals = ", #{locals}" unless locals.empty?
72+
output = "<%= render #{component}.with_collection(#{collection}#{locals}) %>"
73+
else
74+
output = "<%= render #{component}.new(#{locals}) %>"
75+
end
7576
end
7677

7778
output
@@ -109,7 +110,7 @@ def resolve_view_component(component)
109110

110111
# safe_constantize ensures PascalCase
111112
klass = component.safe_constantize || "#{component}Component".safe_constantize
112-
klass.name if klass&.< ViewComponent::Base
113+
klass.name if klass && klass < ViewComponent::Base
113114
end
114115

115116
def translate_location(spot, backtrace_location, source)

0 commit comments

Comments
 (0)