Skip to content

Commit

Permalink
Fix patch of ActionView capture: OutputBuffer refactored by rails/rai…
Browse files Browse the repository at this point in the history
…ls#45614 (Rails 7.1)
  • Loading branch information
varyonic committed Oct 12, 2023
1 parent de3c087 commit ee86f29
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/arbo/rails/template_handler.rb
Expand Up @@ -5,13 +5,18 @@ def capture(*args)
value = nil
buffer = with_output_buffer { value = yield(*args) }

# Override to handle Arbo elements inside helper blocks.
# See https://github.com/rails/rails/issues/17661
# and https://github.com/rails/rails/pull/18024#commitcomment-8975180
value = value.to_s if value.is_a?(Arbo::Element)

if (string = buffer.presence || value) && string.is_a?(String)
ERB::Util.html_escape string
case string = buffer.presence || value
when ActionView::OutputBuffer
string.to_s
when ActiveSupport::SafeBuffer
string
when Arbo::Element
# Override to handle Arbo elements inside helper blocks.
# See https://github.com/rails/rails/issues/17661
# and https://github.com/rails/rails/pull/18024#commitcomment-8975180
value.render_in
when String
ERB::Util.html_escape(string)
end
end
end
Expand Down

0 comments on commit ee86f29

Please sign in to comment.