aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-01 02:39:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-01 02:39:22 +0000
commit84641f265385f1fdacd135a16304762db59e9862 (patch)
tree2461db387cf5b47cc44473ab2bab77cd0f3c8d51
parent258c061faba70db89bba6e25f6e0c9b08f7258bc (diff)
downloadruby-84641f265385f1fdacd135a16304762db59e9862.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.rb15
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}"