diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-01 02:39:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-01 02:39:22 +0000 |
commit | 213fa8ec432fffd9adbcf4f07863023277e18083 (patch) | |
tree | 2461db387cf5b47cc44473ab2bab77cd0f3c8d51 | |
parent | 2eb2367593cc59585ce6d2ef60fba2d34b784da3 (diff) | |
download | ruby-213fa8ec432fffd9adbcf4f07863023277e18083.tar.gz |
generic_erb.rb: -i option
* tool/generic_erb.rb: -i option to merge multiple template files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | tool/generic_erb.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb index 08077f2dbc..c9986c7284 100644 --- a/tool/generic_erb.rb +++ b/tool/generic_erb.rb @@ -16,24 +16,29 @@ output = nil ifchange = nil source = false color = nil +templates = [] -opt = OptionParser.new do |o| +ARGV.options do |o| o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true} + o.on('-i', '--input=PATH') {|v| template << v} o.on('-o', '--output=PATH') {|v| output = v} o.on('-c', '--[no-]if-change') {|v| ifchange = v} o.on('-x', '--source') {source = true} o.on('--color') {color = true} vpath.def_options(o) o.order!(ARGV) + templates << (ARGV.shift or abort o.to_s) if templates.empty? end color = Colorize.new(color) unchanged = color.pass("unchanged") updated = color.fail("updated") -template = ARGV.shift or abort opt.to_s -erb = ERB.new(File.read(template), nil, '%-') -erb.filename = template -result = source ? erb.src : proc{erb.result}.call +result = templates.map do |template| + erb = ERB.new(File.read(template), nil, '%-') + erb.filename = template + source ? erb.src : proc{erb.result(binding)}.call +end +result = result.size == 1 ? result[0] : result.join("") if output if ifchange and (vpath.open(output, "rb") {|f| f.read} rescue nil) == result puts "#{output} #{unchanged}" |