Class: TemplateRender

Inherits:
Object
  • Object
show all
Defined in:
test/unit/support/template_render.rb

Overview

Emulates the Chef template render engine.

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ TemplateRender

Returns a new instance of TemplateRender


25
26
27
# File 'test/unit/support/template_render.rb', line 25

def initialize(f)
  file(f)
end

Instance Method Details

#attributes_dirObject


29
30
31
# File 'test/unit/support/template_render.rb', line 29

def attributes_dir
  File.join(::File.dirname(__FILE__), '..', '..', '..', 'attributes')
end

#file(arg) ⇒ Object


39
40
41
# File 'test/unit/support/template_render.rb', line 39

def file(arg)
  @path = ::File.join(template_dir, arg)
end

#nodeObject


43
44
45
46
47
48
49
50
# File 'test/unit/support/template_render.rb', line 43

def node
  @node ||= begin
    n = Chef::Node.new
    n.name('node001')
    Dir.glob(::File.join(attributes_dir, '*.rb')) { |f| n.from_file(f) }
    n
  end
end

#render(variables = {}) ⇒ Object


52
53
54
55
56
# File 'test/unit/support/template_render.rb', line 52

def render(variables = {})
  context = Chef::Mixin::Template::TemplateContext.new(variables)
  context[:node] = node
  context.render_template(@path)
end

#template_dirObject


33
34
35
36
37
# File 'test/unit/support/template_render.rb', line 33

def template_dir
  File.join(
    ::File.dirname(__FILE__), '..', '..', '..', 'templates', 'default'
  )
end