class ActionView::Base

def compile_haml(template, file_name, local_assigns)

def compile_haml(template, file_name, local_assigns)
  render_symbol = assign_method_name(:haml, template, file_name)
  locals = local_assigns.keys
  @@template_args[render_symbol] ||= {}
  locals_keys = @@template_args[render_symbol].keys | locals
  @@template_args[render_symbol] = Haml::Util.to_hash(locals_keys.map {|k| [k, true]})
  options = Haml::Template.options.dup
  options[:filename] = file_name || 'compiled-template'
  begin
    Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *locals_keys)
  rescue Exception => e
    if logger
      logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
      logger.debug "Backtrace: #{e.backtrace.join("\n")}"
    end
    base_path = if defined?(extract_base_path_from)
                  # Rails 2.0.x
                  extract_base_path_from(file_name) || view_paths.first
                else
                  # Rails <=1.2.6
                  @base_path
                end
    raise ActionView::TemplateError.new(base_path, file_name || template, @assigns, template, e)
  end
  @@compile_time[render_symbol] = Time.now
end

def compile_template(handler, template, file_name, local_assigns)

def compile_template(handler, template, file_name, local_assigns)
  render_symbol = assign_method_name(handler, template, file_name)
  # Move begin up two lines so it captures compilation exceptions.
  begin
    render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
    line_offset = @@template_args[render_symbol].size + handler.line_offset
  
    file_name = 'compiled-template' if file_name.blank?
    CompiledTemplates.module_eval(render_source, file_name, -line_offset)
  rescue Exception => e # errors from template code
    if logger
      logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
      logger.debug "Function body: #{render_source}"
      logger.debug "Backtrace: #{e.backtrace.join("\n")}"
    end
    # There's no way to tell Haml about the filename,
    # so we've got to insert it ourselves.
    e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
    
    raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
  end
  
  @@compile_time[render_symbol] = Time.now
  # logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
end

def compile_template_with_haml(extension, template, file_name, local_assigns)

def compile_template_with_haml(extension, template, file_name, local_assigns)
  return compile_haml(template, file_name, local_assigns) if extension.to_s == "haml"
  compile_template_without_haml(extension, template, file_name, local_assigns)
end

def delegate_template_exists_with_haml(template_path)

def delegate_template_exists_with_haml(template_path)
  template_exists?(template_path, :haml) && [:haml]
end

def output_buffer_with_haml

def output_buffer_with_haml
  return haml_buffer.buffer if is_haml?
  output_buffer_without_haml
end

def render_with_haml(*args, &block)

def render_with_haml(*args, &block)
  options = args.first
  # If render :layout is used with a block,
  # it concats rather than returning a string
  # so we need it to keep thinking it's Haml
  # until it hits the sub-render
  if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
    return non_haml { render_without_haml(*args, &block) }
  end
  render_without_haml(*args, &block)
end

def set_output_buffer_with_haml(new)

def set_output_buffer_with_haml(new)
  if is_haml?
    new = String.new(new) if Haml::Util.rails_xss_safe? && new.is_a?(ActionView::SafeBuffer)
    haml_buffer.buffer = new
  else
    set_output_buffer_without_haml new
  end
end