mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
2eb2367593
commit
213fa8ec43
1 changed files with 10 additions and 5 deletions
|
@ -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}"
|
||||
|
|
Loading…
Reference in a new issue