Module: Revelio::ErbTemplateExtension

Includes:
TemplateType
Defined in:
lib/revelio/erb_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
# File 'lib/revelio/erb_template_extension.rb', line 7

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

  relative, type, short = resolve_template_info(template)

  preamble = %{<!-- revelio-begin file="#{relative}" type="#{type}" short="#{short}" -->}
  postamble = %{<!-- revelio-end file="#{relative}" -->}

  # ERB's output buffer is already initialized by ActionView before the template runs
  "@output_buffer.safe_append='#{preamble}';#{compiled}\n@output_buffer.safe_append='#{postamble}';\n@output_buffer"
end