public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Try replacing _erbout with @output_buffer
jeremy (author)
Mon Jun 02 09:12:00 -0700 2008
commit  933697a5fc5f4c56c4fd7fbbd31b8973df9c1054
tree    44f55a5c801e94db8c3637c73dfc6db7f2c3350d
parent  da91450e687fe9faa7b0575062c2b2aacc261f68
...
178
179
180
181
182
183
184
 
185
186
187
...
178
179
180
 
 
 
 
181
182
183
184
0
@@ -178,10 +178,7 @@ module ActionView #:nodoc:
0
     # that alert()s the caught exception (and then re-raises it). 
0
     @@debug_rjs = false
0
     cattr_accessor :debug_rjs
0
-    
0
-    @@erb_variable = '_erbout'
0
-    cattr_accessor :erb_variable
0
-    
0
+
0
     attr_internal :request
0
 
0
     delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 
 
 
 
46
47
 
48
49
50
...
121
122
123
124
125
126
 
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
 
 
154
155
156
157
 
 
 
 
158
159
160
...
31
32
33
 
 
 
 
 
 
 
 
 
 
 
 
34
35
36
37
38
39
 
40
41
42
43
...
114
115
116
 
 
 
117
118
119
120
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
124
125
 
 
 
126
127
128
129
130
131
132
0
@@ -31,20 +31,13 @@ module ActionView
0
       #   </body></html>
0
       #
0
       def capture(*args, &block)
0
-        # execute the block
0
-        begin
0
-          buffer = eval(ActionView::Base.erb_variable, block.binding)
0
-        rescue
0
-          buffer = nil
0
-        end
0
-        
0
-        if buffer.nil?
0
-          capture_block(*args, &block).to_s
0
-        else
0
-          capture_erb_with_buffer(buffer, *args, &block).to_s
0
-        end
0
+        @output_buffer, old_buffer = '', @output_buffer
0
+        yield *args
0
+        @output_buffer
0
+      ensure
0
+        @output_buffer = old_buffer
0
       end
0
-      
0
+
0
       # Calling content_for stores a block of markup in an identifier for later use.
0
       # You can make subsequent calls to the stored content in other templates or the layout
0
       # by passing the identifier as an argument to <tt>yield</tt>.
0
@@ -121,40 +114,19 @@ module ActionView
0
       # named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
0
       # <tt><%= yield :footer %></tt>.
0
       def content_for(name, content = nil, &block)
0
-        existing_content_for = instance_variable_get("@content_for_#{name}").to_s
0
-        new_content_for      = existing_content_for + (block_given? ? capture(&block) : content)
0
-        instance_variable_set("@content_for_#{name}", new_content_for)
0
+        ivar = "@content_for_#{name}"
0
+        instance_variable_set("@content_for_#{name}", "#{instance_variable_get(ivar)}#{block_given? ? capture(&block) : content}")
0
       end
0
 
0
       private
0
-        def capture_block(*args, &block)
0
-          block.call(*args)
0
-        end
0
-      
0
-        def capture_erb(*args, &block)
0
-          buffer = eval(ActionView::Base.erb_variable, block.binding)
0
-          capture_erb_with_buffer(buffer, *args, &block)
0
-        end
0
-      
0
-        def capture_erb_with_buffer(buffer, *args, &block)
0
-          pos = buffer.length
0
-          block.call(*args)
0
-        
0
-          # extract the block 
0
-          data = buffer[pos..-1]
0
-        
0
-          # replace it in the original with empty string
0
-          buffer[pos..-1] = ''
0
-        
0
-          data
0
-        end
0
-      
0
         def erb_content_for(name, &block)
0
-          eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_erb(&block)"
0
+          ivar = "@content_for_#{name}"
0
+          instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{capture(&block)}")
0
         end
0
-      
0
-        def block_content_for(name, &block)
0
-          eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_block(&block)"
0
+
0
+        def block_content_for(name)
0
+          ivar = "@content_for_#{name}"
0
+          instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{yield}")
0
         end
0
     end
0
   end
...
208
209
210
211
 
212
213
214
...
208
209
210
 
211
212
213
214
0
@@ -208,7 +208,7 @@ module ActionView
0
 
0
     private
0
       def block_is_within_action_view?(block)
0
-        eval("defined? _erbout", block.binding)
0
+        !@output_buffer.nil?
0
       end
0
     end
0
     
...
126
127
128
129
 
130
131
132
...
126
127
128
 
129
130
131
132
0
@@ -126,7 +126,7 @@ module ActionView
0
         end
0
 
0
         def block_is_within_action_view?(block)
0
-          eval("defined? _erbout", block.binding)
0
+          !@output_buffer.nil?
0
         end
0
     end
0
   end
...
25
26
27
28
29
 
 
 
 
 
 
30
31
32
...
25
26
27
 
 
28
29
30
31
32
33
34
35
36
0
@@ -25,8 +25,12 @@ module ActionView
0
       #       end
0
       #       # will either display "Logged in!" or a login link
0
       #   %>
0
-      def concat(string, binding)
0
-        eval(ActionView::Base.erb_variable, binding) << string
0
+      def concat(string, binding = nil)
0
+        if @output_buffer
0
+          @output_buffer << string
0
+        else
0
+          string
0
+        end
0
       end
0
 
0
       if RUBY_VERSION < '1.9'
...
43
44
45
46
 
47
48
49
50
51
52
 
53
54
55
...
43
44
45
 
46
47
48
49
 
 
 
50
51
52
53
0
@@ -43,13 +43,11 @@ module ActionView
0
       include Compilable
0
 
0
       def compile(template)
0
-        ::ERB.new(template.source, nil, @view.erb_trim_mode).src
0
+        ::ERB.new(template.source, nil, @view.erb_trim_mode, '@output_buffer').src
0
       end
0
 
0
       def cache_fragment(block, name = {}, options = nil) #:nodoc:
0
-        @view.fragment_for(block, name, options) do
0
-          eval(ActionView::Base.erb_variable, block.binding)
0
-        end
0
+        @view.fragment_for(block, name, options) { @view.output_buffer }
0
       end
0
     end
0
   end

Comments