diff options
author | José Valim <jose.valim@gmail.com> | 2011-04-16 10:28:47 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-16 10:28:47 +0200 |
commit | e30ca001efa861cc13259ca8287837174b24e679 (patch) | |
tree | ab47ef08d8c2e8773bb7fc6d6d24cda6cd32bf66 /actionpack/lib/action_view/buffers.rb | |
parent | 2dd43c3f804176d114cdbfeb8a0f92a43155baee (diff) | |
download | rails-e30ca001efa861cc13259ca8287837174b24e679.tar.gz rails-e30ca001efa861cc13259ca8287837174b24e679.tar.bz2 rails-e30ca001efa861cc13259ca8287837174b24e679.zip |
Yo dawg, I heard you like streaming. So I put a fiber, inside a block, inside a body, so you can stream.
Diffstat (limited to 'actionpack/lib/action_view/buffers.rb')
-rw-r--r-- | actionpack/lib/action_view/buffers.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/buffers.rb b/actionpack/lib/action_view/buffers.rb new file mode 100644 index 0000000000..2e2b39e4a2 --- /dev/null +++ b/actionpack/lib/action_view/buffers.rb @@ -0,0 +1,43 @@ +require 'active_support/core_ext/string/output_safety' + +module ActionView + class OutputBuffer < ActiveSupport::SafeBuffer + def initialize(*) + super + encode! if encoding_aware? + end + + def <<(value) + super(value.to_s) + end + alias :append= :<< + alias :safe_append= :safe_concat + end + + class StreamingBuffer + 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 + + def html_safe + self + end + end +end
\ No newline at end of file |