Class: Itamae::Resource::Template::RenderContext

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/resource/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ RenderContext

Returns a new instance of RenderContext.



30
31
32
33
34
35
36
# File 'lib/itamae/resource/template.rb', line 30

def initialize(resource)
  @resource = resource

  @resource.attributes.variables.each_pair do |key, value|
    instance_variable_set("@#{key}".to_sym, value)
  end
end

Instance Method Details

#nodeObject



50
51
52
# File 'lib/itamae/resource/template.rb', line 50

def node
  @resource.recipe.runner.node
end

#render_file(src) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/itamae/resource/template.rb', line 38

def render_file(src)
  template = ::File.read(src)
  erb =
    if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
      ERB.new(template, trim_mode: '-')
    else
      ERB.new(template, nil, '-')
    end
  erb.filename = src
  erb.result(binding)
end