Class | ActionView::Base |
In: |
lib/haml/template/patch.rb
lib/haml/template/plugin.rb lib/haml/helpers/action_view_mods.rb |
Parent: | Object |
delegate_template_exists? | -> | delegate_template_exists_without_haml |
compile_template | -> | compile_template_without_haml |
render | -> | render_without_haml |
# File lib/haml/template/patch.rb, line 26 26: def compile_haml(template, file_name, local_assigns) 27: render_symbol = assign_method_name(:haml, template, file_name) 28: locals = local_assigns.keys 29: 30: @@template_args[render_symbol] ||= {} 31: locals_keys = @@template_args[render_symbol].keys | locals 32: @@template_args[render_symbol] = Haml::Util.to_hash(locals_keys.map {|k| [k, true]}) 33: 34: options = Haml::Template.options.dup 35: options[:filename] = file_name || 'compiled-template' 36: 37: begin 38: Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *locals_keys) 39: rescue Exception => e 40: if logger 41: logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" 42: logger.debug "Backtrace: #{e.backtrace.join("\n")}" 43: end 44: 45: base_path = if defined?(extract_base_path_from) 46: # Rails 2.0.x 47: extract_base_path_from(file_name) || view_paths.first 48: else 49: # Rails <=1.2.6 50: @base_path 51: end 52: raise ActionView::TemplateError.new(base_path, file_name || template, @assigns, template, e) 53: end 54: 55: @@compile_time[render_symbol] = Time.now 56: end
Alias for compile_template_with_haml
# File lib/haml/template/plugin.rb, line 43 43: def compile_template(handler, template, file_name, local_assigns) 44: render_symbol = assign_method_name(handler, template, file_name) 45: 46: # Move begin up two lines so it captures compilation exceptions. 47: begin 48: render_source = create_template_source(handler, template, render_symbol, local_assigns.keys) 49: line_offset = @@template_args[render_symbol].size + handler.line_offset 50: 51: file_name = 'compiled-template' if file_name.blank? 52: CompiledTemplates.module_eval(render_source, file_name, -line_offset) 53: rescue Exception => e # errors from template code 54: if logger 55: logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}" 56: logger.debug "Function body: #{render_source}" 57: logger.debug "Backtrace: #{e.backtrace.join("\n")}" 58: end 59: 60: # There's no way to tell Haml about the filename, 61: # so we've got to insert it ourselves. 62: e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error) 63: 64: raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e) 65: end 66: 67: @@compile_time[render_symbol] = Time.now 68: # logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger 69: end
# File lib/haml/template/patch.rb, line 19 19: def compile_template_with_haml(extension, template, file_name, local_assigns) 20: return compile_haml(template, file_name, local_assigns) if extension.to_s == "haml" 21: compile_template_without_haml(extension, template, file_name, local_assigns) 22: end
# File lib/haml/template/patch.rb, line 13 13: def delegate_template_exists_with_haml(template_path) 14: template_exists?(template_path, :haml) && [:haml] 15: end
# File lib/haml/helpers/action_view_mods.rb, line 20 20: def output_buffer_with_haml 21: return haml_buffer.buffer if is_haml? 22: output_buffer_without_haml 23: end
# File lib/haml/helpers/action_view_mods.rb, line 3 3: def render_with_haml(*args, &block) 4: options = args.first 5: 6: # If render :layout is used with a block, 7: # it concats rather than returning a string 8: # so we need it to keep thinking it's Haml 9: # until it hits the sub-render 10: if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?) 11: return non_haml { render_without_haml(*args, &block) } 12: end 13: render_without_haml(*args, &block) 14: end