ruby-changes:47968
From: nobu <ko1@a...>
Date: Sun, 1 Oct 2017 11:39:27 +0900 (JST)
Subject: [ruby-changes:47968] nobu:r60083 (trunk): generic_erb.rb: -i option
nobu 2017-10-01 11:39:22 +0900 (Sun, 01 Oct 2017) New Revision: 60083 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60083 Log: generic_erb.rb: -i option * tool/generic_erb.rb: -i option to merge multiple template files. Modified files: trunk/tool/generic_erb.rb Index: tool/generic_erb.rb =================================================================== --- tool/generic_erb.rb (revision 60082) +++ tool/generic_erb.rb (revision 60083) @@ -16,24 +16,29 @@ output = nil https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L16 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}" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/