#!/usr/bin/ruby require "yaml" require "erb" class TODO < RuntimeError end def load_const(name, value, desc) " # #{desc.to_s.chomp}\n" \ " Lignite::#{name} = #{value.inspect}\n\n" end def rendered_file(yml_hash) op_hash = yml_hash["ops"] result = < #{csym.inspect},\n" end result = < e " # Could not define #{oname}: #{e.message}\n" end def whitespace_cleanup(s) s.lines.map(&:rstrip).join("\n") + "\n" end def render_erb_file(erb_filename, a_binding) safe = nil trim = "<>-" erb = ERB.new(File.read(erb_filename), safe, trim) out_filename = erb_filename.sub(/\.erb$/, "") header = "# This file is generated from its .erb template. DO NOT EDIT.\n\n" rendered = erb.result(a_binding) rendered = whitespace_cleanup(rendered) File.write(out_filename, header + rendered) end # run this via "rake ops" yml = YAML.load_file(ARGV[0]) out_fn = ARGV[1] rendered = rendered_file(yml) rendered = whitespace_cleanup(rendered) File.write(out_fn, rendered) libdir = File.expand_path("..", out_fn) render_erb_file("#{libdir}/defines.rb.erb", binding) render_erb_file("#{libdir}/enums.rb.erb", binding)