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 'code_beauty_ruby.rb'
|
||||
|
||||
def checkForHeader(fileName)
|
||||
foundHeader = false;
|
||||
foundSheBang = 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'
|
||||
isCoffee = true
|
||||
end
|
||||
|
||||
# read file
|
||||
file = File.open(fileName)
|
||||
t_file = Tempfile.new('Temp')
|
||||
allLines = IO.readlines(fileName)
|
||||
|
||||
# detect file type
|
||||
if allLines[0] =~ /(^# Copyright)/ || allLines[1] =~ /(^# Copyright)/
|
||||
foundHeader = true
|
||||
elsif allLines[1] =~/^=begin/ #assume external script
|
||||
|
@ -27,23 +30,37 @@ def checkForHeader(fileName)
|
|||
end
|
||||
|
||||
file.each do |line|
|
||||
# replace old header in script
|
||||
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
|
||||
t_file.puts header
|
||||
t_file.puts line
|
||||
t_file.puts line + "\n"
|
||||
|
||||
# insert new header into script
|
||||
elsif file.lineno == 1 && foundSheBang && !foundHeader
|
||||
t_file.puts line
|
||||
t_file.puts header
|
||||
t_file.puts header + "\n"
|
||||
|
||||
# strip lines
|
||||
else
|
||||
t_file.puts line.rstrip
|
||||
end
|
||||
end
|
||||
|
||||
# rename file
|
||||
t_file.rewind
|
||||
t_file.close
|
||||
FileUtils.cp(t_file.path, fileName)
|
||||
t_file.unlink
|
||||
|
||||
# beautify ruby file
|
||||
if !isCoffee
|
||||
t_file = RBeautify.beautify_file(fileName)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue