diff options
author | Stefan Kaes <stkaes@googlemail.com> | 2008-07-16 08:26:23 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-16 08:26:23 -0500 |
commit | c64d749abdf31a2be322b1787165024067abbda7 (patch) | |
tree | 5289a0ecb600d7e92d4c5fce4e2b3c7147483452 /actionpack/lib | |
parent | 0432d151647f2178ddee79979827d552447c251f (diff) | |
download | rails-c64d749abdf31a2be322b1787165024067abbda7.tar.gz rails-c64d749abdf31a2be322b1787165024067abbda7.tar.bz2 rails-c64d749abdf31a2be322b1787165024067abbda7.zip |
Fixed template recompile logic [#630 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/renderable.rb | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index badb2b171c..46193670f3 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -9,6 +9,10 @@ module ActionView include ActiveSupport::Memoizable + def filename + 'compiled-template' + end + def handler Template.handler_class_for_extension(extension) end @@ -35,35 +39,41 @@ module ActionView end private - # Compile and evaluate the template's code + # Compile and evaluate the template's code (if necessary) def compile(local_assigns) render_symbol = method(local_assigns) @@mutex.synchronize do - return false unless recompile?(render_symbol) + if recompile?(render_symbol) + compile!(render_symbol, local_assigns) + end + end + end - locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join + def compile!(render_symbol, local_assigns) + locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join - source = <<-end_src - def #{render_symbol}(local_assigns) - old_output_buffer = output_buffer;#{locals_code};#{compiled_source} - ensure - self.output_buffer = old_output_buffer - end - end_src + source = <<-end_src + def #{render_symbol}(local_assigns) + old_output_buffer = output_buffer;#{locals_code};#{compiled_source} + ensure + self.output_buffer = old_output_buffer + end + end_src - begin - file_name = respond_to?(:filename) ? filename : 'compiled-template' - ActionView::Base::CompiledTemplates.module_eval(source, file_name, 0) - rescue Exception => e # errors from template code - if logger = ActionController::Base.logger - logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" - logger.debug "Function body: #{source}" - logger.debug "Backtrace: #{e.backtrace.join("\n")}" - end + begin + logger = ActionController::Base.logger + logger.debug "Compiling template #{render_symbol}" if logger - raise ActionView::TemplateError.new(self, {}, e) + ActionView::Base::CompiledTemplates.module_eval(source, filename, 0) + rescue Exception => e # errors from template code + if logger + logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" + logger.debug "Function body: #{source}" + logger.debug "Backtrace: #{e.backtrace.join("\n")}" end + + raise ActionView::TemplateError.new(self, {}, e) end end @@ -71,8 +81,7 @@ module ActionView # The template will be compiled if the file has not been compiled yet, or # if local_assigns has a new key, which isn't supported by the compiled code yet. def recompile?(symbol) - meth = Base::CompiledTemplates.instance_method(template.method) rescue nil - !(meth && frozen?) + !(frozen? && Base::CompiledTemplates.method_defined?(symbol)) end end end |