Class: ActionView::StreamingBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/buffers.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ StreamingBuffer

Returns a new instance of StreamingBuffer.



109
110
111
# File 'lib/action_view/buffers.rb', line 109

def initialize(block)
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



147
148
149
# File 'lib/action_view/buffers.rb', line 147

def block
  @block
end

Instance Method Details

#<<(value) ⇒ Object Also known as: concat, append=



113
114
115
116
117
# File 'lib/action_view/buffers.rb', line 113

def <<(value)
  value = value.to_s
  value = ERB::Util.h(value) unless value.html_safe?
  @block.call(value)
end

#captureObject



126
127
128
129
130
131
132
133
# File 'lib/action_view/buffers.rb', line 126

def capture
  buffer = +""
  old_block, @block = @block, ->(value) { buffer << value }
  yield
  buffer.html_safe
ensure
  @block = old_block
end

#html_safeObject



139
140
141
# File 'lib/action_view/buffers.rb', line 139

def html_safe
  self
end

#html_safe?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/action_view/buffers.rb', line 135

def html_safe?
  true
end

#rawObject



143
144
145
# File 'lib/action_view/buffers.rb', line 143

def raw
  RawStreamingBuffer.new(self)
end

#safe_concat(value) ⇒ Object Also known as: safe_append=



121
122
123
# File 'lib/action_view/buffers.rb', line 121

def safe_concat(value)
  @block.call(value.to_s)
end