class Boxes::Template

Representations of Packer templates.

Attributes

name[R]
template[R]

Public Class Methods

new(env, name) click to toggle source

Load a template with a given name.

@param env [Boxes::Environment] the environment to source templates. @param name [String] the name of the template.

@return [Boxes::Template] a template instance.

# File lib/boxes/template.rb, line 14
def initialize(env, name)
  fail(TemplateNotFoundError) unless env.available_templates.include?(name)

  @name = name
  @template = ''
  File.open(Boxes.config.working_dir + "templates/#{name}.erb") do |f|
    @template << f.read
  end
end

Public Instance Methods

render(args) click to toggle source

Render the template.

@param args [Hash] the values to set.

@return [String] the rendered template.

# File lib/boxes/template.rb, line 29
def render(args)
  ERB.new(template, nil, '-').result(ERBContext.new(args).get_binding)
end