Class: Baha::PreBuild::Module::Template
- Inherits:
-
Object
- Object
- Baha::PreBuild::Module::Template
- Defined in:
- lib/baha/pre_build/template.rb
Defined Under Namespace
Classes: ErbBinding
Constant Summary collapse
Class Method Summary collapse
Class Method Details
.execute(mod) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/baha/pre_build/template.rb', line 27 def self.execute(mod) LOG.debug("template(#{mod.args.inspect})") template = mod.args['template'] src = mod.config.resolve_file(mod.args['template']) dest = mod.image.workspace + mod.args['dest'] raise ArgumentError.new("Unable to find template file #{template}") if src.nil? LOG.info { "Loading template #{src}" } template_str = File.read(src) erb = ERB.new(template_str,0,'-') environment = mod.image.env environment.merge!(Hash[mod.args.map{|k,v| [k.to_sym, v]}]) LOG.debug { "template environment: #{environment.inspect}" } LOG.info { "Writing to #{dest}" } File.open(dest,"w") do |f| f.write(erb.result(ErbBinding.new(environment,mod.config).get_binding)) end end |