public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed template recompile logic [#630 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
Stefan Kaes (author)
Wed Jul 16 06:26:23 -0700 2008
josh (committer)
Wed Jul 16 06:26:23 -0700 2008
commit  c64d749abdf31a2be322b1787165024067abbda7
tree    5289a0ecb600d7e92d4c5fce4e2b3c7147483452
parent  0432d151647f2178ddee79979827d552447c251f
...
9
10
11
 
 
 
 
12
13
14
...
35
36
37
38
 
39
40
41
42
43
 
 
 
 
 
44
45
 
 
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
 
 
 
64
65
 
 
 
 
 
 
66
 
 
67
68
69
...
71
72
73
74
75
 
76
77
78
...
9
10
11
12
13
14
15
16
17
18
...
39
40
41
 
42
43
44
45
46
 
47
48
49
50
51
52
 
53
54
55
 
 
 
 
 
 
 
56
57
58
59
60
61
62
63
 
 
 
 
 
 
 
 
 
64
65
66
67
 
68
69
70
71
72
73
74
75
76
77
78
79
...
81
82
83
 
 
84
85
86
87
0
@@ -9,6 +9,10 @@ module ActionView
0
 
0
     include ActiveSupport::Memoizable
0
 
0
+    def filename
0
+      'compiled-template'
0
+    end
0
+
0
     def handler
0
       Template.handler_class_for_extension(extension)
0
     end
0
@@ -35,35 +39,41 @@ module ActionView
0
     end
0
 
0
     private
0
-      # Compile and evaluate the template's code
0
+      # Compile and evaluate the template's code (if necessary)
0
       def compile(local_assigns)
0
         render_symbol = method(local_assigns)
0
 
0
         @@mutex.synchronize do
0
-          return false unless recompile?(render_symbol)
0
+          if recompile?(render_symbol)
0
+            compile!(render_symbol, local_assigns)
0
+          end
0
+        end
0
+      end
0
 
0
-          locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
0
+      def compile!(render_symbol, local_assigns)
0
+        locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
0
 
0
-          source = <<-end_src
0
-            def #{render_symbol}(local_assigns)
0
-              old_output_buffer = output_buffer;#{locals_code};#{compiled_source}
0
-            ensure
0
-              self.output_buffer = old_output_buffer
0
-            end
0
-          end_src
0
+        source = <<-end_src
0
+          def #{render_symbol}(local_assigns)
0
+            old_output_buffer = output_buffer;#{locals_code};#{compiled_source}
0
+          ensure
0
+            self.output_buffer = old_output_buffer
0
+          end
0
+        end_src
0
 
0
-          begin
0
-            file_name = respond_to?(:filename) ? filename : 'compiled-template'
0
-            ActionView::Base::CompiledTemplates.module_eval(source, file_name, 0)
0
-          rescue Exception => e # errors from template code
0
-            if logger = ActionController::Base.logger
0
-              logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
0
-              logger.debug "Function body: #{source}"
0
-              logger.debug "Backtrace: #{e.backtrace.join("\n")}"
0
-            end
0
+        begin
0
+          logger = ActionController::Base.logger
0
+          logger.debug "Compiling template #{render_symbol}" if logger
0
 
0
-            raise ActionView::TemplateError.new(self, {}, e)
0
+          ActionView::Base::CompiledTemplates.module_eval(source, filename, 0)
0
+        rescue Exception => e # errors from template code
0
+          if logger
0
+            logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
0
+            logger.debug "Function body: #{source}"
0
+            logger.debug "Backtrace: #{e.backtrace.join("\n")}"
0
           end
0
+
0
+          raise ActionView::TemplateError.new(self, {}, e)
0
         end
0
       end
0
 
0
@@ -71,8 +81,7 @@ module ActionView
0
       # The template will be compiled if the file has not been compiled yet, or
0
       # if local_assigns has a new key, which isn't supported by the compiled code yet.
0
       def recompile?(symbol)
0
-        meth = Base::CompiledTemplates.instance_method(template.method) rescue nil
0
-        !(meth && frozen?)
0
+        !(frozen? && Base::CompiledTemplates.method_defined?(symbol))
0
       end
0
   end
0
 end
...
23
24
25
 
26
27
28
...
23
24
25
26
27
28
29
0
@@ -23,6 +23,7 @@ ActionController::Base.logger = nil
0
 ActionController::Routing::Routes.reload rescue nil
0
 
0
 FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
0
+ActionView::PathSet::Path.eager_load_templates!
0
 ActionController::Base.view_paths = FIXTURE_LOAD_PATH
0
 
0
 # Wrap tests that use Mocha and skip if unavailable.

Comments