From 4840acd485a4a6bcdd73338447af7e1340587e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 12 Mar 2010 12:08:23 +0100 Subject: %= works for content_tag and does not require parenthesis on method call --- .../lib/action_view/template/handlers/erb.rb | 53 +++------------------- actionpack/test/template/erb/tag_helper_test.rb | 4 +- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 2ac68d38bd..ac5902cc0e 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -3,52 +3,11 @@ 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 - + class OutputBuffer < ActiveSupport::SafeBuffer 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 to_str - @buffer.to_str - end - - def empty? - @buffer.empty? - end - - def html_safe? - @buffer.html_safe? - end - - if "".respond_to?(:force_encoding) - def encoding - @buffer.encoding - end - - def force_encoding(encoding) - @buffer.force_encoding(encoding) - end + super(value.to_s) end + alias :append= :<< end module Template::Handlers @@ -64,14 +23,14 @@ module ActionView def add_expr_literal(src, code) if code =~ /(do|\{)(\s*\|[^|]*\|)?\s*\Z/ - src << '@output_buffer << ' << code + src << '@output_buffer.append= ' << code else - src << '@output_buffer << (' << code << ');' + src << '@output_buffer.append= (' << code << ');' end end def add_expr_escaped(src, code) - src << '@output_buffer << ' << escaped_expr(code) << ';' + src << '@output_buffer.append= ' << escaped_expr(code) << ';' end def add_postamble(src) diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb index b91539ef0b..cc96a43901 100644 --- a/actionpack/test/template/erb/tag_helper_test.rb +++ b/actionpack/test/template/erb/tag_helper_test.rb @@ -31,8 +31,8 @@ module ERBTest ActionView::Template::Handlers::Erubis.new(template).evaluate(context.new) end - test "percent equals works for content_tag" do - assert_equal "
Hello world
", render_content("content_tag(:div)", "Hello world") + test "percent equals works for content_tag and does not require parenthesis on method call" do + assert_equal "
Hello world
", render_content("content_tag :div", "Hello world") end test "percent equals works for javascript_tag" do -- cgit v1.2.3