diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-03-09 18:00:28 -0800 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-09 23:44:12 -0800 |
commit | 4464b8e87bedd69816d4658c9386cc360affb62e (patch) | |
tree | 72598e47159bbdf36cdb4fcfd31682dce4877b9e /actionpack/lib/action_view/template/handlers | |
parent | f30b7a0903ac1859a139bce96856d228c59a80b7 (diff) | |
download | rails-4464b8e87bedd69816d4658c9386cc360affb62e.tar.gz rails-4464b8e87bedd69816d4658c9386cc360affb62e.tar.bz2 rails-4464b8e87bedd69816d4658c9386cc360affb62e.zip |
Deprecate block_called_from_erb? pending a solution for getting it into apps
Diffstat (limited to 'actionpack/lib/action_view/template/handlers')
-rw-r--r-- | actionpack/lib/action_view/template/handlers/erb.rb | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 4b7cec50f3..3fcae167ff 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -3,10 +3,46 @@ require 'active_support/core_ext/string/output_safety' require 'erubis' module ActionView + class OutputBuffer + def initialize + @buffer = ActiveSupport::SafeBuffer.new + end + + def safe_concat(value) + @buffer.safe_concat(value) + end + + def <<(value) + @buffer << value.to_s + end + + def length + @buffer.length + end + + def [](*args) + @buffer[*args] + end + + def to_s + @buffer.to_s + end + + def empty? + @buffer.empty? + end + + if "".respond_to?(:force_encoding) + def force_encoding(encoding) + @buffer.force_encoding(encoding) + end + end + end + module Template::Handlers class Erubis < ::Erubis::Eruby def add_preamble(src) - src << "@output_buffer = ActiveSupport::SafeBuffer.new;" + src << "@output_buffer = ActionView::OutputBuffer.new;" end def add_text(src, text) @@ -15,10 +51,10 @@ module ActionView end def add_expr_literal(src, code) - if code =~ /\s*raw\s+(.*)/ - src << "@output_buffer.safe_concat((" << $1 << ").to_s);" + if code =~ /(do|\{)(\s*\|[^|]*\|)?\s*\Z/ + src << '@output_buffer << ' << code else - src << '@output_buffer << ((' << code << ').to_s);' + src << '@output_buffer << (' << code << ');' end end @@ -42,7 +78,7 @@ module ActionView self.erb_trim_mode = '-' self.default_format = Mime::HTML - + cattr_accessor :erb_implementation self.erb_implementation = Erubis |