| Class | ActionView::Base |
| In: |
lib/haml/template/plugin.rb
lib/haml/template/patch.rb lib/haml/helpers/action_view_mods.rb |
| Parent: | Object |
| delegate_template_exists? | -> | delegate_template_exists_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
# File lib/haml/template/plugin.rb, line 82
82: def compile_template(handler, template, file_name, local_assigns)
83: render_symbol = assign_method_name(handler, template, file_name)
84:
85: # Move begin up two lines so it captures compilation exceptions.
86: begin
87: render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
88: line_offset = @@template_args[render_symbol].size + handler.line_offset
89:
90: file_name = 'compiled-template' if file_name.blank?
91: CompiledTemplates.module_eval(render_source, file_name, -line_offset)
92: rescue Exception => e # errors from template code
93: if logger
94: logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
95: logger.debug "Function body: #{render_source}"
96: logger.debug "Backtrace: #{e.backtrace.join("\n")}"
97: end
98:
99: # There's no way to tell Haml about the filename,
100: # so we've got to insert it ourselves.
101: e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
102:
103: raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
104: end
105:
106: @@compile_time[render_symbol] = Time.now
107: # logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
108: end
Alias for compile_template_with_haml
# 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
Alias for compile_template
# 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
# File lib/haml/helpers/action_view_mods.rb, line 27
27: def set_output_buffer_with_haml(new)
28: if is_haml?
29: new = String.new(new) if Haml::Util.rails_xss_safe? &&
30: new.is_a?(Haml::Util.rails_safe_buffer_class)
31: haml_buffer.buffer = new
32: else
33: set_output_buffer_without_haml new
34: end
35: end