aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAman Gupta <aman@tmm1.net>2013-03-04 20:40:58 -0800
committerAman Gupta <aman@tmm1.net>2013-03-04 20:41:00 -0800
commitbd308a0d02c4a6459c05770a564405986a663f47 (patch)
tree8ed96e5ede32b65929c654739a51c6a1c4e8b77d /actionpack
parentb1c4469f9cb3800adb99d062c6748154bc0e1b16 (diff)
downloadrails-bd308a0d02c4a6459c05770a564405986a663f47.tar.gz
rails-bd308a0d02c4a6459c05770a564405986a663f47.tar.bz2
rails-bd308a0d02c4a6459c05770a564405986a663f47.zip
avoid extra method calls for appending newlines
before: ');@output_buffer.append= ( content_icon row[:content] );@output_buffer.safe_concat(' ');@output_buffer.safe_concat(' ');@output_buffer.append= ( spinner_img );@output_buffer.safe_concat(' ');@output_buffer.safe_concat(' </td> <td class="content"> ');@output_buffer.append= ( content_link row[:content] );@output_buffer.safe_concat(' ');@output_buffer.safe_concat(' </td> <td class="message"> '); after: ';@output_buffer.append=( content_icon row[:content] );@output_buffer.safe_append=' ';@output_buffer.append=( spinner_img );@output_buffer.safe_append=' </td> <td class="content"> ';@output_buffer.append=( content_link row[:content] );@output_buffer.safe_append=' </td> <td class="message"> ';
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index 52534655eb..7d7a7af51d 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -6,12 +6,23 @@ module ActionView
module Handlers
class Erubis < ::Erubis::Eruby
def add_preamble(src)
+ @newline_pending = 0
src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
end
def add_text(src, text)
return if text.empty?
- src << "@output_buffer.safe_append='" << escape_text(text) << "';"
+
+ if text == "\n"
+ @newline_pending += 1
+ else
+ src << "@output_buffer.safe_append='"
+ src << "\n" * @newline_pending if @newline_pending > 0
+ src << escape_text(text)
+ src << "';"
+
+ @newline_pending = 0
+ end
end
# Erubis toggles <%= and <%== behavior when escaping is enabled.
@@ -28,6 +39,7 @@ module ActionView
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
def add_expr_literal(src, code)
+ flush_newline_if_pending(src)
if code =~ BLOCK_EXPR
src << '@output_buffer.append= ' << code
else
@@ -36,6 +48,7 @@ module ActionView
end
def add_expr_escaped(src, code)
+ flush_newline_if_pending(src)
if code =~ BLOCK_EXPR
src << "@output_buffer.safe_append= " << code
else
@@ -43,9 +56,22 @@ module ActionView
end
end
+ def add_stmt(src, code)
+ flush_newline_if_pending(src)
+ super
+ end
+
def add_postamble(src)
+ flush_newline_if_pending(src)
src << '@output_buffer.to_s'
end
+
+ def flush_newline_if_pending(src)
+ if @newline_pending > 0
+ src << "@output_buffer.safe_append='#{"\n" * @newline_pending}';"
+ @newline_pending = 0
+ end
+ end
end
class ERB