1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/usr/bin/env ruby
require "optparse"
require "ostruct"
require "fileutils"
options = OpenStruct.new
options.rabbit = "bin/rabbit"
options.output_base = "/tmp/rabbit"
options.locale_dir = "data/locale"
opts = OptionParser.new do |opts|
opts.banner = "#{opts.banner} RD_FILES"
opts.on("--rabbit=RABBIT",
"rabbit path",
"(#{options.rabbit})") do |rabbit|
options.rabbit = rabbit
end
opts.on("--output-base=BASE",
"output base directory",
"(#{options.output_base})") do |base|
options.output_base = base
end
opts.on("--locale-dir=DIR",
"locale directory",
"(#{options.locale_dir})") do |dir|
options.locale_dir = dir
end
end
opts.parse!(ARGV)
ARGV.each do |rd|
original_base_name = File.basename(rd, ".*")
themes = [nil]
case original_base_name
when "blue-circle"
themes << ["green-circle", :replace]
when "lightning-talk"
themes << "lightning-talk-with-contact"
when "theme-bench", "theme-bench-en"
themes.concat([
"red-frame", "blue-bar", "clear-blue",
"blue-circle", "green-circle",
"ruby-gnome2", "lightning-rabbit",
"day-white", "night-black", "cozmixng",
"debian", "ranguba",
])
end
themes.each do |theme, option|
base_name = original_base_name.dup
if theme
case option
when :replace
base_name = theme
else
base_name << "-#{theme.sub(/^#{base_name}-/, '')}"
end
end
output_dir = File.join(options.output_base, base_name)
FileUtils.mkdir_p(output_dir)
message = "processing #{rd}..."
message << " (#{theme})" if theme
puts(message)
args = [
"-s",
"-b", File.join(output_dir, base_name),
"-i", "jpg",
"-I", File.dirname(rd),
"--locale-dir", options.locale_dir
]
args.concat(["-t", theme]) if theme
args << rd
begin
lang = ENV["LANG"]
ENV["LANG"] = "C" if /-en\b/ =~ base_name
system(*(options.rabbit.split + args))
ensure
ENV["LANG"] = lang
end
message = "finished #{rd}."
message << " (#{theme})" if theme
puts(message)
system(*(options.rabbit.split + ["--index-mode"] + args))
message = "finished #{rd}. (index mode)"
message << " (#{theme})" if theme
puts(message)
end
end
|