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
|
ifchange = nil
|
||||||
source = false
|
source = false
|
||||||
color = nil
|
color = nil
|
||||||
|
templates = []
|
||||||
|
|
||||||
opt = OptionParser.new do |o|
|
ARGV.options do |o|
|
||||||
o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true}
|
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('-o', '--output=PATH') {|v| output = v}
|
||||||
o.on('-c', '--[no-]if-change') {|v| ifchange = v}
|
o.on('-c', '--[no-]if-change') {|v| ifchange = v}
|
||||||
o.on('-x', '--source') {source = true}
|
o.on('-x', '--source') {source = true}
|
||||||
o.on('--color') {color = true}
|
o.on('--color') {color = true}
|
||||||
vpath.def_options(o)
|
vpath.def_options(o)
|
||||||
o.order!(ARGV)
|
o.order!(ARGV)
|
||||||
|
templates << (ARGV.shift or abort o.to_s) if templates.empty?
|
||||||
end
|
end
|
||||||
color = Colorize.new(color)
|
color = Colorize.new(color)
|
||||||
unchanged = color.pass("unchanged")
|
unchanged = color.pass("unchanged")
|
||||||
updated = color.fail("updated")
|
updated = color.fail("updated")
|
||||||
|
|
||||||
template = ARGV.shift or abort opt.to_s
|
result = templates.map do |template|
|
||||||
erb = ERB.new(File.read(template), nil, '%-')
|
erb = ERB.new(File.read(template), nil, '%-')
|
||||||
erb.filename = template
|
erb.filename = template
|
||||||
result = source ? erb.src : proc{erb.result}.call
|
source ? erb.src : proc{erb.result(binding)}.call
|
||||||
|
end
|
||||||
|
result = result.size == 1 ? result[0] : result.join("")
|
||||||
if output
|
if output
|
||||||
if ifchange and (vpath.open(output, "rb") {|f| f.read} rescue nil) == result
|
if ifchange and (vpath.open(output, "rb") {|f| f.read} rescue nil) == result
|
||||||
puts "#{output} #{unchanged}"
|
puts "#{output} #{unchanged}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue