123456789_123456789_123456789_123456789_123456789_

Class: ActionView::OutputBuffer

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionview/lib/action_view/buffers.rb

Overview

Used as a buffer for views

The main difference between this and ::ActiveSupport::SafeBuffer is for the methods #<< and #safe_expr_append= the inputs are checked for nil before they are assigned and #to_s is called on the input. For example:

obuf = ActionView::OutputBuffer.new "hello"
obuf << 5
puts obuf # => "hello5"

sbuf = ActiveSupport::SafeBuffer.new "hello"
sbuf << 5
puts sbuf # => "hello\u0005"

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(buffer = "") ⇒ OutputBuffer

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 22

def initialize(buffer = "")
  @raw_buffer = String.new(buffer)
  @raw_buffer.encode!
end

Instance Attribute Details

#append=(value) (writeonly)

Alias for #<<.

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 54

alias :append= :<<

#encoding (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#force_encoding (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#html_safe (readonly)

Alias for #to_s.

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 32

alias_method :html_safe, :to_s

#html_safe?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 38

def html_safe?
  true
end

#length (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#raw_buffer (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 89

attr_reader :raw_buffer

#safe_append=(value) (writeonly)

Alias for #safe_concat.

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 60

alias :safe_append= :safe_concat

#safe_expr_append=(val) (writeonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 62

def safe_expr_append=(val)
  return self if val.nil?
  @raw_buffer << val.to_s
  self
end

Instance Method Details

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

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 42

def <<(value)
  unless value.nil?
    value = value.to_s
    @raw_buffer << if value.html_safe?
      value
    else
      CGI.escapeHTML(value)
    end
  end
  self
end

#==(other)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 81

def ==(other)
  other.class == self.class && @raw_buffer == other.to_str
end

#blank?Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#capture(*args)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 72

def capture(*args)
  new_buffer = +""
  old_buffer, @raw_buffer = @raw_buffer, new_buffer
  yield(*args)
  new_buffer.html_safe
ensure
  @raw_buffer = old_buffer
end

#concat(value)

Alias for #<<.

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 53

alias :concat :<<

#empty?Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#encode!

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 27

delegate :length, :empty?, :blank?, :encoding, :encode!, :force_encoding, to: :@raw_buffer

#initialize_copy(other)

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 68

def initialize_copy(other)
  @raw_buffer = other.to_str
end

#raw

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 85

def raw
  RawOutputBuffer.new(self)
end

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

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 56

def safe_concat(value)
  @raw_buffer << value
  self
end

#to_s Also known as: #html_safe

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 29

def to_s
  @raw_buffer.html_safe
end

#to_str

[ GitHub ]

  
# File 'actionview/lib/action_view/buffers.rb', line 34

def to_str
  @raw_buffer.dup
end