Skip to content

Instantly share code, notes, and snippets.

@tasermonkey
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tasermonkey/a603c3d3fdab08df58ee to your computer and use it in GitHub Desktop.
Save tasermonkey/a603c3d3fdab08df58ee to your computer and use it in GitHub Desktop.
super simple not well tested erb renderer.
require 'optparse'
require 'yaml'
require 'erubis'
options = {}
opt_parser = OptionParser.new do |opt|
opt.banner = "Usage: erb_renderer -c config.yml -f file.erb"
opt.on("-c", "--config FILE", "config file to use for data") do |conf|
options[:config] = conf
end
opt.on("-f", "--file FILE", "erb file to render") do |ef|
options[:template] = ef
end
end
opt_parser.parse!
conf = YAML::load_file(options[:config])
conf = Hash[conf.map {|k, v| ["@" + k, v] }]
puts Erubis::Eruby.new(File.open(options[:template], 'r').read).result(conf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment