Skip to content

Commit 933697a

Browse files
committed
Try replacing _erbout with @output_buffer
1 parent da91450 commit 933697a

File tree

6 files changed

+25
-54
lines changed

6 files changed

+25
-54
lines changed

actionpack/lib/action_view/base.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ def self.cache_template_extensions=(*args)
178178
# that alert()s the caught exception (and then re-raises it).
179179
@@debug_rjs = false
180180
cattr_accessor :debug_rjs
181-
182-
@@erb_variable = '_erbout'
183-
cattr_accessor :erb_variable
184-
181+
185182
attr_internal :request
186183

187184
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,

actionpack/lib/action_view/helpers/capture_helper.rb

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,13 @@ module CaptureHelper
3131
# </body></html>
3232
#
3333
def capture(*args, &block)
34-
# execute the block
35-
begin
36-
buffer = eval(ActionView::Base.erb_variable, block.binding)
37-
rescue
38-
buffer = nil
39-
end
40-
41-
if buffer.nil?
42-
capture_block(*args, &block).to_s
43-
else
44-
capture_erb_with_buffer(buffer, *args, &block).to_s
45-
end
34+
@output_buffer, old_buffer = '', @output_buffer
35+
yield *args
36+
@output_buffer
37+
ensure
38+
@output_buffer = old_buffer
4639
end
47-
40+
4841
# Calling content_for stores a block of markup in an identifier for later use.
4942
# You can make subsequent calls to the stored content in other templates or the layout
5043
# by passing the identifier as an argument to <tt>yield</tt>.
@@ -121,40 +114,19 @@ def capture(*args, &block)
121114
# named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
122115
# <tt><%= yield :footer %></tt>.
123116
def content_for(name, content = nil, &block)
124-
existing_content_for = instance_variable_get("@content_for_#{name}").to_s
125-
new_content_for = existing_content_for + (block_given? ? capture(&block) : content)
126-
instance_variable_set("@content_for_#{name}", new_content_for)
117+
ivar = "@content_for_#{name}"
118+
instance_variable_set("@content_for_#{name}", "#{instance_variable_get(ivar)}#{block_given? ? capture(&block) : content}")
127119
end
128120

129121
private
130-
def capture_block(*args, &block)
131-
block.call(*args)
132-
end
133-
134-
def capture_erb(*args, &block)
135-
buffer = eval(ActionView::Base.erb_variable, block.binding)
136-
capture_erb_with_buffer(buffer, *args, &block)
137-
end
138-
139-
def capture_erb_with_buffer(buffer, *args, &block)
140-
pos = buffer.length
141-
block.call(*args)
142-
143-
# extract the block
144-
data = buffer[pos..-1]
145-
146-
# replace it in the original with empty string
147-
buffer[pos..-1] = ''
148-
149-
data
150-
end
151-
152122
def erb_content_for(name, &block)
153-
eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_erb(&block)"
123+
ivar = "@content_for_#{name}"
124+
instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{capture(&block)}")
154125
end
155-
156-
def block_content_for(name, &block)
157-
eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_block(&block)"
126+
127+
def block_content_for(name)
128+
ivar = "@content_for_#{name}"
129+
instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{yield}")
158130
end
159131
end
160132
end

actionpack/lib/action_view/helpers/javascript_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def array_or_string_for_javascript(option)
208208

209209
private
210210
def block_is_within_action_view?(block)
211-
eval("defined? _erbout", block.binding)
211+
!@output_buffer.nil?
212212
end
213213
end
214214

actionpack/lib/action_view/helpers/tag_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def tag_options(options, escape = true)
126126
end
127127

128128
def block_is_within_action_view?(block)
129-
eval("defined? _erbout", block.binding)
129+
!@output_buffer.nil?
130130
end
131131
end
132132
end

actionpack/lib/action_view/helpers/text_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ module TextHelper
2525
# end
2626
# # will either display "Logged in!" or a login link
2727
# %>
28-
def concat(string, binding)
29-
eval(ActionView::Base.erb_variable, binding) << string
28+
def concat(string, binding = nil)
29+
if @output_buffer
30+
@output_buffer << string
31+
else
32+
string
33+
end
3034
end
3135

3236
if RUBY_VERSION < '1.9'

actionpack/lib/action_view/template_handlers/erb.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ class ERB < TemplateHandler
4343
include Compilable
4444

4545
def compile(template)
46-
::ERB.new(template.source, nil, @view.erb_trim_mode).src
46+
::ERB.new(template.source, nil, @view.erb_trim_mode, '@output_buffer').src
4747
end
4848

4949
def cache_fragment(block, name = {}, options = nil) #:nodoc:
50-
@view.fragment_for(block, name, options) do
51-
eval(ActionView::Base.erb_variable, block.binding)
52-
end
50+
@view.fragment_for(block, name, options) { @view.output_buffer }
5351
end
5452
end
5553
end

0 commit comments

Comments
 (0)