Module | ActionView::TemplateHandlers::Compilable |
In: |
vendor/rails/actionpack/lib/action_view/template_handlers/compilable.rb
|
# File vendor/rails/actionpack/lib/action_view/template_handlers/compilable.rb, line 5 5: def self.included(base) 6: base.extend ClassMethod 7: 8: # Map method names to their compile time 9: base.cattr_accessor :compile_time 10: base.compile_time = {} 11: 12: # Map method names to the names passed in local assigns so far 13: base.cattr_accessor :template_args 14: base.template_args = {} 15: 16: # Count the number of inline templates 17: base.cattr_accessor :inline_template_count 18: base.inline_template_count = 0 19: end
Compile and evaluate the template‘s code
# File vendor/rails/actionpack/lib/action_view/template_handlers/compilable.rb, line 33 33: def compile_template(template) 34: return unless compile_template?(template) 35: 36: render_symbol = assign_method_name(template) 37: render_source = create_template_source(template, render_symbol) 38: line_offset = self.template_args[render_symbol].size + self.line_offset 39: 40: begin 41: file_name = template.filename || 'compiled-template' 42: ActionView::Base::CompiledTemplates.module_eval(render_source, file_name, -line_offset) 43: rescue Exception => e # errors from template code 44: if @view.logger 45: @view.logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" 46: @view.logger.debug "Function body: #{render_source}" 47: @view.logger.debug "Backtrace: #{e.backtrace.join("\n")}" 48: end 49: 50: raise ActionView::TemplateError.new(template, @view.assigns, e) 51: end 52: 53: self.compile_time[render_symbol] = Time.now 54: # logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger 55: end