Created
February 25, 2009 13:19
-
-
Save koki-h/70156 to your computer and use it in GitHub Desktop.
YAMLファイルを読み込んでERBで整形するだけ
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/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