Skip to content

Commit 512cc2d

Browse files
committed
Stop depending on @_context.target
1 parent e7e4e48 commit 512cc2d

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

lib/phlex/rails/helper_macros.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ def #{method_name}(*args, **kwargs, &block)
1616
helpers.#{method_name}(*args, **kwargs)
1717
end
1818
19-
case output
20-
when ActiveSupport::SafeBuffer
21-
@_context.target << output
22-
end
23-
24-
nil
19+
raw(output)
2520
end
2621
RUBY
2722
end
@@ -63,12 +58,7 @@ def #{method_name}(*args, **kwargs)
6358
helpers.#{method_name}(*args, **kwargs)
6459
end
6560
66-
case output
67-
when ActiveSupport::SafeBuffer
68-
@_context.target << output
69-
end
70-
71-
nil
61+
raw(output)
7262
end
7363
RUBY
7464
end

lib/phlex/rails/helpers/tag.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def tag(...)
1010

1111
case result
1212
when ActiveSupport::SafeBuffer
13-
@_context.target << result
13+
@_context.buffer << result
1414
when ActionView::Helpers::TagHelper::TagBuilder
1515
Phlex::Rails::Buffered.new(
1616
result,

lib/phlex/rails/sgml.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ def render(*args, **kwargs, &block)
3232
partial = kwargs.delete(:partial)
3333

3434
if partial # this is a hack to get around https://github.com/rails/rails/issues/51015
35-
@_context.target << @_view_context.render(partial, **kwargs) do |*yielded_args|
36-
capture(*yielded_args, &block)
37-
end
38-
39-
return nil
35+
return raw(
36+
@_view_context.render(partial, **kwargs) do |*yielded_args|
37+
capture(*yielded_args, &block)
38+
end,
39+
)
4040
end
4141
end
4242

43-
if block
44-
@_context.target << @_view_context.render(*args, **kwargs) do |*yielded_args|
43+
output = if block
44+
@_view_context.render(*args, **kwargs) do |*yielded_args|
4545
if yielded_args.length == 1 && defined?(ViewComponent::Base) && ViewComponent::Base === yielded_args[0]
4646
capture(Phlex::Rails::Buffered.new(yielded_args[0], view: self), &block)
4747
else
4848
capture(*yielded_args, &block)
4949
end
5050
end
5151
else
52-
@_context.target << @_view_context.render(*args, **kwargs)
52+
@_view_context.render(*args, **kwargs)
5353
end
5454

55-
nil
55+
raw(output)
5656
end
5757

5858
def render_in(view_context, &erb)

0 commit comments

Comments
 (0)