Code beautifying.
This commit is contained in:
parent
a672b0a692
commit
79bebc2d3f
7 changed files with 66 additions and 56 deletions
|
@ -1,2 +1,4 @@
|
||||||
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module PostsHelper
|
module PostsHelper
|
||||||
end
|
end
|
||||||
|
|
|
@ -531,9 +531,9 @@ module Mail
|
||||||
|
|
||||||
# Search for occurences of quoted strings or plain strings
|
# Search for occurences of quoted strings or plain strings
|
||||||
text.scan(/( # Group around entire regex to include it in matches
|
text.scan(/( # Group around entire regex to include it in matches
|
||||||
\=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method
|
\=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method
|
||||||
| # or
|
| # or
|
||||||
.+?(?=\=\?|$) # Plain String
|
.+?(?=\=\?|$) # Plain String
|
||||||
)/xmi).map do |matches|
|
)/xmi).map do |matches|
|
||||||
string, method = *matches
|
string, method = *matches
|
||||||
if method == 'b' || method == 'B'
|
if method == 'b' || method == 'B'
|
||||||
|
|
|
@ -27,7 +27,7 @@ module RBeautify
|
||||||
# user-customizable values
|
# user-customizable values
|
||||||
|
|
||||||
RBeautify::TabStr = " "
|
RBeautify::TabStr = " "
|
||||||
RBeautify::TabSize = 3
|
RBeautify::TabSize = 2
|
||||||
|
|
||||||
# indent regexp tests
|
# indent regexp tests
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ module RBeautify
|
||||||
/^module\b/,
|
/^module\b/,
|
||||||
/^class\b/,
|
/^class\b/,
|
||||||
/^if\b/,
|
/^if\b/,
|
||||||
|
/[A-z]\($/,
|
||||||
/(=\s*|^)until\b/,
|
/(=\s*|^)until\b/,
|
||||||
/(=\s*|^)for\b/,
|
/(=\s*|^)for\b/,
|
||||||
/^unless\b/,
|
/^unless\b/,
|
||||||
|
@ -59,6 +60,9 @@ module RBeautify
|
||||||
/^rescue\b/,
|
/^rescue\b/,
|
||||||
/^ensure\b/,
|
/^ensure\b/,
|
||||||
/^elsif\b/,
|
/^elsif\b/,
|
||||||
|
/^\)$/,
|
||||||
|
/^\);$/,
|
||||||
|
/^\)\./,
|
||||||
/^end\b/,
|
/^end\b/,
|
||||||
/^else\b/,
|
/^else\b/,
|
||||||
/\bwhen\b/,
|
/\bwhen\b/,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
|
||||||
$LOAD_PATH << './lib'
|
$LOAD_PATH << './lib'
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
|
@ -4,59 +4,57 @@
|
||||||
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;
|
||||||
header = "# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/\n\n"
|
header = "# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/\n\n"
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
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
|
||||||
foundHeader = true
|
foundHeader = true
|
||||||
end
|
end
|
||||||
if allLines[0] =~ /(^#!\/)/
|
if allLines[0] =~ /(^#!\/)/
|
||||||
foundSheBang = true
|
foundSheBang = true
|
||||||
end
|
end
|
||||||
|
|
||||||
file.each do |line|
|
file.each do |line|
|
||||||
if file.lineno == 1 && foundSheBang && foundHeader
|
if file.lineno == 1 && foundSheBang && foundHeader
|
||||||
t_file.puts line
|
t_file.puts line
|
||||||
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
|
||||||
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
|
||||||
else
|
else
|
||||||
t_file.puts line.rstrip
|
t_file.puts line.rstrip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
t_file = RBeautify.beautify_file(fileName)
|
t_file = RBeautify.beautify_file(fileName)
|
||||||
end
|
end
|
||||||
|
|
||||||
#folder array
|
#folder array
|
||||||
#folder = ['app/controllers/','app/models/', 'app/helpers/', 'app/mailers/']
|
folder = ['app/controllers/', 'app/models/', 'app/helpers/', 'app/mailers/' ]
|
||||||
#folder = ['app/controllers/', 'script']
|
|
||||||
folder = ['script/']
|
|
||||||
|
|
||||||
folder.each do |folder|
|
folder.each do |folder|
|
||||||
puts 'Working on folder' + folder.to_s
|
puts 'Working on folder' + folder.to_s
|
||||||
rbfiles = File.join("../#{folder}**", "*.rb")
|
rbfiles = File.join("../#{folder}**", "*.rb")
|
||||||
d = Dir.glob(rbfiles)
|
d = Dir.glob(rbfiles)
|
||||||
|
|
||||||
d.each {|fileName|
|
d.each {|fileName|
|
||||||
puts "Working on #{fileName}"
|
puts "Working on #{fileName}"
|
||||||
|
|
||||||
#check if file header is present
|
#check if file header is present
|
||||||
checkForHeader(fileName)
|
checkForHeader(fileName)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
|
||||||
$LOAD_PATH << './lib'
|
$LOAD_PATH << './lib'
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
@ -160,12 +162,12 @@ EventMachine.run {
|
||||||
@clients[client_id][:session] = data['session']
|
@clients[client_id][:session] = data['session']
|
||||||
Session.create( client_id, data['session'], { :type => 'websocket' } )
|
Session.create( client_id, data['session'], { :type => 'websocket' } )
|
||||||
|
|
||||||
# remember ping, send pong back
|
# remember ping, send pong back
|
||||||
elsif data['action'] == 'ping'
|
elsif data['action'] == 'ping'
|
||||||
@clients[client_id][:last_ping] = Time.now
|
@clients[client_id][:last_ping] = Time.now
|
||||||
@clients[client_id][:websocket].send( '[{"action":"pong"}]' )
|
@clients[client_id][:websocket].send( '[{"action":"pong"}]' )
|
||||||
|
|
||||||
# broadcast
|
# broadcast
|
||||||
elsif data['action'] == 'broadcast'
|
elsif data['action'] == 'broadcast'
|
||||||
|
|
||||||
# list all current clients
|
# list all current clients
|
||||||
|
@ -197,7 +199,7 @@ EventMachine.run {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# broadcast every client
|
# broadcast every client
|
||||||
else
|
else
|
||||||
log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id
|
log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id
|
||||||
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
if local_client[:meta][:type] == 'websocket' && @clients[ local_client_id ]
|
||||||
|
@ -256,7 +258,7 @@ EventMachine.run {
|
||||||
begin
|
begin
|
||||||
queue = Session.queue( client_id )
|
queue = Session.queue( client_id )
|
||||||
if queue && queue[0]
|
if queue && queue[0]
|
||||||
# log "send " + queue.inspect, client_id
|
# log "send " + queue.inspect, client_id
|
||||||
log 'notice', "send data to client", client_id
|
log 'notice', "send data to client", client_id
|
||||||
client[:websocket].send( queue.to_json )
|
client[:websocket].send( queue.to_json )
|
||||||
end
|
end
|
||||||
|
@ -313,7 +315,7 @@ EventMachine.run {
|
||||||
return if level == 'debug'
|
return if level == 'debug'
|
||||||
end
|
end
|
||||||
puts "#{Time.now}:client(#{ client_id }) #{ data }"
|
puts "#{Time.now}:client(#{ client_id }) #{ data }"
|
||||||
# puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }"
|
# puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }"
|
||||||
end
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue