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



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

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



65
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
# File 'lib/view_component/global_output_buffer.rb', line 65

def with_output_buffer(buf = nil)
  unless buf
    buf = ActionView::OutputBuffer.new
    if @output_buffer && @output_buffer.respond_to?(:encoding)
      buf.force_encoding(@output_buffer.encoding)
    end
  end

  result = nil

  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