Class: Templator::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/templator/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, var_file, extra_args = {}) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
# File 'lib/templator/generator.rb', line 10

def initialize(template, var_file, extra_args = {})
  @template = template
  @var_file = var_file
  @extra_args = extra_args
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



8
9
10
# File 'lib/templator/generator.rb', line 8

def template
  @template
end

#var_fileObject (readonly)

Returns the value of attribute var_file.



8
9
10
# File 'lib/templator/generator.rb', line 8

def var_file
  @var_file
end

Instance Method Details

#generate(output_path = "") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/templator/generator.rb', line 16

def generate(output_path = "")
  vars = load_vars_from_yaml(self.var_file)
  vars = vars.merge(@extra_args)

  template = Tilt.new(self.template)
  result = template.render(self, vars)

  write_output(output_path, result) if output_path && !output_path.empty?

  result
end