Module: ViewComponent::GlobalOutputBuffer::ActionViewMods

Defined in:
lib/view_component/global_output_buffer.rb

Instance Method Summary collapse

Instance Method Details

#output_buffer=(other_buffer) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/view_component/global_output_buffer.rb', line 58

def output_buffer=(other_buffer)
  if @output_buffer.is_a?(OutputBufferStack)
    @output_buffer.replace(other_buffer)
  else
    super
  end
end

#with_output_buffer(buf = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/view_component/global_output_buffer.rb', line 66

def with_output_buffer(buf = nil)
  unless buf
    buf = ActionView::OutputBuffer.new
    # rubocop:disable Style/SafeNavigation
    if @output_buffer && @output_buffer.respond_to?(:encoding)
      buf.force_encoding(@output_buffer.encoding)
    end
    # rubocop:enable Style/SafeNavigation
  end

  if @output_buffer.is_a?(OutputBufferStack)
    @output_buffer.push(buf)

    begin
      yield
    ensure
      result = @output_buffer.pop
    end

    result
  else
    @output_buffer, old_buffer = buf, output_buffer

    begin
      yield
    ensure
      @output_buffer = old_buffer
    end

    buf
  end
end