@@ -47,17 +47,9 @@ def process(source)
47
47
locals = attributes . empty? ? '' : attributes . map { |k , v | "'#{ k } ': #{ v } " } . join ( ', ' )
48
48
49
49
component = resolve_view_component ( partial )
50
+ is_partial = component . nil?
50
51
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
61
53
partial = partial . delete_prefix ( '_' ) . underscore
62
54
63
55
partial = "#{ path } /#{ partial } " if path
@@ -72,6 +64,15 @@ def process(source)
72
64
locals = ", locals: {#{ locals } }" unless locals . empty?
73
65
output = "<%= render partial: '#{ partial } '#{ collection } #{ locals } %>"
74
66
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
75
76
end
76
77
77
78
output
@@ -109,7 +110,7 @@ def resolve_view_component(component)
109
110
110
111
# safe_constantize ensures PascalCase
111
112
klass = component . safe_constantize || "#{ component } Component" . safe_constantize
112
- klass . name if klass &. < ViewComponent ::Base
113
+ klass . name if klass && klass < ViewComponent ::Base
113
114
end
114
115
115
116
def translate_location ( spot , backtrace_location , source )
0 commit comments