Created
February 2, 2017 23:56
-
-
Save troykinsella/a8c1bb5634a2bb624abb848e36c483a6 to your computer and use it in GitHub Desktop.
Evaluate an ERB template, injecting a YAML file of variables.
This file contains 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
#!/usr/bin/env ruby | |
require 'erb' | |
require 'yaml' | |
class HashBinding | |
def initialize(hash) | |
@hash = hash.dup | |
end | |
def method_missing(m, *args, &block) | |
@hash[m.to_s] | |
end | |
def get_binding | |
binding | |
end | |
end | |
t = ERB.new(File.read(ARGV[0])) | |
vars = YAML.load_file(ARGV[1]) | |
b = HashBinding.new(vars) | |
puts t.result(b.get_binding) |
Doesnt work for me - can you attach two generic inputs?
For instance are you calling the var with <%= var %> or <%= @var %> ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./process-erb.rb template.erb vars.yml > out.txt