2011-04-16 04:28:47 -04:00
|
|
|
require 'active_support/core_ext/string/output_safety'
|
|
|
|
|
|
|
|
module ActionView
|
2011-04-16 05:42:02 -04:00
|
|
|
class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
|
2011-04-16 04:28:47 -04:00
|
|
|
def initialize(*)
|
|
|
|
super
|
|
|
|
encode! if encoding_aware?
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(value)
|
|
|
|
super(value.to_s)
|
|
|
|
end
|
|
|
|
alias :append= :<<
|
|
|
|
alias :safe_append= :safe_concat
|
|
|
|
end
|
|
|
|
|
2011-04-16 05:42:02 -04:00
|
|
|
class StreamingBuffer #:nodoc:
|
2011-04-16 04:28:47 -04:00
|
|
|
def initialize(block)
|
|
|
|
@block = block
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(value)
|
|
|
|
value = value.to_s
|
|
|
|
value = ERB::Util.h(value) unless value.html_safe?
|
|
|
|
@block.call(value)
|
|
|
|
end
|
|
|
|
alias :concat :<<
|
|
|
|
alias :append= :<<
|
|
|
|
|
|
|
|
def safe_concat(value)
|
|
|
|
@block.call(value.to_s)
|
|
|
|
end
|
|
|
|
alias :safe_append= :safe_concat
|
|
|
|
|
|
|
|
def html_safe?
|
|
|
|
true
|
|
|
|
end
|
2011-06-05 11:34:40 -04:00
|
|
|
|
2011-04-16 04:28:47 -04:00
|
|
|
def html_safe
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
2011-06-05 11:34:40 -04:00
|
|
|
end
|