Class: Tilt::ERBTemplate

Inherits:
Template show all
Defined in:
lib/tilt/erb.rb

Overview

Direct Known Subclasses

ErubisTemplate

Constant Summary collapse

SUPPORTS_KVARGS =
::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
@@default_output_variable =
'_erbout'

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Template

#basename, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Class Method Details

.default_output_variableObject



12
13
14
# File 'lib/tilt/erb.rb', line 12

def self.default_output_variable
  @@default_output_variable
end

.default_output_variable=(name) ⇒ Object



16
17
18
19
# File 'lib/tilt/erb.rb', line 16

def self.default_output_variable=(name)
  warn "#{self}.default_output_variable= has been replaced with the :outvar-option"
  @@default_output_variable = name
end

Instance Method Details

#precompiled(locals) ⇒ Object



56
57
58
59
# File 'lib/tilt/erb.rb', line 56

def precompiled(locals)
  source, offset = super
  [source, offset + 1]
end

#precompiled_postamble(locals) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/tilt/erb.rb', line 44

def precompiled_postamble(locals)
  <<-RUBY
      #{super}
    ensure
      #{@outvar} = __original_outvar
    end
  RUBY
end

#precompiled_preamble(locals) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/tilt/erb.rb', line 36

def precompiled_preamble(locals)
  <<-RUBY
    begin
      __original_outvar = #{@outvar} if defined?(#{@outvar})
      #{super}
  RUBY
end

#precompiled_template(locals) ⇒ Object



31
32
33
34
# File 'lib/tilt/erb.rb', line 31

def precompiled_template(locals)
  source = @engine.src
  source
end

#prepareObject



21
22
23
24
25
26
27
28
29
# File 'lib/tilt/erb.rb', line 21

def prepare
  @outvar = options[:outvar] || self.class.default_output_variable
  options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
  @engine = if SUPPORTS_KVARGS
    ::ERB.new(data, trim_mode: options[:trim], eoutvar: @outvar)
  else
    ::ERB.new(data, options[:safe], options[:trim], @outvar)
  end
end