Class: ActionView::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/haml/template/patch.rb,
lib/haml/template/plugin.rb,
lib/haml/helpers/action_view_mods.rb

Instance Method Summary collapse

Instance Method Details

#compile_haml(template, file_name, local_assigns)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/haml/template/patch.rb', line 26

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

#compile_template_with_haml(extension, template, file_name, local_assigns) Also known as: compile_template



19
20
21
22
# File 'lib/haml/template/patch.rb', line 19

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

#compile_template_without_haml



23
# File 'lib/haml/template/patch.rb', line 23

alias_method :compile_template_without_haml, :compile_template

#delegate_template_exists_with_haml(template_path) Also known as: delegate_template_exists?



13
14
15
# File 'lib/haml/template/patch.rb', line 13

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

#output_buffer_with_haml Also known as: output_buffer



20
21
22
23
# File 'lib/haml/helpers/action_view_mods.rb', line 20

def output_buffer_with_haml
  return haml_buffer.buffer if is_haml?
  output_buffer_without_haml
end

#render_with_haml(*args, &block) Also known as: render



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/haml/helpers/action_view_mods.rb', line 3

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

#set_output_buffer_with_haml(new) Also known as: output_buffer=



27
28
29
30
31
32
33
34
35
# File 'lib/haml/helpers/action_view_mods.rb', line 27

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