Added update of header.
This commit is contained in:
parent
49ed627219
commit
cfb2f857fc
1 changed files with 21 additions and 4 deletions
|
@ -3,20 +3,23 @@
|
||||||
|
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'code_beauty_ruby.rb'
|
require 'code_beauty_ruby.rb'
|
||||||
|
|
||||||
def checkForHeader(fileName)
|
def checkForHeader(fileName)
|
||||||
foundHeader = false;
|
foundHeader = false;
|
||||||
foundSheBang = false;
|
foundSheBang = false;
|
||||||
isCoffee = false;
|
isCoffee = false;
|
||||||
|
|
||||||
header = "# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/\n\n"
|
header = "# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/\n"
|
||||||
if File.extname(fileName) == '.coffee'
|
if File.extname(fileName) == '.coffee'
|
||||||
isCoffee = true
|
isCoffee = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# read file
|
||||||
file = File.open(fileName)
|
file = File.open(fileName)
|
||||||
t_file = Tempfile.new('Temp')
|
t_file = Tempfile.new('Temp')
|
||||||
allLines = IO.readlines(fileName)
|
allLines = IO.readlines(fileName)
|
||||||
|
|
||||||
|
# detect file type
|
||||||
if allLines[0] =~ /(^# Copyright)/ || allLines[1] =~ /(^# Copyright)/
|
if allLines[0] =~ /(^# Copyright)/ || allLines[1] =~ /(^# Copyright)/
|
||||||
foundHeader = true
|
foundHeader = true
|
||||||
elsif allLines[1] =~/^=begin/ #assume external script
|
elsif allLines[1] =~/^=begin/ #assume external script
|
||||||
|
@ -27,23 +30,37 @@ def checkForHeader(fileName)
|
||||||
end
|
end
|
||||||
|
|
||||||
file.each do |line|
|
file.each do |line|
|
||||||
|
# replace old header in script
|
||||||
if file.lineno == 1 && foundSheBang && foundHeader
|
if file.lineno == 1 && foundSheBang && foundHeader
|
||||||
t_file.puts line
|
t_file.puts header
|
||||||
|
|
||||||
|
# insert new header
|
||||||
|
elsif file.lineno == 1 && !foundSheBang && foundHeader
|
||||||
|
t_file.puts header
|
||||||
|
|
||||||
|
# insert new header
|
||||||
elsif file.lineno == 1 && !foundSheBang && !foundHeader
|
elsif file.lineno == 1 && !foundSheBang && !foundHeader
|
||||||
t_file.puts header
|
t_file.puts header
|
||||||
t_file.puts line
|
t_file.puts line + "\n"
|
||||||
|
|
||||||
|
# insert new header into script
|
||||||
elsif file.lineno == 1 && foundSheBang && !foundHeader
|
elsif file.lineno == 1 && foundSheBang && !foundHeader
|
||||||
t_file.puts line
|
t_file.puts line
|
||||||
t_file.puts header
|
t_file.puts header + "\n"
|
||||||
|
|
||||||
|
# strip lines
|
||||||
else
|
else
|
||||||
t_file.puts line.rstrip
|
t_file.puts line.rstrip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rename file
|
||||||
t_file.rewind
|
t_file.rewind
|
||||||
t_file.close
|
t_file.close
|
||||||
FileUtils.cp(t_file.path, fileName)
|
FileUtils.cp(t_file.path, fileName)
|
||||||
t_file.unlink
|
t_file.unlink
|
||||||
|
|
||||||
|
# beautify ruby file
|
||||||
if !isCoffee
|
if !isCoffee
|
||||||
t_file = RBeautify.beautify_file(fileName)
|
t_file = RBeautify.beautify_file(fileName)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue