OSDN Git Service

t#31004:create sbt helper
[pettanr/pettanr.git] / script / sbt_helper.rb
1 #フキダシテンプレートを作るサポートツール\r
2 if ARGV.size < 2\r
3   puts "sbt_helper.rb input.json output.json [work dir=input dir]"\r
4   exit\r
5 end\r
6 $KCODE = 'u'\r
7 require 'json'\r
8 require 'base64'\r
9 \r
10 inputfile = ARGV[0]\r
11 wd = ARGV[2] ? File.expand_path(ARGV[2]) : File.dirname(inputfile)\r
12 outputfile = wd + '/' + ARGV[1]\r
13 \r
14 puts "#{inputfile} to #{outputfile}"\r
15 def replace_system_picture attr, wd\r
16   attr.each do |name, value|\r
17     if value.is_a? Hash\r
18       if value['system_picture_file']\r
19         fn = File.expand_path(wd + '/' + value['system_picture_file'])\r
20         puts 'open system picture file ' + fn\r
21         d = File.open(fn, 'rb').read\r
22         b = Base64.encode64(d).gsub(/\r/, '').gsub(/\n/, '')\r
23         value['system_picture_id'] = {"text" => b}\r
24         value.delete 'system_picture_file'\r
25       end\r
26       replace_system_picture value, wd\r
27     end\r
28   end\r
29 end\r
30 \r
31 json = JSON.parse(open(inputfile).read)\r
32 replace_system_picture json, wd\r
33 \r
34 puts "generating " + outputfile\r
35 File.open(outputfile, 'w') do |f|\r
36   f.write json.to_json.to_s\r
37 end\r