Skip to content
This repository
Browse code

Try replacing _erbout with @output_buffer

  • Loading branch information...
commit 933697a5fc5f4c56c4fd7fbbd31b8973df9c1054 1 parent da91450
Jeremy Kemper authored June 02, 2008
5  actionpack/lib/action_view/base.rb
@@ -178,10 +178,7 @@ def self.cache_template_extensions=(*args)
178 178
     # that alert()s the caught exception (and then re-raises it). 
179 179
     @@debug_rjs = false
180 180
     cattr_accessor :debug_rjs
181  
-    
182  
-    @@erb_variable = '_erbout'
183  
-    cattr_accessor :erb_variable
184  
-    
  181
+
185 182
     attr_internal :request
186 183
 
187 184
     delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
56  actionpack/lib/action_view/helpers/capture_helper.rb
@@ -31,20 +31,13 @@ module CaptureHelper
31 31
       #   </body></html>
32 32
       #
33 33
       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
46 39
       end
47  
-      
  40
+
48 41
       # Calling content_for stores a block of markup in an identifier for later use.
49 42
       # You can make subsequent calls to the stored content in other templates or the layout
50 43
       # by passing the identifier as an argument to <tt>yield</tt>.
@@ -121,40 +114,19 @@ def capture(*args, &block)
121 114
       # named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
122 115
       # <tt><%= yield :footer %></tt>.
123 116
       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}")
127 119
       end
128 120
 
129 121
       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  
-      
152 122
         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)}")
154 125
         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}")
158 130
         end
159 131
     end
160 132
   end
2  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -208,7 +208,7 @@ def array_or_string_for_javascript(option)
208 208
 
209 209
     private
210 210
       def block_is_within_action_view?(block)
211  
-        eval("defined? _erbout", block.binding)
  211
+        !@output_buffer.nil?
212 212
       end
213 213
     end
214 214
     
2  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -126,7 +126,7 @@ def tag_options(options, escape = true)
126 126
         end
127 127
 
128 128
         def block_is_within_action_view?(block)
129  
-          eval("defined? _erbout", block.binding)
  129
+          !@output_buffer.nil?
130 130
         end
131 131
     end
132 132
   end
8  actionpack/lib/action_view/helpers/text_helper.rb
@@ -25,8 +25,12 @@ module TextHelper
25 25
       #       end
26 26
       #       # will either display "Logged in!" or a login link
27 27
       #   %>
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
30 34
       end
31 35
 
32 36
       if RUBY_VERSION < '1.9'
6  actionpack/lib/action_view/template_handlers/erb.rb
@@ -43,13 +43,11 @@ class ERB < TemplateHandler
43 43
       include Compilable
44 44
 
45 45
       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
47 47
       end
48 48
 
49 49
       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 }
53 51
       end
54 52
     end
55 53
   end

0 notes on commit 933697a

Please sign in to comment.
Something went wrong with that request. Please try again.