Last active
August 29, 2015 14:03
-
-
Save tasermonkey/a603c3d3fdab08df58ee to your computer and use it in GitHub Desktop.
super simple not well tested erb renderer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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