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