Module: Sanctuary::Planter::Generator

Defined in:
lib/sanctuary/planter/generator.rb

Class Method Summary collapse

Class Method Details

.generate_file_from_plant(plant) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sanctuary/planter/generator.rb', line 6

def self.generate_file_from_plant(plant)
  home_dir = Sanctuary::HOME_DIR
  template_file = IO.read(home_dir + "/" + plant.plant_template)
  template = ERB.new(template_file, nil, '-%<>')
  local_binding = binding
  local_binding.local_variable_set(:name, plant.name)
  local_binding.local_variable_set(:fields, plant.fields)
  local_binding.local_variable_set(:methods, plant.methods)
  puts "Generated #{plant.name}"
  File.open(plant.name + "." + plant.plant_template.split("/").last.split(".")[1], "w") do |f|
    f.write(template.result(local_binding))
  end
end