class Derb
Public Class Methods
new(template_file = nil, data_file = nil)
click to toggle source
# File bin/derb, line 8 def initialize(template_file = nil, data_file = nil) template_file = template_file || 'Dockerfile.erb' data_file = data_file || 'Dockerfile.yml' unless File.exists? template_file raise ArgumentError, "#{template_file} not found" end @template = File.read template_file if File.exists? data_file @data = YAML.load_file data_file if data_file end end
Public Instance Methods
render()
click to toggle source
# File bin/derb, line 22 def render ERB.new(@template, nil, "%<>").result( OpenStruct.new(@data).instance_eval { binding } ) end
render_to_file(output_filename = nil)
click to toggle source
# File bin/derb, line 28 def render_to_file(output_filename = nil) output_filename = output_filename || 'Dockerfile' if File.exists? output_filename raise "#{output_filename} does already exist, aborting" else File.open(output_filename, 'w+'){ |f| f.write(render) } puts "Created #{output_filename}" end end