Module: Revelio::HamlTemplateExtension

Includes:
TemplateType
Defined in:
lib/revelio/haml_template_extension.rb

Instance Method Summary collapse

Methods included from TemplateType

#resolve_template_info, #template_type

Instance Method Details

#call(template, source = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/revelio/haml_template_extension.rb', line 7

def call(template, source = nil)
  return super unless Revelio.config.debug_mode

  source ||= template.source
  options = Haml::RailsTemplate.options

  if template.respond_to?(:identifier)
    options = options.merge(filename: template.identifier)
  end

  if template.respond_to?(:type) && template.type == "text/xml"
    options = options.merge(format: :xhtml)
  end

  relative, type, short = resolve_template_info(template)

  preamble_parts = []
  postamble_parts = []

  if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
    preamble_parts << "<!-- BEGIN #{template.short_identifier} -->"
    postamble_parts << "<!-- END #{template.short_identifier} -->"
  end

  marker_attrs = "file=\"#{relative}\" type=\"#{type}\" short=\"#{short}\""
  preamble_parts << "<!-- revelio-begin #{marker_attrs} -->"
  postamble_parts.unshift("<!-- revelio-end file=\"#{relative}\" -->")

  options = options.merge(
    preamble: preamble_parts.join("\n"),
    postamble: postamble_parts.join("\n")
  )

  Haml::Engine.new(options).call(source)
end