Skip to content

Instantly share code, notes, and snippets.

@koki-h
Created February 25, 2009 13:19
Show Gist options
  • Save koki-h/70156 to your computer and use it in GitHub Desktop.
Save koki-h/70156 to your computer and use it in GitHub Desktop.
YAMLファイルを読み込んでERBで整形するだけ
#!/usr/bin/ruby
#YAMLファイルを読み込んでERBで整形するだけ
#YAMLファイルとテンプレートファイルを引数にとり、整形したのを標準出力に書き出す
require 'yaml'
require 'erb'
require 'kconv'
yaml = ""
#一個目のファイルはYAMLデータとみなす
file1 = ARGF.filename
while (gets())
break if (file1 != ARGF.filename)
yaml += $_
end
data = YAML.load(yaml) # パースする
#2個目以降はテンプレートファイルとみなす
tmpl = ARGF.read()
erb = ERB.new(tmpl)
puts erb.result(binding).toeuc #出力文字コードは必要に応じて変更
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment